[Mono-devel-list] Generics qstn - was: The type mscorlib has two conflicting definitons

Rafael Teixeira monoman at gmail.com
Mon Jan 17 12:46:28 EST 2005


>Is my code wrong? 

AFAIK, yes your code is wrong.

>I thought that as my StereoFeature class implemented
>the IKDTree interface it could be used in place of IKDTree. 

In plain OOP you can do the reverse but I'm not sure about if Generics
would add impose further restrictions. Let's show an example:

public interface IDoer { void JustDoIt(); }

public class MyDoer : IDoer {
  void IDoer.JustDoIt() { Console.WriteLine("Doing it..."); }
  public JustSomethingElse()  { Console.WriteLine("Doing something else..."); }
}

public class AnotherDoer : IDoer {
  void IDoer.JustDoIt() { Console.WriteLine("Doing it... Another Way"); }
}


public class MyApp {

public static IDoer GetADoer() { return new MyDoer();  }
public static IDoer GetAnotherDoer() { return new AnotherDoer();  }

public IDoer Doer1 = new MyDoer(); // OK
public MyDoer Doer2 = new MyDoer(); // OK
public IDoer Doer3 = GetADoer(); // OK

public MyDoer Doer4 = GetADoer(); // CRASH:  return is known to be just a IDoer
public MyDoer Doer5 = GetAnotherDoer(); CRASH:  return is known to be
just a IDoer

}

Maybe you have background from VB or another language that would do
lots of implicit conversions and late-binding, but C# won't defer to
run-time such type safety checks.

>> If so is this a bug in the compiler?

I think the message should be clearer, but assuredly the compiler is
doing the job right.

Have fun,



On Sun, 16 Jan 2005 10:45:25 +0000, James Fitzsimons
<james.fitzsimons at gmail.com> wrote:
> Hi all,
> 
> I've figured out what the problem was, but I'm not sure my code is
> actually wrong.
> 
> I had the following definitions (implementation not included):
> 
> public interface IKDTreeDomain
> 
> public class StereoFeature : IKDTreeDomain
> 
> public class KDTree
> {
>         public List<IKDTreeDomain> NearestNeighbourRange (IKDTreeDomain
>                         target, double range, out double resDist)
> }
> 
> and was calling the NearestNeighbourRange method like so:
> 
> List<StereoFeature> closeKeys = kd.NearestNeighbourRange(refFeature, 20,
>                                                         out dist);
> 
> This cause the error:
> BETA SOFTWARE: Mono C# Compiler 1.1.2.0 for Generics
> > ./StereoMatcher.cs(89) error CS0029: Cannot convert implicitly from
> > `System.Collections.Generic.List`1' to
> > `System.Collections.Generic.List`1'
> > ./StereoMatcher.cs(89) The type mscorlib, Version=2.0.3600.0,
> > Culture=neutral, PublicKeyToken=b77a5c561934e089 has two conflicting
> > definitons, one comes from mscorlib, Version=2.0.3600.0,
> > Culture=neutral, PublicKeyToken=b77a5c561934e089 and the other from
> > mscorlib, Version=2.0.3600.0, Culture=neutral,
> > PublicKeyToken=b77a5c561934e089error
> > Compilation failed: 1 error(s), 0 warnings
> > make: *** [slam.exe] Error 1
> 
> when I changed the way I was calling kd.NearestNeighbourRange to this:
> 
> List<IKDTreeDomain> closeKeys = kd.NearestNeighbourRange(refFeature, 20,
>                                                         out dist);
> the compiler was happy.
> 
> Is my code wrong? I thought that as my StereoFeature class implemented
> the IKDTree interface it could be used in place of IKDTree. If so is
> this a bug in the compiler?
> 
> Cheers,
> James Fitzsimons
> --
> It's 5.50 a.m.... Do you know where your stack pointer is ?
> 
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list
> 


-- 
Rafael "Monoman" Teixeira
---------------------------------------
I'm trying to become a "Rosh Gadol" before my own eyes. 
See http://www.joelonsoftware.com/items/2004/12/06.html for enlightment.



More information about the Mono-devel-list mailing list