Bug 60798 - MTOUCH : error MT2101: Can't resolve the reference
Summary: MTOUCH : error MT2101: Can't resolve the reference
Status: CONFIRMED
Alias: None
Product: iOS
Classification: Xamarin
Component: MSBuild ()
Version: XI 11.2 (d15-4)
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Future Cycle (TBD)
Assignee: Ankit Jain
URL:
Depends on:
Blocks:
 
Reported: 2017-11-22 10:15 UTC by jack
Modified: 2018-01-24 18:49 UTC (History)
5 users (show)

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


Attachments
Zip containing the content of the reference nuget packages that contains IO.Ably.NetStandard20.dll (2.77 MB, application/zip)
2017-11-22 10:15 UTC, jack
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 for Bug 60798 on Developer Community or GitHub if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: Developer Community HTML or GitHub Markdown
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:
Status:
CONFIRMED

Description jack 2017-11-22 10:15:13 UTC
Created attachment 25788 [details]
Zip containing the content of the reference nuget packages that contains IO.Ably.NetStandard20.dll

I am trying to use Xamarin.Forms with .Net Standard 2 and a third party library compiled for .NET Standard

With the linker Behaviour set to 'Don't Link' I get a runtime exception when executed tested in the iOS simulator

Could not load type of field 'XamarinFormsNetStandard.Services.AblyMessenger:_client' (2) due to: Could not load file or assembly 'IO.Ably.NETStandard20, Version=0.8.0.0, Culture=neutral, PublicKeyToken=70c9e5c3d2c68b16' or one of its dependencies. assembly:IO.Ably.NETStandard20, Version=0.8.0.0, Culture=neutral, PublicKeyToken=70c9e5c3d2c68b16 type:<unknown type> member:<none>

With the linker Behaviour set to 'Link All' I receive the following error:

MTOUCH : error MT2101: Can't resolve the reference 'IO.Ably.Realtime.IRealtimeChannel', referenced from the method 'System.Void XamarinFormsNetStandard.Services.AblyMessenger::SendMessage(System.String)' in 'IO.Ably.NETStandard20, Version=0.8.0.0, Culture=neutral, PublicKeyToken=70c9e5c3d2c68b16'.

On the advice of this page https://developer.xamarin.com/guides/ios/troubleshooting/mtouch-errors/#MT2101 I am submitting this bug

A full build log can be found here:
https://gist.github.com/withakay/9eadd41d82b2c03fbef7c06875934fe8

And the Sample solution here:
https://github.com/withakay/XamarinFormsNetStandardBug

A zip containing the content of the nuget package that contains the IO.Ably.NETStandard20.dll assembly is attached.
Comment 1 Alex Soto [MSFT] 2017-11-22 18:19:32 UTC
Hello Jack

Thanks for contacting us, it seems that there is an assembly mismatch, to give you a little more of context let me give an example:

Assembly "A" Depends on a type inside Assembly "B", assembly "B" gets updated (like using NuGet update) and in this new version of "B" the type got removed (Breaking change), our linker tries to resolve this removed type, it can't and you get a MT2101 error.

But in order to confirm this we would need a test case from you so we can reproduce the error and make sure this is the case.
Comment 2 Brendan Zagaeski (Xamarin Team, assistant) 2017-11-22 19:31:20 UTC
> we would need a test case
It looks like the original reporter included a link to a test case in Comment 0:
> https://github.com/withakay/XamarinFormsNetStandardBug
@Alex, was that test case by itself not sufficient to replicate the issue?  Do you suspect that an additional list of steps to follow to replicate this issue will be required to help replicate the issue?

Thanks!
Comment 3 Alex Soto [MSFT] 2017-11-22 20:30:04 UTC
Oh gosh :facepalms: completely sorry, missed that small but important detail, thanks for having my back Brendan.

Checking it ASAP, I should not review bugs under flu meds heh
Comment 4 Alex Soto [MSFT] 2017-11-22 21:12:01 UTC
I am able to confirm the issue, Also I was able to spot using our assembly browser that IO.Ably.Realtime.IRealtimeChannel is both available on the NetStandard 2.0 dll and also in the platform specific dll inside the NuGet package.

In order to reproduce the issue I had to manually add the attached folder in comment #0  as a local nugget source in VS4Mac settings.

@Sebastien could you give me a hand with this issue? Looks like the type exists in both the NetStandard dll and the platform specific dll yet Cecil can't resolve it.

Thanks!
Comment 5 jack 2017-11-22 21:14:22 UTC
Hi,
thanks for taking a look so quickly guys, much appreciated!

