This is Xamarin's bug tracking system. For product support, please use the support links listed in your Xamarin Account.
Bug 8903 - Unhelpful TypeLoadExceptions when dependencies (using fields) missing
: Unhelpful TypeLoadExceptions when dependencies (using fields) missing
Status: RESOLVED FIXED
Product: Runtime
Classification: Mono
Component: misc
: unspecified
: All All
: --- normal
: ---
Assigned To: Bugzilla
:
:
:
:
  Show dependency treegraph
 
Reported: 2012-12-12 10:34 EST by Andres G. Aragoneses
Modified: 2013-02-17 12:59 EST (History)
3 users (show)

See Also:
Tags:
Test Case URL:
External Submit: ---


Attachments

Description Andres G. Aragoneses 2012-12-12 10:34:39 EST
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 EST
This case is now fixed, i.e. we throw a FileNotFoundException instead.
Comment 2 Andres G. Aragoneses 2013-02-17 12:59:04 EST
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.

Note You need to log in before you can comment on or make changes to this bug.