Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Handle TargetInvocationException when reading a property #879

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

alexeykuptsov
Copy link

In my project I use YamlDotNet to serialize arbitrary objects. I can't mark properties of the objects with [YamlIgnore] but I want serializer not to fail in cases when an erroneous property is met. Could you add an ability to serialize such properties as YAML strings literals with a simple error message?

@alexeykuptsov
Copy link
Author

I'm sorry for this mess of closing and reopening. I'm getting used to contributing to OSS 😅

@alexeykuptsov alexeykuptsov force-pushed the target-invocation-exception branch from 8d9297e to 4d3571f Compare December 26, 2023 19:17
@EdwardCooke
Copy link
Collaborator

Can also add this to the static serializer pieces of yamldotnet?

@alexeykuptsov
Copy link
Author

alexeykuptsov commented Jan 23, 2024

I've added test StaticSerializationHandlesTargetInvocationException but I don't understand the static serializer output. The serializer doesn't throw and returns empty object output {}. Can you help me with binding field StaticSerializerBuilder.handleTargetInvocationExceptions with the part of code where it reads from an input object property?

@alexeykuptsov alexeykuptsov force-pushed the target-invocation-exception branch 2 times, most recently from cf8ed3b to efc6b10 Compare April 10, 2024 20:30
@EdwardCooke
Copy link
Collaborator

Just looked this over. One other comment, it may be better to bring the exception handling logic out of the object descriptor, instead pass in a method that would get called in the catch. Takes 3 parameters, exception, object and property. Default of that method would be throw. Then people can handle any different exceptions differently based on their needs. For example, dump out the exception message.

@alexeykuptsov alexeykuptsov force-pushed the target-invocation-exception branch from efc6b10 to a92bdb0 Compare April 13, 2024 06:02
…andler that converts the exception to an error message string
@alexeykuptsov alexeykuptsov force-pushed the target-invocation-exception branch from a92bdb0 to e6826e9 Compare April 13, 2024 06:40
@alexeykuptsov
Copy link
Author

@EdwardCooke Hi Edward, I've implemented the support of custom exception handler function. But I haven't implemented default method "throw". I don't like this idea because try/catch block may affect performance in simple cases like serialization of plain objects with only auto-properties (POCO).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants