When the arguments given in an OData query does not find a result - how will you be handling the returned null value. I get this exception if it happends that there are no retult or I simply return null without ever searching.
Error: Cannot serialize a null 'Resource'
An unhandled exception was thrown by the application. System.Runtime.Serialization.SerializationException: Cannot serialize a null 'Resource'. at Microsoft.AspNet.OData.Formatter.Serialization.ODataResourceSerializer.WriteObjectInline(Object graph, IEdmTypeReference expectedType, ODataWriter writer, ODataSerializerContext writeContext) at Microsoft.AspNet.OData.Formatter.Serialization.ODataResourceSerializer.WriteObject(Object graph, Type type, ODataMessageWriter messageWriter, ODataSerializerContext writeContext) at Microsoft.AspNet.OData.Formatter.ODataOutputFormatterHelper.WriteToStream(Type type, Object value, IEdmModel model, ODataVersion version, Uri baseAddress, MediaTypeHeaderValue contentType, IWebApiUrlHelper internaUrlHelper, IWebApi
I would expect it to return an empty result and a 204 code - but it returns an empty result with a 200 code and throws the exception in the console.
Here is some sample code from the controller:
[EnableQuery]
[ODataRoute("Topic/{id}")]
public TopicDto? GetTopic(string id)
{
return _dbTableContext.Topic.Find(id);
}
