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

Error running on Azure #1

Closed
gavnlh opened this issue Dec 13, 2023 · 6 comments
Closed

Error running on Azure #1

gavnlh opened this issue Dec 13, 2023 · 6 comments

Comments

@gavnlh
Copy link

gavnlh commented Dec 13, 2023

This code works fine running locally in Visual Studio 2022, but fails to retrieve the list of users when deployed to Azure (.NET 8 Early Access). The error is not browser specific, but seems to be the hosting at issue. Exception is on the users.razor page:

Exception: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
      Unhandled exception rendering component: ConstructorContainsNullParameterNames, System.Collections.Generic.KeyValuePair`2[System.String,System.String]
System.NotSupportedException: ConstructorContainsNullParameterNames, System.Collections.Generic.KeyValuePair`2[System.String,System.String]
   at System.Text.Json.ThrowHelper.ThrowNotSupportedException_ConstructorContainsNullParameterNames(Type )

The issue would appear to be with System.Text.Json not supporting KeyValuePair deserialization.

So far I've tried replacing the KeyValuePair with a List<KeyValueClass> and again works fine locally to display a list of users with claims on the users.razor page, but fails gain when deployed to Azure.

The replacement class used to retrieve a user record:
record User(Guid Id, string Email, string LockedOut, string[] Roles, List<KeyValueClass> Claims, string DisplayName, string UserName);

public class KeyValueClass
{
  [JsonProperty("Key")]
  public string Key { get; set; }
  [JsonProperty("value")]
  public string Value { get; set; }
}

Targeting the api directly from the browser (and postman) also returns perfectly good json, ie.:
https://??????????????????.azurewebsites.net/api/identity/userlist?skip=0&limit=10

Returned Raw Data example:

{
   "total":2,
   "data":[
      {
         "id":"319690b5-cad9-4fff-9ceb-ccc824a0e5b8",
         "email":"auser@email",
         "lockedOut":"",
         "roles":[
            "Administrator"
         ],
         "claims":[
            {
               "key":"Name",
               "value":"auser"
            }
         ],
         "displayName":"auser",
         "userName":"auser@email"
      },
      {
         "id":"c77bf450-e898-409d-b938-e51f2e9f15cc",
         "email":"admin@email",
         "lockedOut":"",
         "roles":[
            "Administrator"
         ],
         "claims":[
            {
               "key":"Name",
               "value":"Thenew Administrator"
            },
            {
               "key":"Country",
               "value":"England"
            }
         ],
         "displayName":"Thenew Administrator",
         "userName":"admin@email"
      }
   ]
}

In both cases (VS2022 local, and Azure deployment) the data is coming from the same Azure SQL Database.

Anyone else getting the same issue?

@mguinness
Copy link
Owner

mguinness commented Dec 13, 2023

Maybe related to A published blazor wasm app throws a serialization error "Unhandled exception rendering component: ConstructorContainsNullParameterNames".

If the deployment is in release mode instead of debug mode it could point to trimming issues - try adding the following to your csproj file and republish the app again.

<PublishTrimmed>false</PublishTrimmed>

@gavnlh
Copy link
Author

gavnlh commented Dec 14, 2023

Hi, yes have tried all of the recommendations due to trimming issues. Do you have this code working from Azure?

@mguinness
Copy link
Owner

This issue does appear to be related to generic KeyValuePair, I tried non-generic DictionaryEntry and it worked fine.

Try changing from

record User(Guid Id, string Email, string LockedOut, string[] Roles, KeyValuePair<string, string>[] Claims, string DisplayName, string UserName);

To the following

record User(Guid Id, string Email, string LockedOut, string[] Roles, System.Collections.DictionaryEntry[] Claims, string DisplayName, string UserName);

You will also have to unbox the string values from the DictionaryEntry in ChangeUser method to get it working.

This problem was also raised in blazor wasm throwing deserialization exception when published with an example.

@gavnlh
Copy link
Author

gavnlh commented Dec 19, 2023

I made the DictionaryEntry[] change. Again works fine locally in VS2022. Published to Azure and the api/identity/userlist?skip=0&limit=10 again returns perfectly good json.

Unfortunately, navigating to the 'Users.razor' page deployed to Azure now returns the following error:

Screenshot 2023-12-19 142418

All seems to be working OK in debug and release mode in VS2022. Inspecting objects at breakpoints shows everything as it should be when running on the local machine. I've not yet looked into this error, but have a suspicion that it is caused by the .0.0 that follows the 8

So, no solution yet :-(

@mguinness
Copy link
Owner

mguinness commented Dec 19, 2023

Try enabling detailed runtime logging with the following:

import { dotnet } from './dotnet.js'
await dotnet
  .withDiagnosticTracing(true) // enable JavaScript tracing
  .withConfig({environmentVariables: {
    "MONO_LOG_LEVEL":"debug", //enable Mono VM detailed logging by
    "MONO_LOG_MASK":"all", // categories, could be also gc,aot,type,...
  }})
  .run();

Taken from Runtime logging and tracing for WASM.

@kg Any other suggestions? Try using WasmNativeStrip?

@kg
Copy link

kg commented Dec 19, 2023

Yes, your suggestions are good and setting <WasmNativeStrip>false</WasmNativeStrip> in a property group in your csproj should also help.

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

No branches or pull requests

3 participants