Serialzation Exception when passing parameter from MVC Controller Action
See original GitHub issueIm getting an exception on expressionSerializer.SerializeText()
when trying to serialize an Expression
, seemingly when it contains a reference from an MVC action controller. When assign a new local variable in its place with the same value, the serialization succeeds.
Exception Detail
Error converting type: Type 'WhiteBox.WebApp.Helpers.ConnectorInstanceHelper+<>c__DisplayClass4_0' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute. Alternatively, you can ensure that the type is public and has a parameterless constructor - all public members of the type will then be serialized, and no attributes will be required.
If I inspect the Expression
while debugging, i can see the following difference between the local variable
.Constant<Whitebox.WebApp.Helpers.ConnectorInstanceHelper+<>c__DisplayClass4_0>(Whitebox.WebApp.Helpers.ConnectorInstanceHelper+<>c__DisplayClass4_0).productId
and the one being passed from the controller action. The difference being the CS$<>8__locals1 suffix.
.Constant<Whitebox.WebApp.Helpers.ConnectorInstanceHelper+<>c__DisplayClass4_1>(Whitebox.WebApp.Helpers.ConnectorInstanceHelper+<>c__DisplayClass4_1).CS$<>8__locals1).productId
-Visual Studio 2017 -Net CORE 2.2 -Microsoft.AspNetCore.MVC 2.2.0
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (4 by maintainers)
Top GitHub Comments
Hi Sascha,
For me the exception is caught and writes “Exception Thrown”. Does the code not enter the Catch()?
On Thu, 25 Apr 2019 at 14:30, Sascha Kiefer notifications@github.com wrote:
Hi @esskar, sorry for delayed response. I tried to create a test case where i can consistently reproduce the issue. It still seems to be related to the naming I see in the debug view of the expression, but ive narrowed it down it bit further.
If you initiate the code with
await new TestClass().TestMethod("1231231");
the code within try-catch will throw an exception. The code after that executes without exception. If you move the `var userId = “12313”;’ outside the try-catch and similarily, if you remove the try-catch altogether (demonstrated by the subsequent code) the code executes fine. Its cases when the CS$<>8__locals1 is present in the expression that the serialization seems to fail.I also noted that removing the the
productId
parameter fromTestMethod
results in no errors.