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

Deserialization failures in Blazor WASM #14707

Closed
MarkStega opened this issue Oct 3, 2019 · 3 comments
Closed

Deserialization failures in Blazor WASM #14707

MarkStega opened this issue Oct 3, 2019 · 3 comments
Assignees
Labels
area-blazor Includes: Blazor, Razor Components feature-blazor-wasm This issue is related to and / or impacts Blazor WebAssembly investigate

Comments

@MarkStega
Copy link

If you believe you have an issue that affects the security of the platform please do NOT create an issue and instead email your issue details to secure@microsoft.com. Your report may be eligible for our bug bounty but ONLY if it is reported through email.

Describe the bug

Using System.Text.Json to deserialize an object works on SSB and fails on CSB with identical JSON input data.

To Reproduce

Steps to reproduce the behavior:

  1. Using this version of ASP.NET Core 3.0.0
  2. Create a Blazor application using the server template
  3. Replace Index.razor with the attached file (within attached zip)
  4. Add the file Index.razor.cs (also in attached zip)
  5. Using NuGet, add Newtonsoft.Json to the project
  6. Run & observer proper deserialization by both Newsoft & System.Text.Json (As indicated by an OK status on the Index page)
  7. Now create a Blazor application using the WASM template with an Asp.NetCore host
  8. Add the same two files in the pages directory
  9. Edit the namespace in the .razor.cs to match your chosen name/directory
  10. Run the application

Failure #1: WASM: System.MissingMethodException: Default constructor not found for type Deserialize_CSB.Client.Pages.ServiceResult`1[[Deserialize_CSB.Client.Pages.Process_DD[], Deserialize-CSB.Client, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]

  1. Change the constructor for ServiceResult to public
  2. Rerun the application

Failure #2: WASM: System.Text.Json.JsonException: The JSON value could not be converted to Deserialize_CSB.Client.Pages.ServiceResult`1+eStatus[Deserialize_CSB.Client.Pages.Process_DD[]]. Path: $.pStatus | LineNumber: 0 | BytePositionInLine: 12.

Index.zip

Expected behavior

I expect CSB and SSB to both deserialize correctly.

Screenshots

n/a

Additional context

C:\Users\ms>dotnet --info
.NET Core SDK (reflecting any global.json):
Version: 3.0.100
Commit: 04339c3a26

Runtime Environment:
OS Name: Windows
OS Version: 10.0.18362
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\3.0.100\

Host (useful for support):
Version: 3.0.0
Commit: 7d57652f33

.NET Core SDKs installed:
2.1.802 [C:\Program Files\dotnet\sdk]
2.2.402 [C:\Program Files\dotnet\sdk]
3.0.100 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.2.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

To install additional .NET Core runtimes or SDKs:
https://aka.ms/dotnet-download

@mkArtakMSFT mkArtakMSFT added area-blazor Includes: Blazor, Razor Components feature-blazor-wasm This issue is related to and / or impacts Blazor WebAssembly labels Oct 3, 2019
@conficient
Copy link
Contributor

 private ServiceResult() { }

and

private Process_DD() { }

If you make the default constructor private the deserializer can't access it to create a new instance of your object to be able to set the properties. Have you tried making it public?

@MarkStega
Copy link
Author

Sorry my "Step 11" should have said make both constructors public. It still fails. And it doesn't explain why they need to be public when the same code runs SSB and succeeds.

@mkArtakMSFT
Copy link
Member

This issue was moved to mono/mono#17735

@dotnet dotnet locked and limited conversation to collaborators Nov 6, 2019
@mkArtakMSFT mkArtakMSFT removed this from the blazor-wasm milestone Nov 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-blazor Includes: Blazor, Razor Components feature-blazor-wasm This issue is related to and / or impacts Blazor WebAssembly investigate
Projects
None yet
Development

No branches or pull requests

4 participants