This is Xamarin's bug tracking system. For product support, please use the support links listed in your Xamarin Account.
Bug 10354 - Unhelpful TypeLoadExceptions when dependencies (using inheritance) missing
: Unhelpful TypeLoadExceptions when dependencies (using inheritance) missing
Status: NEW
Product: Runtime
Classification: Mono
Component: misc
: unspecified
: PC Linux
: --- normal
: ---
Assigned To: Bugzilla
:
:
:
:
  Show dependency treegraph
 
Reported: 2013-02-17 16:39 EST by Andres G. Aragoneses
Modified: 2013-05-17 15:19 EDT (History)
3 users (show)

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


Attachments
Proposed patch (1.49 KB, patch)
2013-02-17 17:24 EST, Andres G. Aragoneses
Details | Diff

Description Andres G. Aragoneses 2013-02-17 16:39:46 EST
(Very similar to bug 8903, but using inheritance instead of fields.)

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 : BazClass {

        public BarClass () {
        }
    }
}
(And compile it linking to Baz.dll)

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

        public class FooClass : BarClass {

            public FooClass () {
            }
        }
    }
}
(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: TypeLoadException
Expected results: FileNotFoundException.
Comment 1 Andres G. Aragoneses 2013-02-17 17:08:12 EST
I've got the patch almost ready, will send a pull request soon.
Comment 2 Andres G. Aragoneses 2013-02-17 17:24:44 EST
Created attachment 3396 [details]
Proposed patch

Meh, I was convinced this patch would work, but it doesn't.

I'll debug the thing tomorrow...
Comment 3 Andres G. Aragoneses 2013-02-17 18:04:45 EST
The patch proposed is obsolete, I've finally fixed it, with this pull request:

https://github.com/mono/mono/pull/566

With the above patch, the result of performing the steps to reproduce are:

Unhandled Exception:
System.IO.FileNotFoundException: Could not load file or assembly 'Baz,
Version=1.0.4796.36127, Culture=neutral, PublicKeyToken=null' or one of its
dependencies.
File name: 'Baz, Version=1.0.4796.36127, Culture=neutral, PublicKeyToken=null'
[ERROR] FATAL UNHANDLED EXCEPTION: System.IO.FileNotFoundException: Could not
load file or assembly 'Baz, Version=1.0.4796.36127, Culture=neutral,
PublicKeyToken=null' or one of its dependencies.
File name: 'Baz, Version=1.0.4796.36127, Culture=neutral, PublicKeyToken=null'
Comment 4 Rodrigo Kumpera 2013-05-17 13:35:35 EDT
I don't think you can rely on the exception been TLE or FNFE.
Comment 5 Andres G. Aragoneses 2013-05-17 13:41:39 EDT
chatlog for the record:

<kumpera> knocte: ping
<knocte> kumpera, pong
<kumpera> regarding https://bugzilla.xamarin.com/show_bug.cgi?id=10354
<kumpera> why is it a problem that it's throw TLE and not FNFE?
<knocte> kumpera: because it can be confusing, as sometimes the type
highlighted in the TLE is not one inside the assembly that is missing, example:
https://bugzilla.xamarin.com/show_bug.cgi?id=8903
<kumpera> oh, ok
<kumpera> makes sense
Comment 6 Rodrigo Kumpera 2013-05-17 14:08:49 EDT
The way to fix this is not to increase the reliance on the thread local loader
error. Experience has shown that using it is very tricky and can quite easily
lead to working stuff be though as been broken because one piece of code forgot
to check for errors.

Said that, the way is to wire up MonoError all around the loader functions so
we can properly bubble up the original one and move toward removing the loader
error stuff from the runtime.
Comment 7 Andres G. Aragoneses 2013-05-17 15:19:51 EDT
Thanks Rodrigo. I would like to paste the last part of the chat-log about this,
to make myself aware (in case in the future I feel like working on this) of the
scary estimate:

<kumpera> knocte: anyways, it's a year+ effort
<kumpera> because we can't neither justify getting someone to work on this full
time
<kumpera> nor do I wish someone working on this fulltime

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