When my Blazor WASM project was using .net core project 3.1, Debug.WriteLine("test") would output to Chromes console window.
After upgrading everything to .net core 5.0.301 Nothing is output.
I get this error show in the Visual Studio to debug console.
fail: Microsoft.WebAssembly.Diagnostics.DevToolsProxy[0]
sending error response for id: msg-62E669E5DBE5C53DAF0973BE80FD50E4:::1032 -> [Result: IsOk: False, IsErr: True, Value: , Error: {
"result": {
"type": "object",
"subtype": "error",
"description": "Cannot find member named 'Debug'.",
"className": "ReferenceError"
}
} ]
Does anyone have any ideas?
Although said bug is claimed to be fixed in .NET 6, in .NET 7 I (still or yet again, I did not test it) can't use
Debug.WriteLine()
to output text to the browser console: The texts just never show up.In order to achieve the desired effect - that is, debugging to the browser console in Debug mode, while in release mode these debugging texts shall be omitted -, I do it like this:
This way, when I do something like
ConsoleDebug("something went wrong");
, it's being printed to the browser console when run in debug mode, whereas when in release mode, nothing happens.If you make a component (e.g.
DebugToConsole.razor
) containing the code above, you can simply put@using static DebugToConsole
in_Imports.razor
and use it in all your components via ConsoleDebug("your text").