Bug 8903 - Unhelpful TypeLoadExceptions when dependencies (using fields) missing
Summary: Unhelpful TypeLoadExceptions when dependencies (using fields) missing
Status: RESOLVED FIXED
Alias: None
Product: Runtime
Classification: Mono
Component: General (show other bugs)
Version: unspecified
Hardware: All All
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2012-12-12 10:34 UTC by Andres G. Aragoneses
Modified: 2013-02-17 12:59 UTC (History)
3 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Andres G. Aragoneses 2012-12-12 10:34:39 UTC
Steps to reproduce:

1. Create a library called "Baz" with this class:
namespace Baz {
	public class BazClass {
		public BazClass () {
		}
	}
}

2. Create a library called "Bar" with this class:
namespace Bar {
	public class BarClass {

		public BarClass () {
		}

		Baz.BazClass baz;
	}
}
(And compile it linking to Baz.dll)

3. Create a console program "Foo" with this class:
using System;
namespace Foo {
	class FooClass {
		public static void Main (string[] args) {
			Console.WriteLine ("begin");
			try {
				new Bar.BarClass ();
			}
			catch (Exception ex) {
				Console.WriteLine ("WTF: " + ex.ToString ());
			}
			Console.WriteLine ("end");
		}
	}
}
(And compile it linking to Bar.dll)

4. Compile Foo.
5. Go to Foo/bin/Debug, and delete Baz.dll.
6. Run Foo (mono Foo.exe)

Current results:
Unhandled Exception:
System.TypeLoadException: Could not load type 'Bar.BarClass' from assembly 'Bar, Version=1.0.4729.26388, Culture=neutral, PublicKeyToken=null'.
[ERROR] FATAL UNHANDLED EXCEPTION: System.TypeLoadException: Could not load type 'Bar.BarClass' from assembly 'Bar, Version=1.0.4729.26388, Culture=neutral, PublicKeyToken=null'.

Expected results:
At least, the TypeLoadException should mention Baz assembly or type, not Bar's!!! This is extremely confusing.

MS.NET results:
Microsoft's runtime is even smarter and figures out that it doesn't need Baz.dll at runtime, so it doesn't throw any exception.
Comment 1 Zoltan Varga 2013-01-05 04:36:53 UTC
This case is now fixed, i.e. we throw a FileNotFoundException instead.
Comment 2 Andres G. Aragoneses 2013-02-17 12:59:04 UTC
Thanks for that (https://github.com/mono/mono/commit/25ff420550e1012488e2897f30f1c91ffd01abef). Unfortunately I've found another case of this bug, so I'll rename this to a more specific name, and I'll open a new bug later.