Bug 99 - InternalsVisibleToAttribute causes FileLoadException when friend assembly is not present
Summary: InternalsVisibleToAttribute causes FileLoadException when friend assembly is ...
Alias: None
Product: Runtime
Classification: Mono
Component: General ()
Version: unspecified
Hardware: Other Other
: Normal normal
Target Milestone: ---
Assignee: Marek Habersack
Depends on:
Reported: 2011-07-28 13:12 UTC by Gabor Simon
Modified: 2011-08-10 20:30 UTC (History)
4 users (show)

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

Sample project to reproduce compiler crash (299.17 KB, application/zip)
2011-07-30 06:45 UTC, Gabor Simon

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:

Description Gabor Simon 2011-07-28 13:12:36 UTC
Description of Problem: when one tries to build a project referencing assembly with InternalsVisibleToAttribute (e.g. MySql.Data.dll v3.6.7+) and the friend assemblies (for MySql - MySql.Data.Tests) are not present FileLoadException occurs.

Steps to reproduce the problem:
1. Add a reference for MySql.Data.dll (v3.6.7+)
2. Try to compile

Actual Results:
Unhandled Exception: System.IO.FileLoadException: The assembly name is invalid.
  at System.Reflection.AssemblyName..ctor (System.String assemblyName) [0x00000] in <filename unknown>:0 
  at Mono.CSharp.ImportedAssemblyDefinition.ReadAttributes () [0x00000] in <filename unknown>:0 
  at Mono.CSharp.MetadataImporter.GetAssemblyDefinition (System.Reflection.Assembly assembly) [0x00000] in <filename unknown>:0 
  at Mono.CSharp.ReflectionImporter.ImportAssembly (System.Reflection.Assembly assembly, Mono.CSharp.RootNamespace targetNamespace) [0x00000] in <filename unknown>:0 
  at Mono.CSharp.DynamicLoader.LoadReferences (Mono.CSharp.ModuleContainer module) [0x00000] in <filename unknown>:0 
  at Mono.CSharp.Driver.Compile () [0x00000] in <filename unknown>:0 
  at Mono.CSharp.Driver.Main (System.String[] args) [0x00000] in <filename unknown>:0 

Expected Results:
No exception.

How often does this happen? 

Additional Information:
Mono version: 2.10.2
I was able trace the exception in ImportedAssemblyDefinition.ReadAttributes function: in the if (name == "InternalsVisibleToAttribute") block calls AssemblyName ctor without checking first wether friend assembly can be found or not.
Comment 1 Miguel de Icaza [MSFT] 2011-07-29 16:54:04 UTC
Please provide a self-contained test case that we can use to reproduce this case.

Reset priority, since you have a workaround.
Comment 2 Gabor Simon 2011-07-30 06:45:40 UTC
Created attachment 38 [details]
Sample project to reproduce compiler crash
Comment 3 Gabor Simon 2011-07-30 06:52:51 UTC
Additional info: only affects dmcs (not gmcs)
Comment 4 Marek Safar 2011-08-05 05:10:08 UTC
It's actually runtime bug

using System;
using System.Reflection;

class Tester
	public static int Main ()
		var an = new AssemblyName ("MySql.Data.Tests, PublicKey = 0024000004800000940000000602000000240000525341310004000001000100d973bda91f71752c78294126974a41a08643168271f65fc0fb3cd45f658da01fbca75ac74067d18e7afbf1467d7a519ce0248b13719717281bb4ddd4ecd71a580dfe0912dfc3690b1d24c7e1975bf7eed90e4ab14e10501eedf763bff8ac204f955c9c15c2cf4ebf6563d8320b6ea8d1ea3807623141f4b81ae30a6c886b3ee1");
		return 0;

Work on .NET fails on Mono with

Unhandled Exception: System.IO.FileLoadException: The assembly name is invalid.
  at System.Reflection.AssemblyName..ctor (System.String assemblyName) [0x00000] in <filename unknown>:0 
  at Tester.Main () [0x00000] in <filename unknown>:0
Comment 5 Marek Habersack 2011-08-10 20:30:38 UTC
Fixed in commits 209c253e3f5f49683bb0fc64afee2045b12173a8 (master), e449d41158a205581e7519cc961b7c618f6163a8 and 209c253e3f5f49683bb0fc64afee2045b12173a8 (mono-2-10 branch)