You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Not sure of the best way to handle this. I think libraries like Serilog implement their own custom JSON serialization.
Current Behaviour
When I log certain exceptions System.NotSupportedException is thrown
Code snippet
[Fact]publicvoidReproduceIssue(){varmyEx=newMyException{Handle=(IntPtr)1};varvalue=JsonSerializer.Serialize(myEx);// System.NotSupportedException: Serialization and deserialization of 'System.IntPtr' instances are not supported. Path: $.Handle.}publicclassMyException:Exception{publicIntPtrHandle{get;set;}}
Possible Solution
Possibly implement a JsonConverter which can serialize exceptions (Message, StackTrace)
Steps to Reproduce
[Fact]publicvoidReproduceIssue(){varmyEx=newMyException{Handle=(IntPtr)1};varvalue=JsonSerializer.Serialize(myEx);// System.NotSupportedException: Serialization and deserialization of 'System.IntPtr' instances are not supported. Path: $.Handle.}publicclassMyException:Exception{publicIntPtrHandle{get;set;}}
AWS Lambda Powertools for .NET version
latest
AWS Lambda function runtime
dotnet6
Debugging logs
No response
The text was updated successfully, but these errors were encountered:
Thank you @jakejscott for opening the issue. As you mentioned, System.Text.Json does not support Type & IntPtr serialization but the Logger.LogError method does not serialize the exception. Instead it adds the error message to the log object. Technically you should not get error in that case. I’ll appreciate if you please provide a bit more context on how you are using the Logger to raise the exception.
it’s also understandable that there might be a need to log more details on the exception than just the message. One of the way would be implementing a custom JSON serialization to handle exceptions per suggested. I’ll discuss internally to find out the best way forward and update the ticket accordingly.
Uh oh!
There was an error while loading. Please reload this page.
Expected Behaviour
Some Exceptions have types on them that are not serializable by System.Text.Json for example 'System.Type' and 'System.IntPtr'
See related issue here:
dotnet/runtime#43026
Not sure of the best way to handle this. I think libraries like Serilog implement their own custom JSON serialization.
Current Behaviour
When I log certain exceptions
System.NotSupportedException
is thrownCode snippet
Possible Solution
Possibly implement a
JsonConverter
which can serialize exceptions (Message, StackTrace)Steps to Reproduce
AWS Lambda Powertools for .NET version
latest
AWS Lambda function runtime
dotnet6
Debugging logs
No response
The text was updated successfully, but these errors were encountered: