TypeLoadException

  • Thread starter Thread starter kartik.vad
  • Start date Start date
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.
 
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?
 
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.
 
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 :)
 
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)?
 
Back
Top