Azure / azure-cosmos-dotnet-v2

Contains samples and utilities relating to the Azure Cosmos DB .NET SDK
MIT License
577 stars 836 forks source link

Error while loading assemblies: .../DocumentDB.Spatial.Sql.dll during VS 15.5.0 build of Xamarin.Forms iOS project using <PackageReference>s #399

Open gcrossland-cosworth opened 6 years ago

gcrossland-cosworth commented 6 years ago

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:

gcrossland-cosworth commented 6 years ago

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

kirankumarkolli commented 6 years ago

@gcrossland-cosworth apologies for the delay.

@rnagpal can you please take a look at this?

consoleit commented 6 years ago

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

jamesmontemagno commented 6 years ago

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

jamesmontemagno commented 6 years ago

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

jamesmontemagno commented 6 years ago

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.

jamesmontemagno commented 6 years ago

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

mrward commented 6 years ago

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 commented 6 years ago

Try 1.21.0 https://www.nuget.org/packages/Microsoft.Azure.DocumentDB/

codemillmatt commented 6 years ago

@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.

ausfeldt commented 6 years ago

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

abrasat commented 6 years ago

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

kfuller002 commented 6 years ago

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

wayne-kim commented 6 years ago

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. ` true mac;mac-x86;mac-x64 mac

    `

  4. Re Open project by Visual Studio IDE