Bug 10906 - Assembly.Load of mscorlib overrides typeof<System.Object>.Assembly.Location (not so in .NET)
Summary: Assembly.Load of mscorlib overrides typeof<System.Object>.Assembly.Location (...
Alias: None
Product: Runtime
Classification: Mono
Component: General ()
Version: master
Hardware: PC Mac OS
: --- normal
Target Milestone: Future Cycle (TBD)
Assignee: Bugzilla
Depends on:
Reported: 2013-03-05 09:28 UTC by robin.neatherway
Modified: 2018-01-18 20:54 UTC (History)
4 users (show)

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

repro.fs (394 bytes, text/plain)
2018-01-18 20:54 UTC, Ludovic Henry

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 for Bug 10906 on GitHub or Developer Community if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: GitHub Markdown or Developer Community HTML
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:

Description robin.neatherway 2013-03-05 09:28:59 UTC
I have found a mismatch in behaviour between mono and .NET

Mono version: Mono JIT compiler version 3.0.4 (master/e5fba9d Wed Jan 30 18:38:48 GMT 2013)
.NET version: 4.5 from VS2012

Running the simple program below which reads mscorlib.dll into memory and then loads in with Assembly.Load causes Mono to afterwards return the location of mscorlib as the empty string. On .NET the original location of mscorlib is returned.


open System.Reflection
open System

let main args =
  let asmBytes = System.IO.File.ReadAllBytes("/home/scratch/local_mono/lib/mono/4.5/mscorlib.dll")
  printfn "Location of mscorlib: '%s'" (typeof<System.Object>.Assembly.Location)
  let assm = Assembly.Load(asmBytes)
  printfn "Location of mscorlib: '%s'" (typeof<System.Object>.Assembly.Location)


Location of mscorlib: '/home/scratch/local_mono/lib/mono/4.5/mscorlib.dll'
Location of mscorlib: ''

On Windows I change ReadAllBytes to load from @"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\mscorlib.dll", and the output is:

Location of mscorlib: 'C:\Windows\Microsoft.NET\Framework64\v4.0.30319\mscorlib.
Location of mscorlib: 'C:\Windows\Microsoft.NET\Framework64\v4.0.30319\mscorlib.

This causes problems if you try to do this during xbuild because some tasks (in my case the Fsc task) try to find the mono location and call into MonoLocationHelper.cs:47 which is below:

assemblyLocation = Path.GetDirectoryName (typeof (object).Assembly.Location);

This line then returns the empty string and everything goes wrong from there.
Comment 1 Marek Safar 2016-04-16 08:42:23 UTC
This looks like .net does some assembly interning
Comment 2 Ludovic Henry 2018-01-18 20:52:52 UTC
I can reproduce with Mono (master/117468d740a) with attachment.
Comment 3 Ludovic Henry 2018-01-18 20:54:17 UTC
Created attachment 26096 [details]

To reproduce:

 - install Mono PKG on macOS
 - fsharpc repro.fs
 - mono repro.exe