Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeLoadException thrown erroniously

Tags:

c#

winforms

In a simple app I'm working on, I've got three related assemblies:

  1. "MyCompany.Geography.Windows.Forms" which is a class library with the winforms controls in it
  2. "MyCompany.Geography" which has some definitions for some base types and the like.
  3. "MyCompany.Geography.Windows" which is a quick knock up app with a simple form, and one of the controls dropped on it as a basic test harness.

Now, everything was going well and I could drop my control on tot he form in the designer, and it merrily added the relevant references, but when I try and actually run it under debug, I get:

System.TypeLoadException occurred
  Message="Could not load type 'MyCompany.Geography.Windows.Forms.MyControl' from assembly 'MyCompany.Geography.Windows, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'."
  Source="MyCompany.Geography.Windows"
  TypeName="MyCompany.Geography.Windows.Forms.MyControl"
  StackTrace:
       at MyCompany.Geography.Windows.Form1.InitializeComponent()
       at MyCompany.Geography.Windows.Form1..ctor() in ...\Projects\MyCompany.Geography\MyCompany.Geography.Windows\Form1.cs:line 10
  InnerException: 

Normally I'd go and look at the inner exception, but there is none. the bit that's really confusing me is that I'd have exepcted it to have followed the reference, and looked in there, and I'm a bit stuck as to what to check?

like image 679
Rowland Shaw Avatar asked Nov 18 '25 00:11

Rowland Shaw


1 Answers

Make sure that the executable application references both MyCompany.Geography.Windows.Forms.dll and MyCompany.Geography.dll.

Have you checked the Output window during the debug session for any information about failing to load the assembly? It could also be related to conflicting versions of the assembly. When the application breaks into the debugger at the point of the exception, open the Modules window (Debug -> Windows -> Modules) and see if the assemblies are in fact loaded.

like image 96
Josh Avatar answered Nov 20 '25 14:11

Josh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!