Bugzilla – Bug 320908
Assembly.LoadFrom loads the wrong assembly
Last modified: 2008-02-27 11:15:14 UTC
---- Reported by colin@breame.net 2006-04-22 14:38:17 MST ---- If the current directory contains: test.exe test.dll And we ask it load "test.dll" it insteads loads "test.exe". Compile and run the program below. It outputs: hello from test.exe but should output (as LoadFrom's parameter is test.dll /not/ test.exe): hello from test.dll Am I missing something? make.sh: mcs -out:test.exe test_exe.cs mcs -out:test.dll -target:library test_dll.cs test_exe.cs: sing System; using System.Reflection; public class Test { public static void Main() { Assembly assembly = Assembly.LoadFrom("test.dll"); object o = assembly.CreateInstance("Test"); Console.WriteLine(o.ToString()); } public override string ToString() { return "hello from test.exe"; } } test_dll.cs: public class Test { public override string ToString() { return "hello from test.dll"; } } ---- Additional Comments From robertj@gmx.net 2006-04-22 18:28:22 MST ---- The bug is in assembly.c:mono_assembly_load_from_full () It uses search_loaded () to find out whether the assembly is already loaded. Since the search is based on the AssemblyName, it returns the wrong assembly if 2 different assemblies have the same name, like in the test case above. The test case works on MS.NET as expected. Colin, despite of the bug (if it's one), giving 2 assemblies the same name is a bad idea. Even if the files are called test.dll and test.exe, the AssemblyName is "test" because the extension is not relevant. If you really need test.exe and test.dll, compile the exe into another file using mcs /out:testapp.exe and rename it to test.exe ---- Additional Comments From vargaz@gmail.com 2006-04-22 20:43:22 MST ---- Can be considered a dup of: https://bugzilla.novell.com/show_bug.cgi?id=MONO74982 Unknown operating system unknown. Setting to default OS "Other".
*** This bug has been marked as a duplicate of bug 318022 ***