Bug 30448 - Cecil loads referenced assemblies from GAC specific to the running application, not the referencing library
Summary: Cecil loads referenced assemblies from GAC specific to the running applicatio...
Status: RESOLVED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: WindowsBase ()
Version: master
Hardware: PC Linux
: --- normal
Target Milestone: Untriaged
Assignee: Marek Safar
URL:
Depends on:
Blocks:
 
Reported: 2015-05-26 11:11 UTC by Piotr Zierhoffer
Modified: 2015-06-08 08:23 UTC (History)
3 users (show)

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


Attachments
Failing source code (680 bytes, text/x-csharp)
2015-05-26 11:11 UTC, Piotr Zierhoffer
Details
The project with failing DLL (410.00 KB, application/gzip)
2015-05-26 11:14 UTC, Piotr Zierhoffer
Details
Updated, much simpler test case (2.76 MB, application/gzip)
2015-06-08 08:10 UTC, Piotr Zierhoffer
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 Piotr Zierhoffer 2015-05-26 11:11:34 UTC
Created attachment 11330 [details]
Failing source code

I have a code that analyses .NET DLLs with Cecil. One of this DLL is Xwt, containing a struct Xwt.Size with ValueSerializerAttribute defined.

I have bisected Mono and verified that commit 830bf66a13ea18dd8c6f67203d9a70b20349f1d6 breaks my logic - Resolve returns null. Before this commit everything works fine (and this commit description seems relevant).

As my test case requires Xwt.dll (compiled by me with the same Mono, tested many versions), I post both analyzer code and an archive with it.

I have tried to extract a simpler case from this DLL, but failed, anything simpler works for me.

Steps to reproduce the problem:
1. Compile Program.cs in Debug or Release (Cecil library is fetched by NuGet)
2. Go to Debug/Release directory
3. Run

Expected results:
List of analyzed types and attributes in form similar to:

[...]
Xwt.PasswordEntry: 1 attributes
	Xwt.Backends.BackendTypeAttribute
Xwt.PasswordEntry/WidgetBackendHost: 0 attributes
Xwt.PreviewTextInputEventArgs: 0 attributes
Xwt.Widget: 1 attributes
	Xwt.Backends.BackendTypeAttribute
[...]


Actual results:
A beginning of this list, ending with NRE (thrown from code):

[...]
Xwt.Point: 0 attributes
Xwt.Size: 2 attributes
	System.ComponentModel.TypeConverterAttribute
	System.Windows.Markup.ValueSerializerAttribute

Unhandled Exception:
System.NullReferenceException: Resolve returned null!
  at test31.MainClass.Main (System.String[] args) [...]
Comment 1 Piotr Zierhoffer 2015-05-26 11:14:32 UTC
Created attachment 11331 [details]
The project with failing DLL
Comment 2 Piotr Zierhoffer 2015-06-08 07:25:21 UTC
I believe I have found the actual issue.

The Xwt library was compiled against framework 4.0, and the app - 4.5.

ValueSerializerAttribute was moved from System.Xaml to System between this version.

So, TypeRef in Xwt.dll pointed to System.Xaml.dll, but Cecil opened the file from the current GAC - 4.5. Of course, there was no such type found, so Resolve failed.

It works on Windows/.NET, so I believe this is mono-specific code (BaseAssemblyResolver.GetAssemblyInGac is platform-specific).
Comment 3 Piotr Zierhoffer 2015-06-08 07:32:13 UTC
I believe I have found the actual issue.

The Xwt library was compiled against framework 4.0, and the app - 4.5.

ValueSerializerAttribute was moved from System.Xaml to System between this version.

So, TypeRef in Xwt.dll pointed to System.Xaml.dll, but Cecil opened the file from the current GAC - 4.5. Of course, there was no such type found, so Resolve failed.

It works on Windows/.NET, so I believe this is mono-specific code (BaseAssemblyResolver.GetAssemblyInGac is platform-specific).
Comment 4 Piotr Zierhoffer 2015-06-08 08:10:19 UTC
Created attachment 11504 [details]
Updated, much simpler test case

This does not reference Xwt, but a simple library with attribute. The library is compiled against framework 4.0, the app - 4.5.
Comment 5 Marek Safar 2015-06-08 08:23:59 UTC
Fixed in master