-
-
Notifications
You must be signed in to change notification settings - Fork 753
Description
Bug description
If I try to deserialize to a class where the library can not cast the member types correctly, I expect a MessagePackSerializationException but I found that it's possible to get an ExecutionEngineException raised if I write the destination type in a particular manner - where it is instantiated via a constructor whose parameter is type object but the type of the member is a primitive (and the property value on the source data that was serialized was the same type of primitive).
This would obviously be a bug in the code that I had written but it seems like I should be able to catch and log such a mistake with a try..catch, ideally specifically catching a MessagePackSerializationException but this particular type of invalid code tears down the application with an ExecutionEngineException.
Repro steps
There is a complete repro case here: https://dotnetfiddle.net/mVcTab that has the code shown below. Unfortunately, running it returns only "Command terminated by signal 11" and so it might be easier to run it in Visual Studio to see it in full.
using System;
using MessagePack;
public class Program
{
public static void Main()
{
var source = new Source { Key = 1 };
var serialised = MessagePackSerializer.Serialize(source);
try
{
var clone = MessagePackSerializer.Deserialize<Dest>(serialised);
Console.WriteLine(clone.Value);
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
}
[MessagePackObject]
public class Source
{
[Key(0)]
public int Key { get; set; }
}
[MessagePackObject]
public class Dest
{
// Note: The constructor takes an "object" parameter and tries to cast it,
// rather than just taking an "int" parameter
public Dest(object value) => Value = (int)value;
[Key(0)]
public int Value { get; }
}
Expected behavior
I would expect this to throw a MessagePackSerializationException (and, in the code above, to show the exception details in the console when I run it).
Actual behavior
An ExecutionEngineException is thrown and the debugger stop with the message
"The application is break mode"
... and a popup
"An unhandled exception of type 'System.ExecutionEngineException' occurred in Unknown Module."
I'm using MessagePack 2.1.115 on netcoreapp3.1
Additional context
As I said, this is clearly a case where the code that I've written is wrong but the way in which it behaves at runtime feels like the punishment does not fit the crime.