TypeLoadException

K

kartik.vad

I try to run an executable (test.exe) that depends on an assembly
(AdderNamespace.dll) which exists in the same directory, and I get the
following exception:

Unhandled Exception: System.TypeLoadException: Could not load type
'AdderNamespace.Container' from assembly 'AdderNamespace,
Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'.
at AdderNamespace.Factory.New()
at addertest.Class1.Main()

ILDASM reports that the offending type AdderNamespace.Container indeed
exists. It's public. I have full access to the assembly file, and the
version number of the file matches the one in the error message.

Some of the DLLs the executable (indirectly) depends on have probably
been built with .NET 2 beta, and I'm now using the release version. I
also have 1.1 installed, though I think 2.0 is the one being used (I
notice disk accesses to \WINDOWS\Microsoft.NET\Framework\v2.0.50727
rather than the folder for 1.1)

What could have gone wrong, and how do I fix it? Thank you.
 
K

kartik.vad

I got it solved! It turned out that a dependent DLL was missing and the
CLR's message did not say Assembly Not Found but: Could not load type
from existing assembly". (I seem to get a message of the former kind
when an assembly that the executable directly depends on is missing,
but not if it indirectly depends on the missing assembly.)

I got this info from:
http://blogs.msdn.com/suzcook/archive/2003/05/29/57120.aspx

Sorry for the premature posting. But I wonder: if the CLR can't find an
assembly, why doesn't it say so?
 
J

Jon Skeet [C# MVP]

I try to run an executable (test.exe) that depends on an assembly
(AdderNamespace.dll) which exists in the same directory, and I get the
following exception:

Unhandled Exception: System.TypeLoadException: Could not load type
'AdderNamespace.Container' from assembly 'AdderNamespace,
Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'.
at AdderNamespace.Factory.New()
at addertest.Class1.Main()

ILDASM reports that the offending type AdderNamespace.Container indeed
exists. It's public. I have full access to the assembly file, and the
version number of the file matches the one in the error message.

Some of the DLLs the executable (indirectly) depends on have probably
been built with .NET 2 beta, and I'm now using the release version. I
also have 1.1 installed, though I think 2.0 is the one being used (I
notice disk accesses to \WINDOWS\Microsoft.NET\Framework\v2.0.50727
rather than the folder for 1.1)

What could have gone wrong, and how do I fix it? Thank you.

I suspect the problem is that it can't load the AdderNamespace assembly
because it depends on beta assemblies which are no longer available.

Rebuild all the assemblies which refer to beta assemblies, and I expect
the problem will go away.
 
J

Jon Skeet [C# MVP]

I got it solved! It turned out that a dependent DLL was missing and the
CLR's message did not say Assembly Not Found but: Could not load type
from existing assembly". (I seem to get a message of the former kind
when an assembly that the executable directly depends on is missing,
but not if it indirectly depends on the missing assembly.)

I got this info from:
http://blogs.msdn.com/suzcook/archive/2003/05/29/57120.aspx

Sorry for the premature posting. But I wonder: if the CLR can't find an
assembly, why doesn't it say so?

Did you look at the inner exception of the original TypeLoadException?
That might have had more information.

(For what it's worth, I've just tried to reproduce the problem, and not
managed it - I suspect it needs to be a bit more involved than my
little sample code :)
 
K

kartik.vad

Did you look at the inner exception of the original TypeLoadException?
No - I didn't know there was an inner exception because there was no
mention of it in the stack trace. Why doesn't the CLR print out this
information (like the JVM does)?
 

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