'Amazon.DynamoDBv2.DocumentModel.DynamoDBNull

I am using the C# and this function gives following error when I fetch data about an year

Code :var remainingItems = await search.GetRemainingAsync();

Exception : Unable to convert [Amazon.DynamoDBv2.DocumentModel.DynamoDBNull] of type Amazon.DynamoDBv2.DocumentModel.DynamoDBNull to System.String



Solution 1:[1]

I came across a similar problem using PartiLQ, using the statement:

"UPDATE TABLE SET MyLongAttribute=null where PartitionKey=?";

The update was executed successfully, but the error occurs when I then tried to load the model back from the document record. The SDK complaints that Amazon.DynamoDBv2.DocumentModel.DynamoDBNull cannot be mapped into a <nullable>long.

This is related to a known problem https://github.com/aws/aws-sdk-net/issues/629

To resolve this problem, instead of setting the attribute to null, you should just remove the attribute from the object instead, e.g.

"UPDATE TABLE REMOVE MyLongAttribute where PartitionKey=?";

If you use the PutItem API instead of PartiLQ, and the attribute is a String instead of a long, the concept should still be similar. The GitHub reference above describes that the workaround is simple enough, AWS would not bother fixing this on the DotNet SDK.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 gordon so