Azure-cosmos-dotnet-v2: Error while loading assemblies: .../DocumentDB.Spatial.Sql.dll during VS 15.5.0 build of Xamarin.Forms iOS project using <PackageReference>s

Created on 11 Dec 2017  路  14Comments  路  Source: Azure/azure-cosmos-dotnet-v2

Trying to build an iOS-targeting Xamarin.Forms project (as created by the cross-platform template wizard) that references (directly or indirectly) the Microsoft.Azure.DocumentDB.Core package (tested with 1.6.0 and 1.7.1) using the new PackageReference package management format in Visual Studio 15.5.0 fails with (for example) ..._\Xamarin.iOS.Common.targets(777,3): error : Error while loading assemblies: _..._/bin/iPhone/Debug/DocumentDB.Spatial.Sql.dll_ (this message comes from Xamarin's CompileToNative step, which is run on a Mac via Xamarin Agent).

Reproduction:

  • Start Visual Studio 15.5.0.
  • Ensure that using PackageReference is enabled: _Tools_ -> _Options_; _NuGet Package Manager_; set _Default package management format_ to _PackageReference_.
  • Create a new .NET Standard - based Xamarin.Forms project with name, say, _tst_: _File_ -> _New_ -> _Project_; _Installed_ -> _Visual C#_ -> _Cross-Platform_; select _Cross-Platform App (Xamarin.Forms)_; set _Code Sharing Strategy)_ to _.NET Standard_.

    • The iOS project, named _tst.iOS_, should build (if you are connected to a Xamarin Agent - enabled Mac; if not, the last few build steps are skipped).

  • Make the core project, named _tst_, include Microsoft.Azure.DocumentDB.Core: from _tst_'s context menu, _Manage NuGet Packages_; _Browse_; search for Microsoft.Azure.DocumentDB.Core; _Install_ etc.
  • Rebuild the _tst.iOS_ project (while connected to a Xamarin Agent - enabled Mac).

    • If you don't have Xamarin Agent set up, the failing step will be skipped, but _tst.iOS\bin\iPhone\Debug_ will still contain both _DocumentDB.Spatial.Sql.dll_ and _Microsoft.Azure.Documents.ServiceInterop.dll_, which seems a bit odd.

  • (Extra) Make the _tst.iOS_ project itself explicitly include Microsoft.Azure.DocumentDB.Core and rebuild that project. The error still occurs.

Most helpful comment

I believe this is a Mono MSBuild bug:

https://bugzilla.xamarin.com/show_bug.cgi?id=57229

Currently Mono's MSBuild is adding win runtimes to the project.assets.json file when it runs a restore.

You should be able to workaround this by changing the runtime identifiers in the iOS project. Adding the following to iOS project, running a restore again, then building, and all is good again.

<RuntimeIdentifiers>mac;mac-x86;mac-x64</RuntimeIdentifiers>
<NuGetRuntimeIdentifier>mac</NuGetRuntimeIdentifier>

Note that you have to put some runtimes in here, since if they are not defined then 'win' will be used by default. Since the NuGet package has no associated runtimes for mac this prevents the 'win' dlls from being used.

All 14 comments

399-repoproj.zip contains a VS solution created using the reproduction steps (including the extra bit), plus msbuild's diagnostic output.

@gcrossland-cosworth apologies for the delay.

@rnagpal can you please take a look at this?

I'm getting the same error with a Xamarin forms application. But I just tried of adding the dll as a manual reference than nuget and it worked. I think the issue may be the long path to the dll as it's runtime path is very long

I can also confirm this does seem to be an issue, will try the work around, but was getting the issue on VS for Mac too

Android is compiling okay, but on iOS:

MTOUCH : error MT0009: Error while loading assemblies: /Users/jamesmontemagno/.nuget/packages/microsoft.azure.documentdb.core/1.8.1/runtimes/win/native/DocumentDB.Spatial.Sql.dll

I can confirm that it does exist though

I should mention that I am consuming a .NET Standard 2.0 library that also has the nuget installed.

I remove the NuGet from the iOS project and it still had issues. I had to remove it from the .NET Standard project as well. Then it would build again.

Looks like if we use; https://www.nuget.org/packages/Microsoft.Azure.DocumentDB/ then there aren't any issues

I believe this is a Mono MSBuild bug:

https://bugzilla.xamarin.com/show_bug.cgi?id=57229

Currently Mono's MSBuild is adding win runtimes to the project.assets.json file when it runs a restore.

You should be able to workaround this by changing the runtime identifiers in the iOS project. Adding the following to iOS project, running a restore again, then building, and all is good again.

<RuntimeIdentifiers>mac;mac-x86;mac-x64</RuntimeIdentifiers>
<NuGetRuntimeIdentifier>mac</NuGetRuntimeIdentifier>

Note that you have to put some runtimes in here, since if they are not defined then 'win' will be used by default. Since the NuGet package has no associated runtimes for mac this prevents the 'win' dlls from being used.

@ausfeldt - 1.21.0 of that package worked ... but looks like it has been rolled back (see #443). And 1.21.1 does _not_ work.

Good news is that 1.9.1 of https://www.nuget.org/packages/Microsoft.Azure.DocumentDB.Core/ seems to work.

Bouncing back and forth between the NuGets isn't ideal.

@codemillmatt The package introduced bugs and was unlisted. We will bring back the single NuGet soon when the reported gaps are addressed.

Same problem here (Xamarin.Forms iOS project referencing NetStandard 2.0 class library).
Updated Microsoft.Azure.DocumentDB.Core to latest 1.10.0 version, but problem persists:

C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Xamarin\iOS\Xamarin.iOS.Common.targets(786,3): error : Error while loading assemblies: /Users//Library/Caches/Xamarin/mtbs/builds/MyApp.iOS//bin/iPhoneSimulator/Debug/DocumentDB.Spatial.Sql.dll

Same issue, Xamarin.Forms with NetStandard 2.0. If i remove DocumentDB.Core it builds fine.

I've tried multiple versions of DocumentDB.Core and none seem to work for me.

Error while loading assemblies: /Users//Library/Caches/Xamarin/mtbs/builds/App.iOS//bin/iPhoneSimulator/Debug/DocumentDB.Spatial.Sql.dll

i use Visual Studio for Mac. i fixed this bug like this.

  1. close Visual Studio.
  2. open "youtprojectname".iOS.csproj by common editor
  3. Add the Tag at first PropertyGroup.
    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> <RuntimeIdentifiers>mac;mac-x86;mac-x64</RuntimeIdentifiers> <NuGetRuntimeIdentifier>mac</NuGetRuntimeIdentifier>
  4. Re Open project by Visual Studio IDE
Was this page helpful?
0 / 5 - 0 ratings