Bug 11199 - Assembly.Load(byte[]) loads cached assemblies
Summary: Assembly.Load(byte[]) loads cached assemblies
Status: RESOLVED FIXED
Alias: None
Product: Runtime
Classification: Mono
Component: General (show other bugs)
Version: master
Hardware: PC All
: --- normal
Target Milestone: ---
Assignee: Aleksey Kliger
URL:
: 11420 (view as bug list)
Depends on:
Blocks:
 
Reported: 2013-03-16 08:20 UTC by Llewellyn Pritchard
Modified: 2018-04-25 21:31 UTC (History)
7 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Compile program to reproduce (5.10 KB, application/octet-stream)
2013-03-16 08:20 UTC, Llewellyn Pritchard
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Llewellyn Pritchard 2013-03-16 08:20:13 UTC
Created attachment 3631 [details]
Compile program to reproduce

When calling Assembly.Load(byte[]) on 2 (or more) different assemblies but with the same name, the initial assembly is loaded and cached for subsequent calls. This is different behavior than in Microsoft's implementation.

Example program:

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

class Program
{
  static void Main(string[] args)
  {
    var class1 = File.ReadAllBytes("Class1/TestLib.dll");
    var class2 = File.ReadAllBytes("Class2/TestLib.dll");
    var ass1 = Assembly.Load(class1);
    Console.WriteLine(ass1.GetExportedTypes()[0].FullName); // should print 'TestLib.Class1'
    var ass2 = Assembly.Load(class2);
    Console.WriteLine(ass2.GetExportedTypes()[0].FullName); // should print 'TestLib.Class2'
  }
}

TestLib.dll only contains 1 class depending on the subdirectory.

In the second case, Mono prints 'TestLib.Class1'.

Sample program attached.

Tested on Mono compiled from source (3.0.8).
Comment 1 Llewellyn Pritchard 2013-05-18 14:42:38 UTC
Is this ever going to be addressed or acknowlegded?
Comment 2 Rodrigo Kumpera 2013-08-23 12:42:38 UTC
We'll get to this bug at some time in the future, thanks for reporting.
Comment 3 Rodrigo Kumpera 2013-08-23 12:44:32 UTC
*** Bug 11420 has been marked as a duplicate of this bug. ***
Comment 4 Ludovic Henry 2018-01-18 21:00:10 UTC
I can reproduce with 5.11.0.276 (master/117468d740a)
Comment 5 Aleksey Kliger 2018-04-25 21:31:43 UTC
This should be fixed in mono master by https://github.com/mono/mono/commit/40c13f7b0ff71bfff8e58f8bd66bca0734d7d284