我使用 Xamarin.Forms 创建了一个小型移动应用程序此应用程序使用 Cosmos DB(Azure 数据库)。我需要知道是否可以在 Xamarin.forms 中使用 Microsoft.Azure.Cosmos (Nuget)。如果可能的话,你能帮我弄清楚我做错了什么。
我使用了 Microsoft.Azure.DocumentDB.Core(v2.51) https://www.nuget.org/packages/Microsoft.Azure.DocumentDB.Core/)。这是在 azure-cosmos-dotnet-v2 下。一切正常。
今天,我正在尝试更新到 Microsoft.Azure.Cosmos (v3.10) https://www.nuget.org/packages/Microsoft.Azure.Cosmos/。这是在 azure-cosmos-dotnet-v3 下。但是一旦我点击 CreateItemAsync 行,系统就会失败。
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'
编辑:我添加了一些检查点,看起来连接正常(CosmosClient),但是数据库连接不正确。