Azure / azure-cosmos-dotnet-v3

.NET SDK for Azure Cosmos DB for the core SQL API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Using Cosmos db in Xamarin.Forms Cross Platform

PKYADAV opened this issue · comments

Hi, I am trying to use cosmos db in Xamarin.Forms project but it is showing below errors:

**Severity Code Description Project File Line Suppression State

Error Can not resolve reference: Microsoft.Azure.Cosmos.Direct, referenced by Microsoft.Azure.Cosmos.Client. Please add a NuGet package or assembly reference for Microsoft.Azure.Cosmos.Direct, or remove the reference to Microsoft.Azure.Cosmos.Client. MobileApp1.Android**

Also, when I am adding this nuget then another error is showing as below:

Severity Code Description Project File Line Suppression State
Error Can not resolve reference: Microsoft.Azure.Cosmos.Serialization.HybridRow, referenced by Microsoft.Azure.Cosmos.Client. Please add a NuGet package or assembly reference for Microsoft.Azure.Cosmos.Serialization.HybridRow, or remove the reference to Microsoft.Azure.Cosmos.Client. MobileApp1.Android

Please help me to out of this.

Could you share a small repro Xamarin project we can use as base to reproduce it in our side?

@PKYADAV please re-open with the repro.

This issue occurs when the Cosmos reference is a transitive reference.

reproduce.zip

@ausfeldt can u please take a look?

@jackbond Thanks for the repro!

@PKYADAV The issue is .NET Standard project is the new project format that supports PackageReferences and the Android project is the old project format, which uses packages.config. This caused package dependencies of the .NET Standard project fomat to not flow to the Android project, which is the old format. The work around is add the following to your Android project file:

<PropertyGroup>
    <RestoreProjectStyle>PackageReference</RestoreProjectStyle>
</PropertyGroup>

Make sure that your you delete your bin and obj or do a "git clean -fdx" before you build.

commented

We should add a sample project for this since other users will likely hit this same issue.

Also any thoughts on anyways to make the work-around discoverable?

@ausfeldt I'm on Jack's team. Tried your suggestion but doesn't appear to have any impact. The project didn't have a packages.config file though before that change all of it's references were in it's csproj file. Here's a new copy of the repro with that change.

reproduce.zip

@jameswhollister Interesting, depending on the order I build the project is succeeds or fails. Instead adding below to "XamarinAndCosmosNoLike" project, also will fix the issue, but consistently.

<PropertyGroup>
    <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>

Apparently this is a known issue that has been open for a while: xamarin/xamarin-macios#3949

@ausfeldt that did it. Thank you!