Bug 7505 - FileNotFoundException when probing assemblies should provide more context.
Summary: FileNotFoundException when probing assemblies should provide more context.
Status: RESOLVED FIXED
Alias: None
Product: Android
Classification: Xamarin
Component: MSBuild ()
Version: 4.2.x
Hardware: PC Mac OS
: Low enhancement
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2012-09-27 10:25 UTC by Jonathan Pryor
Modified: 2018-04-16 16:07 UTC (History)
4 users (show)

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

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 Developer Community or GitHub 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 Jonathan Pryor 2012-09-27 10:25:45 UTC
Create a project which references an assembly which isn't part of the project. (TODO: create actual such project.)

If one of the assemblies can't be found, an error is generated. This is good:

> Error	20	Exception while loading assemblies: System.IO.FileNotFoundException: Could not load assembly 'SMDiagnostics, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. Perhaps it doesn't exist in the Mono for Android profile?
> File name: 'SMDiagnostics.dll'
>    at Monodroid.Tuner.MonoDroidResolver.Resolve(AssemblyNameReference reference, ReaderParameters parameters)
>    at Xamarin.Android.Tasks.ResolveAssemblies.AddAssemblyReferences(List`1 assemblies, AssemblyDefinition assembly)
>    at Xamarin.Android.Tasks.ResolveAssemblies.AddAssemblyReferences(List`1 assemblies, AssemblyDefinition assembly)
>    at Xamarin.Android.Tasks.ResolveAssemblies.AddAssemblyReferences(List`1 assemblies, AssemblyDefinition assembly)
>    at Xamarin.Android.Tasks.ResolveAssemblies.AddAssemblyReferences(List`1 assemblies, AssemblyDefinition assembly)
>    at Xamarin.Android.Tasks.ResolveAssemblies.AddAssemblyReferences(List`1 assemblies, AssemblyDefinition assembly)
>    at Xamarin.Android.Tasks.ResolveAssemblies.Execute()	AndroidApplication

It's good, but not Great. Why is this assembly required? What assembly requires it? etc.

What would be great is if we also provided the assembly reference "chain" so we can more easily determine which project reference was pulling in the assembly in the first place.
Comment 1 Atsushi Eno 2012-10-18 12:42:25 UTC
I have added a verbose output in assembly resolution task and now /v:diagnostic output contains output like this:


                                  Adding assembly reference for Hello, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null, recursively...
                                    Adding assembly reference for Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=c4c4237547e4b6cd, recursively...
                                      Adding assembly reference for mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, recursively...
                                      Adding assembly reference for System.Core, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, recursively...

...

                                  Adding assembly reference for System.ServiceModel.Discovery, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, recursively...
/home/atsushi/svn/monodroid/tools/msbuild/build/Xamarin/Android/Xamarin.Android.Common.targets: error : Exception while loading assemblies: System.IO.FileNotFoundException: Could not load assembly 'System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. Perhaps it doesn't exist in the Mono for Android profile?
File name: 'System.Configuration.dll'
  at Monodroid.Tuner.MonoDroidResolver.Resolve (Mono.Cecil.AssemblyNameReference reference, Mono.Cecil.ReaderParameters parameters) [0x00000] in <filename unknown>:0
  at Monodroid.Tuner.MonoDroidResolver.Resolve (Mono.Cecil.AssemblyNameReference reference) [0x00000] in <filename unknown>:0
  at Xamarin.Android.Tasks.ResolveAssemblies.AddAssemblyReferences (System.Collections.Generic.List`1 assemblies, Mono.Cecil.AssemblyDefinition assembly) [0x00000] in <filename unknown>:0
  at Xamarin.Android.Tasks.ResolveAssemblies.Execute () [0x00000] in <filename unknown>:0

[rev. 8fd7f01]
Comment 2 Jonathan Pryor 2012-10-18 13:33:10 UTC
Nice, but it's not quite "easy." The only way to know that System.Configuration is being brought in from System.ServiceModel.Discovery is to read the surrounding context, and (historically speaking) people are not good at reading surrounding context. :-/

Furthermore, the surrounding context messages aren't warnings or errors, and thus won't appear in the IDE. The only way for the developer to see them would be to enable verbose/diagnostic logging, which (historically) is not the norm.

Would it be possible to improve the FileNotFoundException to be along the lines of:

> Could not load assembly ''System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a',
> referenced by SystemServiceModel.Discovery, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35'
> referenced by ...
> referenced by project.
> Perhaps it doesn't exist in the Mono for Android profile?
Comment 3 Atsushi Eno 2012-10-18 13:43:20 UTC
Agreed that it's easier.
Comment 4 Bassam Tantawi 2013-09-01 09:22:16 UTC
So any fixes for this? and why it happens?
Comment 5 Jonathan Pryor 2013-09-02 18:24:00 UTC
@Bassam: Why does it happen? "Broken" projects, as mentioned in the original comment. For example, assume you had an assembly A.dll which was built under .NET 4.0 and has an assembly reference to System.Configuration.dll. Xamarin.Android doesn't provide System.Configuration (namespace or assembly), so this assembly WILL NOT WORK, but attempting to _use_ the assembly MAY work...in Debug builds.

In Release builds, the linker will attempt to find System.Configuration.dll and fail, resulting in the FileNotFoundException.

This is (1) by design, but (2) user-hostile. The purpose of this bug, as per Comment #2, is to make the error _easier_ to diagnose and act upon.

Comment #1 is _a_ fix, but (as mentioned in Comment #2) is not ideal, as it requires the logging and manual reading of diagnostic output, which very few people actually do.

An ideal output would be:

> XA1234: Could not load assembly '<assembly-name>.
> Perhaps it does not exist in the Xamarin.Android profile?
> Referenced by <IntermediateAssembly1.dll>, <IntermediateAssembly2.dll>, and <UserAssembly1.dll>.

The above would be actionable -- you know which sequence of assembly references is leading to <assembly-name>, and thus can (hopefully) fix one of the intermediate assembly references.
Comment 6 Bassam Tantawi 2013-09-03 04:17:13 UTC
The problem is that SMDiagnostics V4 is not in my gac, what I have is V3. and I can't find it anywhere on the internet to download it. most people say it is already found in the .Net 4 package, which I already installed.

The problem presists either in running the application in debug mode or in deploying it to an emulator.
Comment 7 Jonathan Pryor 2013-09-03 10:58:27 UTC
@Bassam: The problem isn't that you only have SMDiagnostics v3 in your GAC.

The problem is that you're using it AT ALL.

The only safe assemblies to use are those that only reference assemblies that come with Xamarin.Android, or assemblies that in turn only reference assemblies that come with Xamarin.Android, etc.:

http://docs.xamarin.com/guides/android/advanced_topics/assemblies

SMDiagnostics.dll is NOT such an assembly; it's a Microsoft assembly built against .NET 4.0 and references assemblies that are not included with Xamarin.Android such as System.Configuration.dll and System.ServiceModel.Internals.dll. It CANNOT work.

In the future PCL assemblies will also be usable with Xamarin.Android. This still won't help you, as SMDiagnostics.dll isn't a PCL assembly, and is unlikely to ever be one (based on the assembly references, anyway).

If your code is reference SMDiagnostics.dll, you must REMOVE all references to that assembly from your source code and RECOMPILE your source code within a Android Library project.