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 (...
Status: CONFIRMED
Alias: None
Product: Runtime
Classification: Mono
Component: General (show other bugs)
Version: master
Hardware: PC Mac OS
: --- normal
Target Milestone: Future Cycle (TBD)
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2013-03-05 09:28 UTC by robin.neatherway
Modified: 2018-01-18 20:54 UTC (History)
4 users (show)

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


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

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.


Program:

open System.Reflection
open System

[<EntryPoint>]
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)
  0

Output:

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.
dll'
Location of mscorlib: 'C:\Windows\Microsoft.NET\Framework64\v4.0.30319\mscorlib.
dll'


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 5.11.0.276 (master/117468d740a) with attachment.
Comment 3 Ludovic Henry 2018-01-18 20:54:17 UTC
Created attachment 26096 [details]
repro.fs

To reproduce:

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

Note You need to log in before you can comment on or make changes to this bug.