0

I have a problem with static classes from image processing libraries in blazor webassembly. As soon as i use one i get a TypeInitializationException like in this screenshot: TypeInitializationException

I use the visual studio version 17.7.3 and .NET SDK 7.0.400 (x64)

And this is my solution config. if it helps:

<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">

    <PropertyGroup>
        <TargetFramework>net7.0</TargetFramework>
        <AssemblyVersion>1.0.0</AssemblyVersion>
        <Nullable>enable</Nullable>
        <ImplicitUsings>enable</ImplicitUsings>
        <ServiceWorkerAssetsManifest>service-worker-assets.js</ServiceWorkerAssetsManifest>
        <BlazorWebAssemblyLoadAllGlobalizationData>true</BlazorWebAssemblyLoadAllGlobalizationData>
    </PropertyGroup>

    <ItemGroup>
        <Content Remove="compilerconfig.json" />
    </ItemGroup>

    <ItemGroup>
        <_ContentIncludedByDefault Remove="compilerconfig.json" />
    </ItemGroup>

    <ItemGroup>
        <None Include="compilerconfig.json" />
    </ItemGroup>

    <ItemGroup>
        <PackageReference Include="Blazor.SignaturePad" Version="7.4.2" />
        <PackageReference Include="Blazored.LocalStorage" Version="4.4.0" />
        <PackageReference Include="BrowserInterop" Version="1.1.2" />
        <PackageReference Include="Microsoft.AspNetCore.Components.Authorization" Version="7.0.10" />
        <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="7.0.10" />
        <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="7.0.10" PrivateAssets="all" />
        <PackageReference Include="Microsoft.Extensions.Localization" Version="7.0.10" />
        <PackageReference Include="ReactorBlazorQRCodeScanner" Version="1.0.5" />
        <PackageReference Include="signaturepad" Version="1.5.3" />
        <PackageReference Include="ZKWeb.System.Drawing" Version="4.0.1" />
    </ItemGroup>
</Project>

Thanks in advance for the answers!

  • Different .NET SDKs
  • Different Visual studio versions
  • dotnet restore
  • Rebuilding and Cleaning
  • Different Image Processing Libraries like ImageSharp, SkiaSharp, Magick.NET
2
  • 99% sure System.Drawing is not compatible with WebAssembly. 100% sure those libraries utilize System.Drawing. You are going to need to handle images server side or find a 100% WebAssembly compatible library.
    – mxmissile
    Commented Sep 8, 2023 at 14:15
  • AFAIK System.Drawing is not a .NET Core library. You cannot use it.
    – Grizzlly
    Commented Sep 11, 2023 at 20:26

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.