The fully qualified name for my type is provided but when I run the program it looks for the type in the wrong assembly

Viewed 46

When I run my WCF service, I get the error

"Could not load type 'CompanyName.Services.WCF.GenericNotes.Entities.GenericNote' from assembly 'CompanyName.Services.WCF.GenericNotes, Version=1.2.0.7,Culture=neutral,PublicKeyToken=null'.

True enough, the GenericNote type is not in CompanyName.Services.WCF.GenericNotes, but it is in the CompanyName.Services.WCF.GenericNotes.ENTITIES assembly, the dll for which is included in my program's directory. I determined that this type is needed by a client I'm instantiating by looking at the client's definition from metadata, so I cannot touch the file that actually looks for the type. The proper 'using' directives were provided there. How come .NET is looking for the type in the wrong assembly even though the full name is provided? How does it determine where to look for a type?

1 Answers

This scenario usually happens for one of two reasons:

  1. there is an incorrect assembly specified (as text) in a config file - check the config files that your application is using
  2. a type has been moved between assemblies; meaning: when SomeAssembly.dll was compiled, the type was in CompanyName.Services.WCF.GenericNotes.dll, but it has since moved to CompanyName.Services.WCF.GenericNotes.Entities.dll and you SomeAssembly.dll has not been rebuilt with that dependency; for this, there are two options:
    1. rebuild SomeAssembly.dll with the updated dependencies, or
    2. add [TypeForwardedTo(typeof(CompanyName.Services.WCF.GenericNotes.Entities.GenericNote))] to 'CompanyName.Services.WCF.GenericNotes.dll and rebuild it (note that this requires a dependency to the project that now has the type); this attribute is used by the runtime to resolve types that have moved (note that there is also [TypeForwardedFrom(...)] in some frameworks, which works similarly but with different directionality)
Related