2

This seems strange unless I am missing something...

public static string ToDomainSolarSystemCelestial(this TypeMapper<string> m)
{
    // Does not reference any other assemblies - straight string to string mapping.
    return m.Source
}

public static Universe.SolarSystemCelestial ToDomainSolarSystemCelestial(this TypeMapper<Db.SolarSystemCelestial> m)
{
     // Maps between a database and business object. 
     // Requires a reference to the Db assembly.
     return new Universe.SolarSystemCelestial()
     {
         Id = m.Source.Id,
         // etc
     }
}

Both of these extension methods are defined in the same class. The second override needs to know what a Db.SolarSystemCelestial is so it needs a reference to the containing assembly. However the first is a straight string to string mapping.

Yet if I do this...

var x = Mapper.Map("x").ToDomainSolarSystemCelestial();

.. using the overload that has no dependencies, Visual Studio will complain with the following message:

The type Db.SolarSystemCelestial is not defined in an assembly that is referenced. You must add a reference to assembly Db, Version 1.0.0.0...

If I change the name of one of the methods the problem goes away. Is there a work around to this apart from changing the name? Ideally I would like the overrides to have the same name but deal with different types.

Thanks.

Note: There are questions about finding assemblies that are not referenced but in this case I am asking about the compilation of extension methods and not just a missing assembly reference.

Remotec
  • 10,304
  • 25
  • 105
  • 147

1 Answers1

1

What is the base class of Universe.SolarSystemCelestial?

Its something to do with the return type either being in a different assembly, or one of its base types, or types that it exposes publicly is in the other assembly.

EDIT:

After reading the question again with extra comments, the problem is as stated by @dbugger

One work around would be to have the extension methods in different namespaces, and in calling code only add the namespace you need. So compiler only sees one.

Michal Ciechan
  • 13,492
  • 11
  • 76
  • 118