Assembly.GetTypes Exception

D

Dan Holmes

Assembly a =
Assembly.LoadFrom(@"c:\sandbox\iaf.net\serverinstall\IVS.WMS.Category.Server.dll");
Type []t = a.GetTypes();

The GetTypes fails with this message:

"System.TypeLoadException: Could not load type
'IVS.WMS.Product.ICategoryService' from assembly
'IVS.WMS.Category.Common, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null'."

What i don't get is that the interface it says it can't load isn't used
in the code being loaded. To make it more confusing
IVS.WMS.Category.Common has an interface of that name.

Ideas?

dan
 
L

Lasse Vågsæther Karlsen

Dan said:
Assembly a =
Assembly.LoadFrom(@"c:\sandbox\iaf.net\serverinstall\IVS.WMS.Category.Server.dll");

Type []t = a.GetTypes();

The GetTypes fails with this message:

"System.TypeLoadException: Could not load type
'IVS.WMS.Product.ICategoryService' from assembly
'IVS.WMS.Category.Common, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null'."

What i don't get is that the interface it says it can't load isn't used
in the code being loaded. To make it more confusing
IVS.WMS.Category.Common has an interface of that name.

Ideas?

dan

Are you sure your dll containing the interface you claim is being used
is the same as the one being referenced?

I've seen this problem in the following scenario:

1. application references and uses code from dll A version 1
2. application also references and uses code from dll B
3. dll B references dll A version 2, but no code that would use that dll
is actually being called, so should not be a problem
4. application is only shipped with dll A version 1 (but shouldn't be a
problem)

unless... you start itering with reflection and GetTypes()... then you
might end up trying to load a referenced assembly that isn't actually
present, which would otherwise not be a problem since no code from that
assembly is actually needed to run your application.

So to start with, I would check the references and see which versions
they add. Also note that I think VS2005 lists the version of the dll
found in the property window for a reference, instead of the version the
project actually references. Ie. if the project added the reference to
version 1.0.0.0 of the dll, and you later replace the dll with version
1.0.0.1, the project will reference 1.0.0.0, but the property window
might show 1.0.0.1. I'm not entirely sure about this but I've always
found that removing and readding the references fixes these problems.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top