Jack
Comment 6 Sebastien Pouliot 2017-11-24 22:26:05 UTC
 Dependency "IO.Ably.NETStandard20, Version=0.8.0.0, Culture=neutral, PublicKeyToken=70c9e5c3d2c68b16".
        Could not resolve this reference. Could not locate the assembly "IO.Ably.NETStandard20, Version=0.8.0.0, Culture=neutral, PublicKeyToken=70c9e5c3d2c68b16". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.
            For SearchPath "/Users/poupou/git/bugs/XamarinFormsNetStandardBug/XamarinFormsNetStandardLib/bin/Debug/netstandard2.0".
            Considered "/Users/poupou/git/bugs/XamarinFormsNetStandardBug/XamarinFormsNetStandardLib/bin/Debug/netstandard2.0/IO.Ably.NETStandard20.winmd", but it didn't exist.
            Considered "/Users/poupou/git/bugs/XamarinFormsNetStandardBug/XamarinFormsNetStandardLib/bin/Debug/netstandard2.0/IO.Ably.NETStandard20.dll", but it didn't exist.
            Considered "/Users/poupou/git/bugs/XamarinFormsNetStandardBug/XamarinFormsNetStandardLib/bin/Debug/netstandard2.0/IO.Ably.NETStandard20.exe", but it didn't exist.
            For SearchPath "{TargetFrameworkDirectory}".
            Considered "/Library/Frameworks/Mono.framework/External/xbuild-frameworks/Xamarin.iOS/v1.0/IO.Ably.NETStandard20.winmd", but it didn't exist.
            Considered "/Library/Frameworks/Mono.framework/External/xbuild-frameworks/Xamarin.iOS/v1.0/IO.Ably.NETStandard20.dll", but it didn't exist.
            Considered "/Library/Frameworks/Mono.framework/External/xbuild-frameworks/Xamarin.iOS/v1.0/IO.Ably.NETStandard20.exe", but it didn't exist.
            Considered "/Users/poupou/git/xamarin/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS/IO.Ably.NETStandard20.winmd", but it didn't exist.
            Considered "/Users/poupou/git/xamarin/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS/IO.Ably.NETStandard20.dll", but it didn't exist.
            Considered "/Users/poupou/git/xamarin/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS/IO.Ably.NETStandard20.exe", but it didn't exist.
            Considered "/Users/poupou/git/xamarin/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS/Facades/IO.Ably.NETStandard20.winmd", but it didn't exist.
            Considered "/Users/poupou/git/xamarin/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS/Facades/IO.Ably.NETStandard20.dll", but it didn't exist.
            Considered "/Users/poupou/git/xamarin/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS/Facades/IO.Ably.NETStandard20.exe", but it didn't exist.
            Considered "/Users/poupou/git/xamarin/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS/Facades/IO.Ably.NETStandard20.winmd", but it didn't exist.
            Considered "/Users/poupou/git/xamarin/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS/Facades/IO.Ably.NETStandard20.dll", but it didn't exist.
            Considered "/Users/poupou/git/xamarin/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS/Facades/IO.Ably.NETStandard20.exe", but it didn't exist.
            For SearchPath "{GAC}".
            Considered "IO.Ably.NETStandard20, Version=0.8.0.0, Culture=neutral, PublicKeyToken=70c9e5c3d2c68b16", which was not found in the GAC.
            For SearchPath "bin/iPhoneSimulator/Debug/".
            Considered "bin/iPhoneSimulator/Debug/IO.Ably.NETStandard20.winmd", but it didn't exist.
            Considered "bin/iPhoneSimulator/Debug/IO.Ably.NETStandard20.dll", but it didn't exist.
            Considered "bin/iPhoneSimulator/Debug/IO.Ably.NETStandard20.exe", but it didn't exist.
        Required by "/Users/poupou/git/bugs/XamarinFormsNetStandardBug/XamarinFormsNetStandardLib/bin/Debug/netstandard2.0/XamarinFormsNetStandard.dll".


^^^ the actual (real) error happens a lot earlier (than `mtouch`)

       Could not resolve this reference. Could not locate the assembly "IO.Ably.NETStandard20, Version=0.8.0.0, Culture=neutral, PublicKeyToken=70c9e5c3d2c68b16". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.


It seems the search path does not include the nuget paths so either msbuild (nor mtouch later) knows where to find the assembly.
Comment 7 jack 2017-11-28 12:43:08 UTC
Thanks for your efforts Sebastien!

So, if this is not a bug with mtouch, then what is it a bug with? 
Visual Studio for Mac perhaps?

I am just wondering how to proceed.
Comment 8 Jeffrey Stedfast 2018-01-24 18:49:48 UTC
The NetStandard20 library project has <PackageReference> items but that does not point to a physical location like normal references do.

I assume that the core MSBuild targets are supposed to resolve/expand those into <Reference> items, but I guess they aren't working?

That suggests that this is MSBuild bug and not specific to the iOS build tasks.