Mono: Cannot load .NET Standard 2.0 class library built by VS2017 with mono/wasm.

Created on 18 Nov 2018  路  3Comments  路  Source: mono/mono

Steps to Reproduce

  1. Create a .NET Standard 2.0 class library project in VS2017. (project is attached)
  2. Download the latest mono/wasm sdk
  3. Use the dll built by VS2017 in a static website with mono/wasm
  4. See the error when the page loaded.

Note: the error will not occur if the class library is built with mcs. (See build.ps1)

Current Behavior

Error occurred:

Uncaught (in promise) Error: Could not find class: MonoWasmDemo:Program

The .NET Standard class library project containing downloaded mono/wasm files:
MonoWasmDemo.zip

Expected Behavior

No error occurs and the console prints "Hello from C#!".

On which platforms did you notice this

Windows 10, Chrome Version 70.0.3538.102

Version Used:
mono-wasm:
https://jenkins.mono-project.com/job/test-mono-mainline-wasm/label=ubuntu-1804-amd64/lastSuccessfulBuild/Azure/processDownloadRequest/1476/ubuntu-1804-amd64/sdks/wasm/mono-wasm-f30ce1cbcee.zip

Stacktrace

mono.js:7877 Loaded: MonoWasmDemo.dll
mono.js:7877 Loaded: System.Net.Http.dll
mono.js:7877 Loaded: Mono.Security.dll
mono.js:7877 Loaded: WebAssembly.Bindings.dll
mono.js:7877 Loaded: WebAssembly.Net.Http.dll
mono.js:7877 Loaded: System.Core.dll
mono.js:7877 Loaded: System.dll
mono.js:7877 Loaded: System.Xml.dll
mono.js:7877 Loaded: mscorlib.dll
mono.js:7883 initializing mono runtime
mono.js:7809 >>mono_wasm_runtime_ready
mono.js:8546 Uncaught (in promise) Error: Could not find class: MonoWasmDemo:Program
    at Object.resolve_method_fqn (mono.js:8546)
    at Object.call_static_method (mono.js:8555)
    at runtime.js:11
    at mono.js:7900
target-wasm

Most helpful comment

We are working on tooling.

Thanks for letting us know that it worked and your feedback.

All 3 comments

@zwcloud First thank you for the great example.

It looks like there are some libraries missing from the loaded assemblies list if you are publishing for .NET Standard 2.0.

Did you run the packager.exe on the MonoWasmDemo.dll that was output in the .\bin\debug\netstandard2.0\?

I did the following as outline from sample doc.

In step 4. Package and publish sample there is a utility program delivered in the zip file that you can run to assemble all the assemblies needed.

%WASM_SDK%packager.exe --copy=ifnewer --out=.\publish --asset=index.html .\bin\debug\netstandard2.0\MonoWasmDemo.dll

The %WASM_SDK% points to the .zip file download. Instructions can be found here

I just set:

set WASM_SDK=c:\projects\mono\sdks\

Once you have that you can serve it from the publish directory.

Try that and let us know how it goes.

@kjpou1

It looks like there are some libraries missing from the loaded assemblies list if you are publishing for .NET Standard 2.0.

But if I build the project as an .NET Framework 4.6.1 class library, the output MonoWasmDemo.dll is able to be loaded. So I thought it also works for a regular .NET Standard assembly.

In step 4. Package and publish sample there is a utility program delivered in the zip file that you can run to assemble all the assemblies needed.

This is the step I neglected.

