Bug 40201 - Xamarin.Mac can't load binding assembly
Summary: Xamarin.Mac can't load binding assembly
Status: RESOLVED ANSWERED
Alias: None
Product: Xamarin.Mac
Classification: Desktop
Component: Other ()
Version: 2.8.0 (C7)
Hardware: Macintosh Mac OS
: --- blocker
Target Milestone: ---
Assignee: Chris Hamons
URL:
Depends on:
Blocks:
 
Reported: 2016-04-07 15:42 UTC by Matthew Leibowitz
Modified: 2016-04-14 15:41 UTC (History)
4 users (show)

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


Attachments
Code for testing (844.17 KB, application/zip)
2016-04-07 15:42 UTC, Matthew Leibowitz
Details
Example showing console app behaving same. (362.05 KB, application/zip)
2016-04-14 15:41 UTC, Chris Hamons
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 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 ANSWERED

Description Matthew Leibowitz 2016-04-07 15:42:46 UTC
Created attachment 15645 [details]
Code for testing

This is a bit of a weird one, but here goes:

Steps to repro success:
 1. create a binding project for Xamarin.Mac
 2. create a sample Mac app
 3. reference the binding from the sample
 4. make sure something is used/referenced from the binding
 5. run the sample
 6. everything should work

Steps to repro failure (part 1):
 1. using the same binding project
 2. create a new sample app
 3. copy the binding project output dll into a new folder
 4. reference the copied assembly from the sample
 5. run the sample
 6. everything seems to work still

Steps to repro total weirdness:
 1. using the same binding project and sample app
 2. rename the binding project output assembly (this seems to cause the errors)
 3. reference the renamed assembly from the sample
 4. run the sample
 5. explodes

Seems to be failing every time. I noticed this when my projects worked, but failed after uploading to NuGet.org.
Comment 1 Matthew Leibowitz 2016-04-07 15:53:00 UTC
Another think to point out is that the exception message is:

    Could not load file or assembly 'BindingProject' or one of its dependencies.

In my example, "BindingProject" is the name of the binding project output, even though I am referencing the same assembly, but renamed to "Eksplosin"
Comment 2 Matthew Leibowitz 2016-04-07 15:57:35 UTC
I can't test this as I only have one mac, but it might be the case as well that if the assembly has not been loaded before, but the name remains the same (someone else creates a test app that references the output dll), the exception can be avoided by:

    var cb = Assembly.GetExecutingAssembly ().CodeBase;
    var filePath = new Uri (cb).LocalPath;
    var dir = Path.GetDirectoryName (filePath);
    var bindingPath = Path.Combine (dir, "../Resources", "OriginalName");
    ObjCRuntime.Dlfcn.dlopen(bindingPath, 0);
Comment 3 Chris Hamons 2016-04-14 15:18:31 UTC
So if you look at the assemblies that the program reference:

monop --refs -r:/Users/donblas/Downloads/TestCase-2/MacFileReference/bin/Debug/MacFileReference.exe 
Xamarin.Mac, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065
BindingProject, Version=1.0.5941.31081, Culture=neutral, PublicKeyToken=null
mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e


It's still looking for a file called BindingProject.

Even after renaming the file, the name is still baked in metadata:

[assembly: AssemblyTitle ("BindingProject")]

even after "linking" against the renamed version:

Added assembly /Users/donblas/Downloads/TestCase-2/ScaryFile.dll
Comment 4 Chris Hamons 2016-04-14 15:30:09 UTC
I just tried this with a console app that depends on a lib that was renamed:

Unhandled Exception:
System.IO.FileNotFoundException: Could not load file or assembly 'TestLib, Version=1.0.5948.18630, Culture=neutral, PublicKeyToken=null' or one of its dependencies.
File name: 'TestLib, Version=1.0.5948.18630, Culture=neutral, PublicKeyToken=null'
[ERROR] FATAL UNHANDLED EXCEPTION: System.IO.FileNotFoundException: Could not load file or assembly 'TestLib, Version=1.0.5948.18630, Culture=neutral, PublicKeyToken=null' or one of its dependencies.
File name: 'TestLib, Version=1.0.5948.18630, Culture=neutral, PublicKeyToken=null'
Comment 5 Chris Hamons 2016-04-14 15:41:11 UTC
Created attachment 15724 [details]
Example showing console app behaving same.