Bug 320908 (MONO78165) - Assembly.LoadFrom loads the wrong assembly
Summary: Assembly.LoadFrom loads the wrong assembly
Status: RESOLVED DUPLICATE of bug 318022
Alias: MONO78165
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-04-22 21:38 UTC by Colin JN Breame
Modified: 2008-02-27 11:15 UTC (History)
1 user (show)

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


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Wiest 2007-09-15 19:56:09 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".

Comment 1 Kornél Pál 2008-02-27 11:15:14 UTC

*** This bug has been marked as a duplicate of bug 318022 ***