New to Blazor, new to Web Assembly, new to .NET Core, not new to .NET (since 1.0).
I'm taking some first steps into learning Blazor - I'm mostly a back-end and winforms dev, not client-side.
For my project, I'm building a Blazor Web Assembly client that accesses some existing functionality that I have deployed through Azure Functions 3. I'd like to share some POCOs between the front-end and back-end app.
I'm running into "impedance mismatches" between the Blazor app and the Azure functions app. Both apps (Blazor and Functions) are basic "out of the box" apps, configured the way the new project templates in VS2019 created them.
- Azure functions app targets "netcoreapp3.1" while the Blazor client side app targets "netstandard2.1"
- Azure Functions uses
Newtonsoft.Json
while Blazor usesSystem.Text.Json
In order to share object definitions, I changed the class library containing my POCOs to netstandard2.1 and that seems to be OK. Was this the correct solution?
The problem I haven't been able to overcome is this: an object that contains an enum
property is returned from the Azure Functions app. Deserialization of this object fails in the Blazor app when an enum value is encountered in the JSON text.
How can I get System.Text.Json
to deserialize enum
properties?
I've seen examples of how to add a JsonConvertorFactory
to ASP.NET Core, but it's not clear how or if those examples apply inside the Blazor app. For example, here.
On the Newtsoft.Json
side, the POCOs are decorated with the Newtonsoft.Json.JsonConvertor
attribute. I tried adding the corresponding System.Text.Json
convertor attribute, but that class wasn't found - is System.Text.Json
not part of netstandard2.1?