Repository navigation
Closed
Labels
Milestone
Description
Describe the bug
I am using Roslyn (e.g. Microsoft.CodeAnalysis.CSharp.*) in a Blazor WASM project. My code was working fine in 3.2, but after upgrading to 5.0-Preview7, I now receive the following runtime error when calling SemanticModel.GetDiagnostics().
blazor.webassembly.js:1 Uncaught (in promise) Error: System.TypeInitializationException: The type initializer for 'Crypto' threw an exception.
---> System.DllNotFoundException: libSystem.Security.Cryptography.Native.OpenSsl assembly:<unknown assembly> type:<unknown type> member:(null)
at Interop.Crypto..cctor()
--- End of inner exception stack trace ---
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
--- End of stack trace from previous location ---
at Microsoft.JSInterop.Infrastructure.DotNetDispatcher.InvokeSynchronously(JSRuntime jsRuntime, DotNetInvocationInfo& callInfo, IDotNetObjectReference objectReference, String argsJson)
at Microsoft.JSInterop.Infrastructure.DotNetDispatcher.BeginInvokeDotNet(JSRuntime jsRuntime, DotNetInvocationInfo invocationInfo, String argsJson)
at Object.endInvokeDotNetFromJS (http://localhost:51214/_framework/blazor.webassembly.js:1:3112)
at Object.invokeJSFromDotNet (http://localhost:51214/_framework/blazor.webassembly.js:1:2732)
at _mono_wasm_invoke_js_marshalled (http://localhost:51214/_framework/dotnet.5.0.0-preview.7.20364.11.js:1:164798)
at do_icall (<anonymous>:wasm-function[5230]:0xe660d)
at do_icall_wrapper (<anonymous>:wasm-function[1665]:0x4787d)
at interp_exec_method (<anonymous>:wasm-function[1200]:0x29604)
at interp_runtime_invoke (<anonymous>:wasm-function[4814]:0xcc5f0)
at mono_jit_runtime_invoke (<anonymous>:wasm-function[4317]:0xb63e1)
at do_runtime_invoke (<anonymous>:wasm-function[1664]:0x477c6)
at mono_runtime_try_invoke (<anonymous>:wasm-function[422]:0xd74c)
To Reproduce
In a Blazor WASM .Net 5.0-Preview7 project, add references to latest C# Roslyn compiler assemblies, and invoke the Roslyn compiler as follows:
var compilation = CSharpCompilation.Create(...);
var model = compilation.GetSemanticModel(tree);
var diag = model.GetDiagnostics(); // <-- Exception thrown hereCode works fine in 3.2, but fails in 5.0-Preview7.
Activity
pranavkm commentedon Jul 22, 2020
/cc @marek-safar
CoffeeFlux commentedon Jul 22, 2020
Seems like a loader or build problem? The runtime can't find OpenSSL. cc: @lewing @kg
lewing commentedon Jul 22, 2020
Yeah this is going to be an issue. That error should be different in recent builds but the code will still fail because the Cryptography classes are no longer available.
3 remaining items
RichardVogelij commentedon Jul 27, 2020
Would like to mention this also started appearing in the generation of PDF files using iTextSharp which worked fine in 3.2 but not any more in 5.0 due to
System.DllNotFoundException: libSystem.Security.Cryptography.Native.OpenSsl assembly:<unknown assembly> type:<unknown type> member:(null)marek-safar commentedon Jul 27, 2020
@lewing @akoeplinger What API does Roslyn call?
vcsjones commentedon Jul 27, 2020
@marek-safar Looks like Roslyn uses the SHA/MD5 algorithms to digest source files. https://github.com/dotnet/roslyn/blob/master/src/Compilers/Core/Portable/CryptographicHashProvider.cs
marek-safar commentedon Jul 29, 2020
I'm closing this as the original issue was fixed in Preview 8. We are now tracking the .NET5 crypto regressions in #40076.
msschl commentedon Aug 5, 2020
This also leads to signalr being unable to connect via websockets to a remote server in blazor wasm:
lewing commentedon Aug 5, 2020
@msschl what version of .NET are you seeing that stack trace from, it should be failing in a different place.
msschl commentedon Aug 5, 2020
@lewing
blazor-wasm, net5.0
Microsoft.AspNetCore.SignalR.Client Version:
5.0.0-preview.7.*lewing commentedon Aug 5, 2020
you shouldn't see this failure in preview 8
msschl commentedon Aug 5, 2020
Ok, I'll retest as soon as preview 8 is released.
akoeplinger commentedon Aug 5, 2020
To be clear, in preview8 you'll still get an exception but it will be a proper
PlatformNotSupportedExceptionrather than some misleading error about not findinglibSystem.Security.Cryptography.Native.OpenSsl.We're looking at adding support for the hash functions as part of #40076
lewing commentedon Aug 5, 2020
@akoeplinger preview 8 has browser websockets so it should hopefully just work.
akoeplinger commentedon Aug 5, 2020
@lewing ah I see, I was only looking at the part of the stacktrace that hit
System.Security.Cryptography.SHA1.Create()😄msschl commentedon Aug 26, 2020
@lewing In preview 8 it's actually worse. Before, the above mentioned exception got thrown, then signalr switched to long-polling and the site kept working. In preview 8 another exception (see issue #25259) gets thrown and the site stops working completely.