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

browser-wasm - System.TypeLoadException: Could not load type 'System.Runtime.InteropServices.MemoryMarshal' #2731

Open
oudi opened this issue Oct 25, 2024 · 5 comments
Labels
area-NativeAOT-LLVM LLVM generation for Native AOT compilation (including Web Assembly)

Comments

@oudi
Copy link

oudi commented Oct 25, 2024

With the sample https://github.com/dotnet/runtimelab/tree/feature/NativeAOT-LLVM/samples/NativeLibrary

  • dotnet --info Version: 9.0.0-rc.2.24473.5
  • emsdk Version 3.1.70

when click = Button in the sample, the console of brower show error below

Unhandled exception. System.TypeLoadException: Could not load type 'System.Runtime.InteropServices.MemoryMarshal' from assembly 'System.Runtime, Version=9.0.0.0, Culture=neutral, PublicKey=002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293'.

   at Internal.Runtime.CompilerHelpers.ThrowHelpers.ThrowTypeLoadException(ExceptionStringID, String, String):0x138874
   at NativeLibrary.NativeLibrary.ComputeArithmeticExpression(Byte*):0x19e3e6
   at http://localhost:6931/bin/Release/net9.0/browser-wasm/publish/NativeLibrary.js:594:12
   at HTMLDivElement.<anonymous> (http://localhost:6931/NativeLibraryHost.html:56:34)
Aborted(native code called abort())

Uncaught RuntimeError: Aborted(native code called abort())
    at abort (NativeLibrary.js:561:11)
    at __abort_js (NativeLibrary.js:3874:7)
    at NativeLibrary.wasm:0x1a6cee
    at NativeLibrary.wasm:0x135e40
    at NativeLibrary.wasm:0x149ddc
    at NativeLibrary.wasm:0x19dcd6
    at NativeLibrary.wasm:0x18d8ab
    at NativeLibrary.wasm:0x19e403
    at NativeLibrary.wasm:0x168467
    at NativeLibrary.wasm:0x16828a
  • NativeLibrary.csproj
<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>library</OutputType>
    <TargetFramework>net9.0</TargetFramework>
    <AllowUnsafeBlocks>true</AllowUnsafeBlocks>

    <PublishTrimmed>true</PublishTrimmed>
    <SelfContained>true</SelfContained>
    <MSBuildEnableWorkloadResolver>false</MSBuildEnableWorkloadResolver>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.DotNet.ILCompiler.LLVM" Version="9.0.0-*" />
    <PackageReference Include="runtime.$(NETCoreSdkPortableRuntimeIdentifier).Microsoft.DotNet.ILCompiler.LLVM" Version="9.0.0-*" />
  </ItemGroup>

  <ItemGroup>
    <LinkerArg Include="-sEXPORTED_RUNTIME_METHODS=stringToNewUTF8" />
  </ItemGroup>

</Project>
  • nuget.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
 <packageSources>
    <!--To inherit the global NuGet package sources remove the <clear/> line below -->
    <clear />
    <add key="dotnet9" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet9/nuget/v3/index.json" />
    <add key="dotnet-public" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-public/nuget/v3/index.json" />
    <add key="dotnet-experimental" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-experimental/nuget/v3/index.json" />
 </packageSources>
</configuration>
@jkotas jkotas added the area-NativeAOT-LLVM LLVM generation for Native AOT compilation (including Web Assembly) label Oct 25, 2024
@jkotas
Copy link
Member

jkotas commented Oct 25, 2024

Could not load type 'System.Runtime.InteropServices.MemoryMarshal'

This error is caused by breaking changes done between previews and release candidates. It should get fixed by #2730

@jkotas
Copy link
Member

jkotas commented Oct 25, 2024

Actually, we have the fix in NativeAOT-LLVM branch but it is in 10.0.0 package. Could you please try updating the package versions to 10.0.0 to see whether it fixes it?

    <PackageReference Include="Microsoft.DotNet.ILCompiler.LLVM" Version="9.0.0-*" />
    <PackageReference Include="runtime.$(NETCoreSdkPortableRuntimeIdentifier).Microsoft.DotNet.ILCompiler.LLVM" Version="9.0.0-*" />

@oudi
Copy link
Author

oudi commented Oct 28, 2024

Actually, we have the fix in NativeAOT-LLVM branch but it is in 10.0.0 package. Could you please try updating the package versions to 10.0.0 to see whether it fixes it?

    <PackageReference Include="Microsoft.DotNet.ILCompiler.LLVM" Version="9.0.0-*" />
    <PackageReference Include="runtime.$(NETCoreSdkPortableRuntimeIdentifier).Microsoft.DotNet.ILCompiler.LLVM" Version="9.0.0-*" />

It fiexed! thanks.

@oudi oudi closed this as completed Oct 28, 2024
@jkotas
Copy link
Member

jkotas commented Oct 28, 2024

We should update the sample to point to use dotnet10 TFM

@jkotas jkotas reopened this Oct 28, 2024
oudi added a commit to oudi/runtimelab that referenced this issue Oct 28, 2024
fix stringToNewUTF8 not export & issue dotnet#2731
@oudi
Copy link
Author

oudi commented Oct 28, 2024

We should update the sample to point to use dotnet10 TFM

there are another problem stringToNewUTF8 not export! I create a pull to fix this all.

jkotas pushed a commit that referenced this issue Oct 29, 2024
* fix samples/NativeLibrary

fix stringToNewUTF8 not export & issue #2731

* Update ILCompiler.LLVM to 10.0.0

Update samples HelloWorld to 10.0.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-NativeAOT-LLVM LLVM generation for Native AOT compilation (including Web Assembly)
Projects
None yet
Development

No branches or pull requests

2 participants