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.