1
Error in all Excel files: The type initializer for '_VAb' threw an exception
Problem reported by Spyros M - 3/11/2025 at 2:22 PM
Resolved
I'm getting the following error when trying to view all excel files in our DocumentViewer installation:
DocumentViewer:



ASP .NET 6.0 runtime. Our environment is Ubuntu linux, could that be related? Word document are loading correctly though.

Thanks in advance,
Spyros

10 Replies

Reply to Thread
0
Cem Alacayir Replied
Employee Post
> Our environment is Ubuntu linux, could that be related?
Yes it's highly related.

It's probably caused by System.Drawing.Common package which DocumentUltimate still depends on, for some document formats.

Microsoft decided to make it "Windows only" in .NET 6. The package will show compile warnings, since it relies on libgdiplus which might not be present on some Linux distribution. See System.Drawing.Common only supported on Windows.

However there is a solution:

You can enable support for non-Windows platforms in .NET 6 by setting the System.Drawing.EnableUnixSupport runtime configuration switch to true in the runtimeconfig.json file.

runtimeconfig.template.json template file:

JSON
{
   "configProperties": {
      "System.Drawing.EnableUnixSupport": true
   }
}

[appname].runtimeconfig.json output file:

JSON
{
   "runtimeOptions": {
      "configProperties": {
         "System.Drawing.EnableUnixSupport": true
      }
   }
}

References:
https://stackoverflow.com/questions/44428405/i-am-using-net-core-with-c-sharp-on-linux-and-library-system-drawing-is-miss
https://learn.microsoft.com/en-us/dotnet/core/compatibility/core-libraries/6.0/system-drawing-common-windows-only

In future versions, we plan to drop System.Drawing.Common package dependency for all formats.
0
Spyros M Replied
hi there , thanks for the response. I performed the proposed steps and the error persists. Just to make sure we are on the same page, we did the following:
1) added a runtimeconfig.template.json in our project
2) upon successful build we made sure that the EnableUnixSupport setting is enabled in [appname].runtimeconfig.json file. 
3) updated the DLL (along with the runtime config) on the target server and restarted the linux container that servers the ASP .NET web app. 

Still the same error though. Our references are as follows:

 
any thoughts?
0
Cem Alacayir Replied
Employee Post

Add the following line to the .csproj file in a PropertyGroup section:

<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>

Next create a file named runtimeconfig.template.json in the same directory as your project file containing:

{
      "configProperties": {
         "System.Drawing.EnableUnixSupport": true
      }
}

Using the dotnet publish command, will create a [YourAppNameHere].runtimeconfig.json file in the output directory I supplied to the dotnet publish command.

For an asp.net project, the publish result will look like in the following for [YourAppNameHere].runtimeconfig.json file:

{
  "runtimeOptions": {
    "tfm": "net6.0",
    "includedFrameworks": [
      {
        "name": "Microsoft.NETCore.App",
        "version": "6.0.1"
      },
      {
        "name": "Microsoft.AspNetCore.App",
        "version": "6.0.1"
      }
    ],
    "configProperties": {
      "System.Drawing.EnableUnixSupport": true,
      "System.GC.Server": true,
      "System.Reflection.Metadata.MetadataUpdater.IsSupported": false,
      "System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false
    }
  }
}

The published result should NOT look like this:
{
  "runtimeOptions": {
    "tfm": "net6.0",
    "includedFrameworks": [
      {
        "name": "Microsoft.NETCore.App",
        "version": "6.0.1"
      },
      {
        "name": "Microsoft.AspNetCore.App",
        "version": "6.0.1"
      }
    ],
    "runtimeOptions": {
      "configProperties": {
        "System.Drawing.EnableUnixSupport": true
      }
    },
    "configProperties": {
      "System.GC.Server": true,
      "System.Reflection.Metadata.MetadataUpdater.IsSupported": false,
      "System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false
    }
  }
}
Note the nested runtimeOptions, which will not work.

Also note that in your screenshot, you are referencing 8.0.0 version of System.Drawing.Common, version larger than 6.x may not work with this settings. DocumentUltimate v7.4.0 started to reference 6.0.0 version of System.Drawing.Common so I don't know why it's incremented to 8.0.0 in your project, try to decrement it to 6.0.0.

Also there seem to be an easier other way than messing with runtimeconfig.template.json file, you can try to set the switch in code (in application startup):

AppContext.SetSwitch("System.Drawing.EnableUnixSupport", true);

