question

MarkMakSekKwai-6048 avatar image
0 Votes"
MarkMakSekKwai-6048 asked MarkMakSekKwai-6048 commented

Mvc.Razor.RazorViewEngine cannot load library (System.Drawing.Common)

Information:
My MVC program will use Razor to generate an email template.
However, I found that the program does not work in Windows Server 2019.
It seems like the "Mvc.Razor.RazorViewEngine" cannot load the library under .net runtime. (I use DLLFinder64.exe to check and make sure the program loaded the library)

DLLFinder64 output

C:\share\DLLFinder>DLLFinder64.exe -f System.Drawing.Common.dll

Process Name PID DLL Name Base Address Load Count DLL Path
================================================================

NexTore.WebApp.exe 7644 System.Drawing.Common.dll 0x00007FF8B32B0000 1 C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App\3.1.16\System.Drawing.Common.dll


Workaround method:
Copy the missing libraries to my program's working directory


Error Log (the upload feature not working, no idea what happened. I share the log in below link)

https://drive.google.com/file/d/1L7ssUOCxUpZy66taKbC1wO9sFMETShkn/view?usp=sharing


Package Reference

<ItemGroup>
<PackageReference Include="AutoMapper" Version="10.1.1" />
<PackageReference Include="AutoMapper.Extensions.ExpressionMapping" Version="4.1.0" />
<PackageReference Include="ClosedXML" Version="0.95.3" PrivateAssets="compile" />
<PackageReference Include="FastMember.NetCore" Version="1.1.0" PrivateAssets="compile" />
<PackageReference Include="Hangfire.AspNetCore" Version="1.7.22" PrivateAssets="compile" />
<PackageReference Include="Hangfire.SqlServer" Version="1.7.22" PrivateAssets="compile" />
<PackageReference Include="Hangfire.Storage.MySql" Version="2.1.0-beta" />
<PackageReference Include="MimeTypeMapOfficial" Version="1.0.14" />
<PackageReference Include="iTextSharp" Version="5.5.13.1" PrivateAssets="compile" />
<PackageReference Include="Lucene.Net" Version="4.8.0-beta00014" PrivateAssets="compile" />
<PackageReference Include="Lucene.Net.ICU" Version="4.8.0-beta00014" PrivateAssets="compile" />
<PackageReference Include="Lucene.Net.QueryParser" Version="4.8.0-beta00014" PrivateAssets="compile" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.7" PrivateAssets="compile" />
<!-- https://github.com/dotnet/aspnetcore/issues/7223#issuecomment-460278162
razor compilation package adds refs folder in module's output folder, PrivateAssets prevents it -->
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="3.1.7" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="3.7.0" PrivateAssets="compile" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="5.0.6" PrivateAssets="compile" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="5.0.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.6" PrivateAssets="compile" />
<PackageReference Include="MySqlConnector.Authentication.Ed25519" Version="1.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="Newtonsoft.Json.Schema" Version="3.0.13" />
<PackageReference Include="NexTore.OptimaJet.Workflow.MySQL" Version="4.1.4" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="5.0.0" />
<PackageReference Include="System.Linq.Dynamic.Core" Version="1.2.2" />
<PackageReference Include="UnityAddon.Cache" Version="2.6.5.1313" />
<PackageReference Include="UnityAddon.Core" Version="2.9.17.1332" />
<PackageReference Include="UnityAddon.Ef" Version="2.6.11.1315" />
<PackageReference Include="UnityAddon.Hangfire" Version="2.6.5.1316" />
<PackageReference Include="UnityAddon.Utilities" Version="2.0.16.1282" />
<PackageReference Include="WorkflowEngine.NETCore-Core" Version="4.1.4" />
<PackageReference Include="WorkflowEngine.NETCore-ProviderForMSSQL" Version="4.1.4" PrivateAssets="compile" />
<PackageReference Include="NexTore.DistributedTask.Client" Version="1.0.0.4210" />
</ItemGroup>







dotnet-aspnet-core-razor
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@MarkMakSekKwai-6048

At the beginning of the post, it said that you copy System.Drawing.Common.dll to the program directory and it will work normally. The answer I gave is to include System.Drawing.Common.dll in the directory of the published file when publishing.

1 Vote 1 ·

Hi @JasonPan-MSFT

I got your point.
Your suggestion is to make the build event automatically copy the "System.Drawing.Common.dll" to the working directory to avoid the problem.

Test Result:
I applied the <ResolvedFileToPublish> modification to all my dlls project and webapp.exe project, the output directory does not include the "System.Drawing.Common.dll".
This may be the syntax problem of XML (anyway, thanks for this suggestion).

However, the strange place is that this only happens in Windows Server 2019. I deploy the same set of binary to Windows Server 2016, everything works fine.
I guess the root cause come from the "Microsoft.AspNetCore.Mvc.Razor.RazorViewEngine"/"Microsoft.Extensions.DependencyModel.CompilationLibrary.ResolveReferencePaths".

If anyone has a similar problem, copy the missing binary to the working directory is a workaround method.

To solve the root cause, it depends on Microsoft.

1 Vote 1 ·
JasonPan-MSFT avatar image
0 Votes"
JasonPan-MSFT answered

Hi @MarkMakSekKwai-6048 ,

The problem is you missing System.Drawing.Common after you published your webapp.

You just add below code in your .csproj file, you can replace my path. These code just includes dll file when publish.

 <ItemGroup>
     <ResolvedFileToPublish Include="System.Drawing.Common.dll">
     <RelativePath>System.Drawing.Common.dll</RelativePath>
     </ResolvedFileToPublish>
 </ItemGroup>



If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Best Regards,
Jason

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

MarkMakSekKwai-6048 avatar image
0 Votes"
MarkMakSekKwai-6048 answered

Hi @JasonPan-MSFT,

Thanks for your reply.

Actually, my project dependency is like below.

  • NexTore.WebApp.exe

  • NexTore.Core.dll

  • NexTore.DistributedTask.Client.dll (this one depend on "System.Drawing.Common.dll")

However, I can't directly modify the "NexTore.DistributedTask.Client.dll" (need some time to modify the .csproj file to test)

I did add the below setting to the .csproj files ("NexTore.WebApp.exe" and "NexTore.Core.dll", only modify one .csproj to test for each test case)

<ItemGroup>
<ResolvedFileToPublish Include="System.Drawing.Common.dll">
<RelativePath>System.Drawing.Common.dll</RelativePath>
</ResolvedFileToPublish>
</ItemGroup>


But the result is the same (cannot load the "System.Drawing.Common.dll")

pending to modify the "NexTore.DistributedTask.Client.dll" to test.


Question:

  • Which .csproj file should I put the <ItemGroup> setting?


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.