Nullierbares Objekt muss einen Wert haben, während die Antwort vom Endpunkt zurückgegeben wirdC#

Ein Treffpunkt für C#-Programmierer
Guest
 Nullierbares Objekt muss einen Wert haben, während die Antwort vom Endpunkt zurückgegeben wird

Post by Guest »

Ich habe ein benutzerdefiniertes Framework in meiner Organisation. Und ich verwende eine Methode dieses Frameworks, um die Antwort aus der API zurückzugeben. Es ist ziemlich unkomplizierte Methode: < /p>

Code: Select all

[HttpGet]
[Route("order/{orderId:long}")]
public async Task GetOrderAsync(int orderId)
{
try
{
return await ProcessRequestAsync(
requestParameter,
requestMethod,
response => Ok(response) 
 Meine Ergebnisse: < /strong> < /p>

 Die Antwort ist nicht null, es hat korrekte Werte. < /li>
 Die Antwort hat ein komplexes Objekt. Unten ist, wie die Antwort aussieht: < /li>
< /ol>
Response
- Object1 (Which doesn't have any exception in properties)
- Object2 (Which doesn't have any exception in properties)
- Object3 (Which has exception in few properties)
< /code>
Ich versuche, ein vorhandenes Projekt von .NET48 bis .NET8 zu migrieren, aber ich stecke am obigen Code fest.  < /p>
I just want the response should be returned irrespective if some properties are throwing exception of InvalidOperation because it was working in .NET48 framework.

Für Ihre Referenz ist die Ausnahme, die ich in den Eigenschaften bekomme,:

Code: Select all

threw an exception of type 'System.InvalidOperationException'

und ich bekomme die folgende Antwort in meiner Prahlerei:

Code: Select all

{
"Message": "Nullable object must have a value.",
"StackTrace": "   at OpenBuysValueGetter(Object)\r\n   at System.Text.Json.Serialization.Metadata.JsonPropertyInfo`1.GetMemberAndWriteJson(Object obj, WriteStack& state, Utf8JsonWriter writer)\r\n   at System.Text.Json.Serialization.Converters.ObjectDefaultConverter`1.OnTryWrite(Utf8JsonWriter writer, T value, JsonSerializerOptions options, WriteStack& state)\r\n   at System.Text.Json.Serialization.JsonConverter`1.TryWrite(Utf8JsonWriter writer, T& value, JsonSerializerOptions options, WriteStack& state)\r\n   at System.Text.Json.Serialization.Metadata.JsonPropertyInfo`1.GetMemberAndWriteJson(Object obj, WriteStack& state, Utf8JsonWriter writer)\r\n   at System.Text.Json.Serialization.Converters.ObjectDefaultConverter`1.OnTryWrite(Utf8JsonWriter writer, T value, JsonSerializerOptions options, WriteStack& state)\r\n   at System.Text.Json.Serialization.JsonConverter`1.TryWrite(Utf8JsonWriter writer, T& value, JsonSerializerOptions options, WriteStack& state)\r\n   at System.Text.Json.Serialization.Metadata.JsonPropertyInfo`1.GetMemberAndWriteJson(Object obj, WriteStack& state, Utf8JsonWriter writer)\r\n   at System.Text.Json.Serialization.Converters.ObjectDefaultConverter`1.OnTryWrite(Utf8JsonWriter writer, T value, JsonSerializerOptions options, WriteStack& state)\r\n   at System.Text.Json.Serialization.JsonConverter`1.TryWrite(Utf8JsonWriter writer, T& value, JsonSerializerOptions options, WriteStack& state)\r\n   at System.Text.Json.Serialization.Metadata.JsonPropertyInfo`1.GetMemberAndWriteJson(Object obj, WriteStack& state, Utf8JsonWriter writer)\r\n   at System.Text.Json.Serialization.Converters.ObjectDefaultConverter`1.OnTryWrite(Utf8JsonWriter writer, T value, JsonSerializerOptions options, WriteStack& state)\r\n   at System.Text.Json.Serialization.JsonConverter`1.TryWrite(Utf8JsonWriter writer, T& value, JsonSerializerOptions options, WriteStack& state)\r\n   at System.Text.Json.Serialization.Metadata.JsonPropertyInfo`1.GetMemberAndWriteJson(Object obj, WriteStack& state, Utf8JsonWriter writer)\r\n   at System.Text.Json.Serialization.Converters.ObjectDefaultConverter`1.OnTryWrite(Utf8JsonWriter writer, T value, JsonSerializerOptions options, WriteStack& state)\r\n   at System.Text.Json.Serialization.JsonConverter`1.TryWrite(Utf8JsonWriter writer, T& value, JsonSerializerOptions options, WriteStack& state)\r\n   at System.Text.Json.Serialization.JsonConverter`1.WriteCore(Utf8JsonWriter writer, T& value, JsonSerializerOptions options, WriteStack& state)\r\n   at System.Text.Json.Serialization.Metadata.JsonTypeInfo`1.SerializeAsync(Stream utf8Json, T rootValue, CancellationToken cancellationToken, Object rootValueBoxed)\r\n   at System.Text.Json.Serialization.Metadata.JsonTypeInfo`1.SerializeAsync(Stream utf8Json, T rootValue, CancellationToken cancellationToken, Object rootValueBoxed)\r\n   at System.Text.Json.Serialization.Metadata.JsonTypeInfo`1.SerializeAsync(Stream utf8Json, T rootValue, CancellationToken cancellationToken, Object rootValueBoxed)\r\n   at Microsoft.AspNetCore.Mvc.Formatters.SystemTextJsonOutputFormatter.WriteResponseBodyAsync(OutputFormatterWriteContext context"
}

Is there any way you can help me?

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post