[Mono-list] Type conversion trouble

Wolfgang Schulze-Zachau wolfgangs at manticoreit.com
Wed Dec 10 16:59:11 EST 2008


Hi all,

I am using the current 2.0 Alpha 2 release and I have some strange
behaviour. Any help would be appreciated. Here is the problem:
I am building an application where I am separating code into various
libraries, all with their own namespaces. One of these contains all the data
access objects, complete with a data provider and with interface
definitions. In parallel to this, the library containing the unit tests has
a mock data provider, so that for my tests I don't have to have a working
database. The mock data provider makes use of the interfaces above. Here is
an extract from one of the unit test classes:

using System;
using NUnit.Framework;
using Amino.Common;
using Amino.Project;

namespace Amino.testProCosta
{
	
	
	[TestFixture()]
	public class TestProjectNode
	{
		ProjectNode node;
		
		[Test()]
		public void Instantiation()
		{
			IDataProvider provider = new MockDataProvider();
			IProjectNodeData nd = provider.getNewNodeData();
			node = new ProjectNode(nd);
			Assert.AreEqual(0, node.WorkTypeID, "wrong worktype ID instantiated");
			Assert.AreEqual(0, node.ParentID, "wrong parent ID instantiated");
			Assert.AreEqual(ProjectNodeType.Project, node.NodeType, "wrong type
instantiated");
		}

The definition of the ProjectNode class looks like this:

using System;
using System.Collections;
using Amino.Common;

namespace Amino.Project
{
	
	
	public class ProjectNode
	{
		protected IProjectNodeData data;
		protected ProjectNodeType nodetype;
		ProjectNode parent;
		ArrayList children;
		Department department;
		
		public ProjectNode()
		{
			throw new InvalidOperationException("You must use the data provider to
obtain project node data objects for instantiation");
		}
		
		public ProjectNode(IProjectNodeData dao) {
			this.data = dao;
			this.nodetype = ProjectNodeType.Project;
		}
		
...

As you can see, all of these use the IProjectNodeData interface to define
the data access objects. When I compile this code, I get an error message:

Cannot convert 'Amino.Common.IProjectNodeData' expression to type
'Amino.Common.IProjectNodeData' (CS1503).

Now this is where the fun starts:
1.) The error message doesn't make any sense to me. The two types are
exactly the same. There should be no need to do any conversion?????
2.) Here is how I can work around this:
  a) copy the IProjectNodeData interface to the project where ProjectNode is
defined. Enable the build on this interface.
  b) rebuild the solution. Error message sticks around. Sometimes it changes
to something like this:
  Cannot convert 'Amino.Project.IProjectNodeData' expression to type
'Amino.Common.IProjectNodeData' (CS1503).
  => Note the difference in namespace, this actually makes sense.
  c) disable the build on the new interface
  d) rebuild the solution. Build succeeds.

Now this makes even less sense to me. What is going on here? I must be
making some fundamental mistake in my use of namespaces and or
types/interfaces, but I cannot figure out where.
Oh, yeah and then there is the issue that if I do a complete rebuild (using
Ctrl-F8), I get this nice big red error message at the end (after all work
has been done: 
Build failed. Object reference not set to an instance of an object
(I thought this had been fixed long ago, apparently not).

I am happy to provide more detail and/or required source code. Any pointers
would be highly appreciated.

greetings
Wolfgang

-- 
View this message in context: http://www.nabble.com/Type-conversion-trouble-tp20944980p20944980.html
Sent from the Mono - General mailing list archive at Nabble.com.



More information about the Mono-list mailing list