This is Xamarin's bug tracking system. For product support, please use the support links listed in your Xamarin Account.
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: NEW
Alias: None
Product: Runtime
Classification: Mono
Component: Reflection (show other bugs)
Version: 4.2.0 (C6)
Hardware: PC Linux
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2013-03-05 09:28 UTC by robin.neatherway
Modified: 2016-04-16 08:42 UTC (History)
3 users (show)

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


Attachments

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

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