PS D:\Workspace\0_Experiment\MonoWasmDemo> .\MonoWasmSdk\packager.exe --copy=ifnewer --out=.\publish --asset=index.html .\bin\debug\netstandard2.0\MonoWasmDemo.dll
Processing D:\Workspace\0_Experiment\MonoWasmDemo\bin\debug\netstandard2.0\MonoWasmDemo.dll debug False
Processing D:\Workspace\0_Experiment\MonoWasmDemo\MonoWasmSdk\wasm-bcl\wasm\Facades\netstandard.dll debug False
Processing D:\Workspace\0_Experiment\MonoWasmDemo\MonoWasmSdk\wasm-bcl\wasm\mscorlib.dll debug False
Processing D:\Workspace\0_Experiment\MonoWasmDemo\MonoWasmSdk\wasm-bcl\wasm\System.Core.dll debug False
Processing D:\Workspace\0_Experiment\MonoWasmDemo\MonoWasmSdk\wasm-bcl\wasm\System.dll debug False
Processing D:\Workspace\0_Experiment\MonoWasmDemo\MonoWasmSdk\wasm-bcl\wasm\Mono.Security.dll debug False
Processing D:\Workspace\0_Experiment\MonoWasmDemo\MonoWasmSdk\wasm-bcl\wasm\System.Xml.dll debug False
Processing D:\Workspace\0_Experiment\MonoWasmDemo\MonoWasmSdk\wasm-bcl\wasm\System.Data.dll debug False
Processing D:\Workspace\0_Experiment\MonoWasmDemo\MonoWasmSdk\wasm-bcl\wasm\System.Numerics.dll debug False
Processing D:\Workspace\0_Experiment\MonoWasmDemo\MonoWasmSdk\wasm-bcl\wasm\System.Transactions.dll debug False
Processing D:\Workspace\0_Experiment\MonoWasmDemo\MonoWasmSdk\wasm-bcl\wasm\System.Drawing.dll debug False
Processing D:\Workspace\0_Experiment\MonoWasmDemo\MonoWasmSdk\wasm-bcl\wasm\System.IO.Compression.dll debug False
Processing D:\Workspace\0_Experiment\MonoWasmDemo\MonoWasmSdk\wasm-bcl\wasm\System.IO.Compression.FileSystem.dll debug False
Processing D:\Workspace\0_Experiment\MonoWasmDemo\MonoWasmSdk\wasm-bcl\wasm\System.ComponentModel.Composition.dll debug False
Processing D:\Workspace\0_Experiment\MonoWasmDemo\MonoWasmSdk\wasm-bcl\wasm\System.Net.Http.dll debug False
Processing D:\Workspace\0_Experiment\MonoWasmDemo\MonoWasmSdk\wasm-bcl\wasm\System.Runtime.Serialization.dll debug False
Processing D:\Workspace\0_Experiment\MonoWasmDemo\MonoWasmSdk\wasm-bcl\wasm\System.ServiceModel.Internals.dll debug False
Processing D:\Workspace\0_Experiment\MonoWasmDemo\MonoWasmSdk\wasm-bcl\wasm\System.Web.Services.dll debug False
Processing D:\Workspace\0_Experiment\MonoWasmDemo\MonoWasmSdk\wasm-bcl\wasm\System.Xml.Linq.dll debug False
Processing D:\Workspace\0_Experiment\MonoWasmDemo\MonoWasmSdk\framework\WebAssembly.Bindings.dll debug False
cp: IfNewer - D:\Workspace\0_Experiment\MonoWasmDemo\bin\debug\netstandard2.0\MonoWasmDemo.dll -> .\publish\managed\MonoWasmDemo.dll
cp: IfNewer - D:\Workspace\0_Experiment\MonoWasmDemo\MonoWasmSdk\wasm-bcl\wasm\Facades\netstandard.dll -> .\publish\managed\netstandard.dll
cp: IfNewer - D:\Workspace\0_Experiment\MonoWasmDemo\MonoWasmSdk\wasm-bcl\wasm\mscorlib.dll -> .\publish\managed\mscorlib.dll
cp: IfNewer - D:\Workspace\0_Experiment\MonoWasmDemo\MonoWasmSdk\wasm-bcl\wasm\System.Core.dll -> .\publish\managed\System.Core.dll
cp: IfNewer - D:\Workspace\0_Experiment\MonoWasmDemo\MonoWasmSdk\wasm-bcl\wasm\System.dll -> .\publish\managed\System.dll
cp: IfNewer - D:\Workspace\0_Experiment\MonoWasmDemo\MonoWasmSdk\wasm-bcl\wasm\Mono.Security.dll -> .\publish\managed\Mono.Security.dll
cp: IfNewer - D:\Workspace\0_Experiment\MonoWasmDemo\MonoWasmSdk\wasm-bcl\wasm\System.Xml.dll -> .\publish\managed\System.Xml.dll
cp: IfNewer - D:\Workspace\0_Experiment\MonoWasmDemo\MonoWasmSdk\wasm-bcl\wasm\System.Data.dll -> .\publish\managed\System.Data.dll
cp: IfNewer - D:\Workspace\0_Experiment\MonoWasmDemo\MonoWasmSdk\wasm-bcl\wasm\System.Numerics.dll -> .\publish\managed\System.Numerics.dll
cp: IfNewer - D:\Workspace\0_Experiment\MonoWasmDemo\MonoWasmSdk\wasm-bcl\wasm\System.Transactions.dll -> .\publish\managed\System.Transactions.dll
cp: IfNewer - D:\Workspace\0_Experiment\MonoWasmDemo\MonoWasmSdk\wasm-bcl\wasm\System.Drawing.dll -> .\publish\managed\System.Drawing.dll
cp: IfNewer - D:\Workspace\0_Experiment\MonoWasmDemo\MonoWasmSdk\wasm-bcl\wasm\System.IO.Compression.dll -> .\publish\managed\System.IO.Compression.dll
cp: IfNewer - D:\Workspace\0_Experiment\MonoWasmDemo\MonoWasmSdk\wasm-bcl\wasm\System.IO.Compression.FileSystem.dll -> .\publish\managed\System.IO.Compression.FileSystem.dll
cp: IfNewer - D:\Workspace\0_Experiment\MonoWasmDemo\MonoWasmSdk\wasm-bcl\wasm\System.ComponentModel.Composition.dll -> .\publish\managed\System.ComponentModel.Composition.dll
cp: IfNewer - D:\Workspace\0_Experiment\MonoWasmDemo\MonoWasmSdk\wasm-bcl\wasm\System.Net.Http.dll -> .\publish\managed\System.Net.Http.dll
cp: IfNewer - D:\Workspace\0_Experiment\MonoWasmDemo\MonoWasmSdk\wasm-bcl\wasm\System.Runtime.Serialization.dll -> .\publish\managed\System.Runtime.Serialization.dll
cp: IfNewer - D:\Workspace\0_Experiment\MonoWasmDemo\MonoWasmSdk\wasm-bcl\wasm\System.ServiceModel.Internals.dll -> .\publish\managed\System.ServiceModel.Internals.dll
cp: IfNewer - D:\Workspace\0_Experiment\MonoWasmDemo\MonoWasmSdk\wasm-bcl\wasm\System.Web.Services.dll -> .\publish\managed\System.Web.Services.dll
cp: IfNewer - D:\Workspace\0_Experiment\MonoWasmDemo\MonoWasmSdk\wasm-bcl\wasm\System.Xml.Linq.dll -> .\publish\managed\System.Xml.Linq.dll
cp: IfNewer - D:\Workspace\0_Experiment\MonoWasmDemo\MonoWasmSdk\framework\WebAssembly.Bindings.dll -> .\publish\managed\WebAssembly.Bindings.dll
runtime template <runtime.js> cp: IfNewer - runtime.js -> .\publish\runtime.js
Asset: cp: IfNewer - index.html -> .\publish\index.html

The assembly processed by packager.exe can now be loaded by mono-wasm! Thank you very much!


But I want to make a point that mono-wasm should be able to load the .NET Standard assembly built by Visual Studio directly without any extra assembling procedure. I think this compatibility guarantee is essential for easier integration with current .NET architecture.

We are working on tooling.

Thanks for letting us know that it worked and your feedback.

Was this page helpful?
0 / 5 - 0 ratings