Bug 322132 (MONO79426) - [PATCH] Assembly loader failures result in FileNotFoundException with message equal to filename
Summary: [PATCH] Assembly loader failures result in FileNotFoundException with message...
Status: RESOLVED FIXED
Alias: MONO79426
Product: Mono: Runtime
Classification: Mono
Component: misc (show other bugs)
Version: 1.1
Hardware: Other Other
: P3 - Medium : Normal
Target Milestone: ---
Assignee: Mono Bugs
QA Contact: Mono Bugs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-09-17 18:02 UTC by Gert Driesen
Modified: 2007-09-15 21:24 UTC (History)
0 users

See Also:
Found By: ---
Services Priority:
Business Priority:
Blocker: ---
Marketing QA Status: ---
IT Deployment: ---


Attachments
Fix (3.05 KB, patch)
2006-09-17 18:06 UTC, Thomas Wiest
Details | Diff
Runtime patch (4.50 KB, patch)
2006-09-20 00:01 UTC, Thomas Wiest
Details | Diff
corlib patch (17.91 KB, patch)
2006-09-20 00:02 UTC, Thomas Wiest
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Wiest 2007-09-15 20:10:22 UTC


---- Reported by gert.driesen@pandora.be 2006-09-17 11:02:04 MST ----

When an assembly cannot be loaded, we currently construct a 
FileNotFoundException with a message equal to the filename or assembly 
name of the assembly that could not be loaded.

To reproduce, compile and run the following code snippet:

using System;
using System.IO;
using System.Reflection;

public class Test {
  static void Main () {
    try {
      Assembly.LoadFrom ("b.dll");
    } catch (FileNotFoundException ex) {
      Console.WriteLine ("*** #1 ***");
      Console.WriteLine ("Message: " + ex.Message);
      Console.WriteLine ("FileName: " + ex.FileName);
    }

    try {
      Assembly.Load ("whatever");
    } catch (FileNotFoundException ex) {
      Console.WriteLine ("*** #2 ***");
      Console.WriteLine ("Message: " + ex.Message);
      Console.WriteLine ("FileName: " + ex.FileName);
    }

    try {
      AppDomain.CurrentDomain.ExecuteAssembly ("c.dll");
    } catch (FileNotFoundException ex) {
      Console.WriteLine ("*** #3 ***");
      Console.WriteLine ("Message: " + ex.Message);
      Console.WriteLine ("FileName: " + ex.FileName);
    }
  }
}

Actual result:

*** #1 ***
Message: b.dll
FileName: b.dll
*** #2 ***
Message: whatever
FileName: whatever
*** #3 ***
Message: c.dll
FileName: c.dll

Expected result:

*** #1 ***
Message: Could not load file or assembly 'b.dll' or one of its 
dependencies. The system cannot find the file specified.
FileName: b.dll
*** #2 ***
Message: Could not load file or assembly 'whatever' or one of its 
dependencies. The system cannot find the file specified.
FileName: whatever
*** #3 ***
Message: Could not load file or assembly 'c.dll' or one of its 
dependencies. The system cannot find the file specified.
FileName: c.dll

Note: 

without this fix, the ToString () of the FileNotFoundException for these 
load errors would just be the name of the file (or the assembly name), 
which doesn't tell very much (unless you know that it concerns a 
FileNotFoundException).



---- Additional Comments From gert.driesen@pandora.be 2006-09-17 11:06:40 MST ----

Created an attachment (id=170495)
Fix




---- Additional Comments From vargaz@gmail.com 2006-09-17 11:28:24 MST ----

I think the proper fix is to fix FileNotFoundException to set the
message in the ctor, i.e.

	  try {
		  throw new FileNotFoundException (null, "foo.dll");
	  }
	  catch (Exception ex) {
		  Console.WriteLine (ex.Message);
	  }

prints 'File or assembly name foo.dll, or one of its dependencies
was not found' on MS.NET, but not on mono.




---- Additional Comments From gert.driesen@pandora.be 2006-09-17 11:50:36 MST ----

You're right of course.

I'll attach a new patch (for both runtime and corlib) tomorrow or so.



---- Additional Comments From gert.driesen@pandora.be 2006-09-19 17:01:17 MST ----

Created an attachment (id=170496)
Runtime patch




---- Additional Comments From gert.driesen@pandora.be 2006-09-19 17:02:08 MST ----

Created an attachment (id=170497)
corlib patch




---- Additional Comments From gert.driesen@pandora.be 2006-09-19 17:06:20 MST ----

Zoltan, I've attach two new patches: one for corlib, and one for 
runtime.

The corlib patch changes FileNotFoundException to match MS, and 
introduces some unit tests for it.

The runtime match modifies the signature of 
mono_get_exception_file_not_found2 to take a MonoString instead of 
char for the msg argument. We now pass NULL as msg where 
appropriate, and construct a MonoString from char where a message 
was actually passed in.

Let me know if there's anything I should change.



---- Additional Comments From vargaz@gmail.com 2006-09-20 12:22:19 MST ----

This looks ok to check in, altough I don't really understand why
the mono_get_exception_file_not_found2 signature needs to be changed,
the original one seemed just fine.




---- Additional Comments From gert.driesen@pandora.be 2006-09-20 12:29:01 MST ----

I'm a total C newbie, so if you can tell me how I pass NULL as msg 
with the original mono_get_exception_file_not_found2 signature, I'll 
revert that change.



---- Additional Comments From vargaz@gmail.com 2006-09-20 14:40:41 MST ----

Just pass NULL.




---- Additional Comments From gert.driesen@pandora.be 2006-09-20 15:17:46 MST ----

That doesn't work (which I why I changed the signature) as it 
introduces a SIGSEGV:

=================================================================
Got a SIGSEGV while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries 
used by your application.
=================================================================

Stacktrace:

  at (wrapper managed-to-native) System.Reflection.Assembly.LoadFrom 
(string,bool) <0x00004>
  at (wrapper managed-to-native) System.Reflection.Assembly.LoadFrom 
(string,bool) <0xffffffff>
  at System.Reflection.Assembly.LoadFrom (string) <0x0000c>
  at Test.Main () <0x008fe>
  at (wrapper runtime-invoke) System.Object.runtime_invoke_int 
(object,intptr,intptr,intptr) <0xffffffff>

Native stacktrace:

	mono(mono_handle_native_sigsegv+0xf5) [0x81685b5]
	mono [0x8152553]
	[0xffffe440]
	mono(mono_get_exception_file_not_found2+0x1b) [0x80f139b]
	mono [0x80be846]
	[0xb7ba1d7b]
	[0xb7ba1d35]
	[0xb7b9d7f7]
	[0xb7b9c7cf]
	mono(mono_runtime_exec_main+0x13c) [0x80df02c]
	mono(mono_runtime_run_main+0x21f) [0x80df2bf]
	mono(mono_main+0xf07) [0x805d5f7]
	mono [0x805c23e]
	/lib/tls/libc.so.6(__libc_start_main+0xdc) [0xb7deeeec]
	mono [0x805c181]




---- Additional Comments From vargaz@gmail.com 2006-09-20 15:58:44 MST ----

Just change the following line in file_not_found2:
	MonoString *s = mono_string_new (mono_domain_get (), msg);
to
        MonoString *s = msg ? mono_string_new (mono_domain_get (),
msg) : NULL;



---- Additional Comments From gert.driesen@pandora.be 2006-09-21 16:00:50 MST ----

Fixed in svn.

Imported an attachment (id=170495)
Imported an attachment (id=170496)
Imported an attachment (id=170497)

Unknown operating system unknown. Setting to default OS "Other".