1

I created a small mobile app using Xamarin.Forms This app use Cosmos DB (Azure Database). I need to know if it is possible to use Microsoft.Azure.Cosmos (Nuget) in Xamarin.forms. If it is possible, can you help me to figure out what I am doing wrong.

I used the Microsoft.Azure.DocumentDB.Core(v2.51) https://www.nuget.org/packages/Microsoft.Azure.DocumentDB.Core/). This is under azure-cosmos-dotnet-v2. Everything works OK.

Today, I am trying to update to Microsoft.Azure.Cosmos (v3.10) https://www.nuget.org/packages/Microsoft.Azure.Cosmos/. This is under azure-cosmos-dotnet-v3. But as soon i hit the line CreateItemAsync, the system fail.

CosmosClient client = new CosmosClient(CosmosEndpointUrl, CosmosAuthKey);
AccountProperties ap= await client.ReadAccountAsync(); // Check connection... It is OK
Database db = client.GetDatabase("MyDatabase");//My Database name is OK,
DatabaseResponse dbresponse= await db.ReadAsync();///Fail 
Container container = client.GetContainer("MyDatabase", "MyCollection");
dynamic testItem = new { id = "1234", userId = "2222", details = "it's working" };
ItemResponse<dynamic> response = await container.CreateItemAsync<dynamic>(testItem); /// Fail...



[0:] DocDBTrace Error: 0 : 
[0:] Operation will NOT be retried. Current attempt 0, Exception: System.NotSupportedException: Linked Away
  at System.Runtime.Remoting.Messaging.CallContext.LogicalGetData (System.String ) [0x00005] in <4b124141b7914f4d8253001e6b8a15cf>:0 
  at System.Diagnostics.CorrelationManager.get_ActivityId () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.14.0.110/src/Xamarin.iOS/mcs/class/referencesource/System/compmod/system/diagnostics/CorrelationManager.cs:23 
  at Microsoft.Azure.Cosmos.ActivityScope..ctor (System.Guid activityId) [0x0000c] in <36733228c2e04bedaa8ccf505865c0ea>:0 
  at Microsoft.Azure.Cosmos.Routing.ClientCollectionCache.ReadCollectionAsync (System.String collectionLink, System.Threading.CancellationToken cancellationToken, Microsoft.Azure.Cosmos.IDocumentClientRetryPolicy retryPolicyInstance) [0x000b8] in <36733228c2e04bedaa8ccf505865c0ea>:0 
  at Microsoft.Azure.Documents.BackoffRetryUtility`1[T].ExecuteRetryAsync (System.Func`1[TResult] callbackMethod, System.Func`3[T1,T2,TResult] callShouldRetry, System.Func`1[TResult] inBackoffAlternateCallbackMethod, System.TimeSpan minBackoffForInBackoffCallback, System.Threading.CancellationToken cancellationToken, System.Action`1[T] preRetryCallback) [0x0008c] in <5ffe0b54a2fb4f58adef177e11a3d996>:0  
**System.NotSupportedException:** 'Linked Away'

EDIT: I add some checkpoint, and looks like the connection is OK (CosmosClient), however the database is not connected properly.

logeshpalani31
  • 1,416
  • 12
  • 33
  • https://spouliot.wordpress.com/2011/11/01/linker-vs-linked-away-exceptions/ – magicandre1981 Aug 03 '19 at 07:59
  • Thanks @magicandre1981 ... I am getting close to solve the problem... in Xamarin.Forms iOS Property I change "Link Behavior" from "Link Framework SDKs Only" to Don't Link... I get the problem solve (in iOS)... do you know what are the implication of this change? – BlueOceans1st Aug 03 '19 at 16:18
  • The major implication you get by this, is the increasing size of your package. Depending on your application and the libs used, this may be a difference in less than a MB, but can increase to dozens of MBs as well. Just check for your application and compare the packages of the builds – auX Aug 03 '19 at 20:21
  • [linking removes unneeded code from apk](https://xamarinhelp.com/xamarin-linker/), but if too many things get removed you get exceptions. – magicandre1981 Aug 04 '19 at 16:16
  • Hey @BlueOceans1st, did you figure out how to fix this issue without changing the linker behavior? – Valeriy Kovalenko Nov 14 '19 at 14:33
  • No, I did not figure out. So, I came back to v2, I will back to v3 once Xamarin.Forms approve this new version. I am using Microsoft.Azure.DocumenBD.Core v2.91. If you have update about v3 and Xamarin.Forms, please let me know. Thanks – BlueOceans1st Nov 15 '19 at 15:07

0 Answers0