Skip to content

CosmosDatabaseWrapper - NullReferenceException in SaveAsync #20976

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
milannankov opened this issue May 17, 2020 · 0 comments · Fixed by #21326 or #21347
Closed

CosmosDatabaseWrapper - NullReferenceException in SaveAsync #20976

milannankov opened this issue May 17, 2020 · 0 comments · Fixed by #21326 or #21347

Comments

@milannankov
Copy link

When deleting items from CosmosDB I get NullReferenceException in CosmosDatabaseWrapper. The exception is thrown when SaveChangesAsync is executed.

I believe that having a get only property that is specified as partition key causes this error. I have provided a sample project which demonstrates that If I add a setter to StoreConnectionId, the problem disappears.

Steps to reproduce

Run the provided project - efcore-cosmosdb-bug2.zip
Run the CosmosDb emulator and create a contianer with the following item:

{
   "id": "881f02f3-2602-4e42-bcce-ea582ab23592",
    "createdAt": "2019-11-24T07:18:05+02:00",
    "isDeleted": false,
    "legacyId": "4392717582410",
    "productDescription": "test2",
    "productName": "test2",
    "storeConnectionId": "7c00d11c-8ce3-4a8a-82f8-c4aaa383ba40",
    "updatedAt": "2020-04-16T05:38:34+03:00",
    "vendor": "vendor"
}

There should be an error when SaveChangesAsync is called.

The exception is the following:

Exception has occurred: CLR/System.NullReferenceException
An exception of type 'System.NullReferenceException' occurred in System.Private.CoreLib.dll but was not handled in user code: 'Object reference not set to an instance of an object.'
   at Microsoft.EntityFrameworkCore.Metadata.Internal.MetadataExtensions.AsConcreteMetadataType[TInterface,TConcrete](TInterface interface, String methodName)
   at Microsoft.EntityFrameworkCore.Metadata.Internal.PropertyBaseExtensions.AsPropertyBase(IPropertyBase propertyBase, String methodName)
   at Microsoft.EntityFrameworkCore.Metadata.Internal.PropertyBaseExtensions.GetPropertyAccessors(IPropertyBase propertyBase)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry.GetCurrentValue[TProperty](IPropertyBase propertyBase)
   at Microsoft.EntityFrameworkCore.Cosmos.Update.Internal.DocumentSource.GetId(IUpdateEntry entry)
   at Microsoft.EntityFrameworkCore.Cosmos.Storage.Internal.CosmosDatabaseWrapper.SaveAsync(IUpdateEntry entry, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Cosmos.Storage.Internal.CosmosDatabaseWrapper.<SaveChangesAsync>d__5.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.<SaveChangesAsync>d__97.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.<SaveChangesAsync>d__101.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at Microsoft.EntityFrameworkCore.Storage.ExecutionStrategy.<ExecuteImplementationAsync>d__31`2.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.EntityFrameworkCore.Storage.ExecutionStrategy.<ExecuteImplementationAsync>d__31`2.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Microsoft.EntityFrameworkCore.DbContext.<SaveChangesAsync>d__54.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at efcore_cosmosdb_bug.Program.<Main>d__0.MoveNext() in C:\Users\milan\dev\test\efcore-cosmosdb-bug2\Program.cs:line 25

This issues might be related to another one that I have reported and has already been fixed - #20916

Further technical details

EF Core version: 3.1.3
Database provider: 3.1.3
Target framework: .NET Core 3.1
Operating system: Windows 10
IDE: Visual Studio Code

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
3 participants