Bug 10126 - Module initializer and assembly resolve
Summary: Module initializer and assembly resolve
Status: CONFIRMED
Alias: None
Product: Runtime
Classification: Mono
Component: General (show other bugs)
Version: unspecified
Hardware: PC Windows
: Normal enhancement
Target Milestone: Future Cycle (TBD)
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2013-02-07 11:45 UTC by Erik Källén
Modified: 2017-07-14 23:56 UTC (History)
4 users (show)

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


Attachments
Program to demonstrate the behavior (5.38 MB, application/x-msdownload)
2013-02-07 11:45 UTC, Erik Källén
Details

Description Erik Källén 2013-02-07 11:45:06 UTC
Created attachment 3342 [details]
Program to demonstrate the behavior

The attached program has all its references embedded as resources. It also contains a module initializer that adds an AppDomain.AssemblyResolve event handler to load these assemblies. This operation works in .net, but it fails on Mono 3.0.3
Comment 1 Sergey Alekseev 2014-02-07 06:06:53 UTC
I believe this bug is present for ages.

I tried to test it with 3.2.6:

$ MONO_LOG_LEVEL=info MONO_LOG_MASK=asm mono sc.exe
Mono: Assembly Loader probing location: '/opt/mono-3.2.6/lib/mono/4.5/mscorlib.dll'.
Mono: Image addref mscorlib[0x9f36f28] -> /opt/mono-3.2.6/lib/mono/4.5/mscorlib.dll[0x9f36590]: 2
Mono: Assembly Loader probing location: '/opt/mono-3.2.6/lib/mono/4.5/mscorlib.dll'.
Mono: Assembly Loader loaded assembly from location: '/opt/mono-3.2.6/lib/mono/4.5/mscorlib.dll'.
Mono: Assembly mscorlib[0x9f36f28] added to domain sc.exe, ref_count=1
Mono: Assembly Loader probing location: 'sc.exe'.
Mono: Image addref sc[0xb5500590] -> /home/vagrant/test/sc.exe[0x9f359d0]: 3
Mono: Assembly sc[0xb5500590] added to domain sc.exe, ref_count=1
Mono: Assembly Loader loaded assembly from location: 'sc.exe'.
Mono: Assembly Loader probing location: 'sc.exe'.
Mono: Assembly Ref addref sc[0xb5500590] -> mscorlib[0x9f36f28]: 2
Mono: Assembly Loader probing location: '/home/vagrant/test/Saltarelle.Compiler.dll'.
Mono: Assembly Loader probing location: '/opt/mono-3.2.6/lib/Saltarelle.Compiler.dll'.
Mono: Assembly Loader probing location: '/opt/mono-3.2.6/lib/mono/4.5/Facades/Saltarelle.Compiler.dll'.
Mono: Assembly Loader probing location: '/home/vagrant/test/Saltarelle.Compiler.exe'.
Mono: Assembly Loader probing location: '/opt/mono-3.2.6/lib/Saltarelle.Compiler.exe'.
Mono: Assembly Loader probing location: '/opt/mono-3.2.6/lib/mono/4.5/Facades/Saltarelle.Compiler.exe'.
Mono: The following assembly referenced from /home/vagrant/test/sc.exe could not be loaded:
     Assembly:   Saltarelle.Compiler    (assemblyref_index=1)
     Version:    2.0.0.0
     Public Key: (none)
The assembly was not found in the Global Assembly Cache, a path listed in the MONO_PATH environment variable, or in the location of the executing assembly (/home/vagrant/test/).

Mono: Failed to load assembly sc[0xb5500590]

Mono: Could not load file or assembly 'Saltarelle.Compiler, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies.

Unhandled Exception:
System.IO.FileNotFoundException: Could not load file or assembly 'Saltarelle.Compiler, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies.
File name: 'Saltarelle.Compiler, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null'
[ERROR] FATAL UNHANDLED EXCEPTION: System.IO.FileNotFoundException: Could not load file or assembly 'Saltarelle.Compiler, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies.
File name: 'Saltarelle.Compiler, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null'



I've been trying to use this feature for quite some time. I'm using Costura.Fody to embed assemblies.
And it seems like exception is thrown somewhere after /mono/metadata/assembly.c:1108 (mono_assembly_load_reference)
Comment 2 Rodrigo Kumpera 2017-07-14 23:56:31 UTC
Mono doesn't handle module ctors correctly.

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