References:
0
Spyros M Replied
Yes, I confirm that we applied the above steps but unfortunately still it doesn't work. We even tried to set this switch via code. The issue must lie to the underlying version of System.Drawing.Common assembly that you observed. The stackoverflow thread you referred me to, mentions "The answers listed above do not work for System.Drawing.Common 7.0.0 and above on .NET 6.". However we can't find the source of this dependency since it's automatically added to our project when we reference Gleamtech.DocumentUltimate. 

Any ideas how to force the library to reference System.Drawing.Common v6.0.0?
0
Cem Alacayir Replied
Employee Post
Well it obviously comes from package EPPlus which is in your screenshot, you need to decrement its version from 7.5.3 to 7.4.2.
0
Spyros M Replied
hi there,

After downgrading EPPlus and referencing v6 of the System.Drawing.Common we still are getting the same behavior:


Please let us know if you have any other idea.

Thanks
0
Cem Alacayir Replied
Employee Post
Other ideas:
System.Drawing.Common relies on libgdiplus which might not be present on some Linux distribution, probably on Ubuntu too. And it seems it's not installed along with .NET runtime. Try installing these libs on your Ubuntu:

sudo apt install libgdiplus
and if that's not enough maybe also

sudo apt install libc6-dev
Hopefully it works now.

References:
0
Spyros M Replied
still the same, sorry. These 2 packages were already deployed in their latest version in our machine.
1
Cem Alacayir Replied
Employee Post Marked As Resolution
Ok, I tested DocumentUltimate AspNetCoreCS example project on Ubuntu 24.04.1 LTS (on Windows Bash).

Adding this setting to .csproj fixed the exception for Excel files:

<ItemGroup>
  <RuntimeHostConfigurationOption Include="System.Drawing.EnableUnixSupport" Value="true" />
</ItemGroup>
This does the same thing like the other methods but it's more clean and easy, i.e. it adds the same setting to the generated [YourAppNameHere].runtimeconfig.json next to the app dll. So Remove other methods runtimeconfig.template.json file and 
<GenerateRuntimeConfigurationFiles> from your project and only use <RuntimeHostConfigurationOption>.


Here are the steps I followed:

1. I installed .NET 6.0 on Ubuntu via script method (provided by Microsoft) as it seems Microsoft does no longer support this version on newer Ubuntu via apt install:

wget https://dot.net/v1/dotnet-install.sh -O dotnet-install.sh
chmod +x ./dotnet-install.sh
./dotnet-install.sh --channel 6.0

2. I edited bash profile file in my home directory, i.e. the file ~/.bashrc and added these lines for being able to access dotnet commands:

export DOTNET_ROOT=$HOME/.dotnet
export PATH=$PATH:$DOTNET_ROOT:$DOTNET_ROOT/tools
Ref:

3. When I run the project via dotnet run, and went to the created link http://localhost:5221, the app worked but DocumentViewer showed an error about missing fonts (not for Excel for any document). 

The "Arial" font family could not be found in the following directories: * /usr/local/share/fonts/ *

This error probably came from ImageSharp.Fonts package which is used internally. I installed MS fonts package to fix it:

sudo apt install msttcorefonts
Although the app compiled and worked first time except font error, I also added .NET dependencies for Ubuntu, just in case:

sudo apt-get update \
    && sudo apt-get install -y --no-install-recommends \
    libc6 \
    libgcc-s1 \
    libicu74 \
    libssl3 \
    libstdc++6 \
    zlib1g 
and also libgdiplus for System.Drawing.Common assembly:

sudo apt install libgdiplus
Ref:

4. After this, PDF and Word files worked but I got the same error as you for the Excel files:

The type initializer for '_VAb' threw an exception.

Then I added this to my .csproj file

<ItemGroup>
  <RuntimeHostConfigurationOption Include="System.Drawing.EnableUnixSupport" Value="true" />
</ItemGroup>

And I run the project via dotnet run again, and voila! The Excel files started working and displaying.


For your case, is it possible that you installed a higher version than .NET 6.0 on Ubuntu? Because Microsoft implies that System.Drawing.Common is not supported after .NET 6.0 and even on .NET 6.0 you need the switch. So if you have .NET 8.0 on your Ubuntu it may not work even with switch. Normally .NET 8.0 runtime can run .NET 6.0 apps but System.Drawing.Common is an exception.
1
Spyros M Replied
thank you very much! That post pointed us to the correct direction. We needed to apply some of the steps within our linux docker container as opposed to the host, and it also seems to resolve our issues with the missing fonts.

Thanks again,
Spyros

Reply to Thread