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

Martin Baulig martin at ximian.com
Mon Jan 17 15:27:29 EST 2005


On Sun, 2005-01-16 at 10:45 +0000, James Fitzsimons wrote:

> 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);
Hi,

this won't work:

NearestNeighbourRange() returns a List<IKDTreeDomain>, not a
List<StereoFeature>.

> 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?

It's the other way around: you can cast from a class to an interface it
implements, but not the other way around.

Martin





More information about the Mono-devel-list mailing list