System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.CSharp, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.
File name: 'Microsoft.CSharp, Culture=neutral, PublicKeyToken=null'
at System.Reflection.RuntimeAssembly.InternalLoad(ObjectHandleOnStack assemblyName, ObjectHandleOnStack requestingAssembly, StackCrawlMarkHandle stackMark, Boolean throwOnFileNotFound, ObjectHandleOnStack assemblyLoadContext, ObjectHandleOnStack retAssembly)
at System.Reflection.RuntimeAssembly.InternalLoad(AssemblyName assemblyName, RuntimeAssembly requestingAssembly, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, AssemblyLoadContext assemblyLoadContext)
at System.Reflection.Assembly.Load(AssemblyName assemblyRef)
at RazorEngineCore.RazorEngineCompilationOptions..ctor()
at RazorEngineCore.RazorEngineCompilationOptionsBuilder..ctor(RazorEngineCompilationOptions options)
at RazorEngineCore.RazorEngine.Compile(String content, Action`1 builderAction)
If I do not use the "-p:PublicTrimmed=true" option, errors will not occur and work well. However, if I do not use the "-p:PublicTrimmed=true" option, the executable size will increase from 50MB to 80MB.
The "-p:PublicTrimmed=true" option causes an error that the Microsoft.CSharp assembly cannot be found.
The full command to publish executable is as follows:
"C:\Program Files\dotnet\dotnet.exe" publish -c Release -r win-x64 --self-contained true -p:PublishReadyToRun=false -p:PublishSingleFile=true -p:PublishTrimmed=true -p:IncludeNativeLibrariesForSelfExtract=true -o publish\release\win-x64
The error that occurs is as follows:
System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.CSharp, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.
File name: 'Microsoft.CSharp, Culture=neutral, PublicKeyToken=null' at System.Reflection.RuntimeAssembly.InternalLoad(ObjectHandleOnStack assemblyName, ObjectHandleOnStack requestingAssembly, StackCrawlMarkHandle stackMark, Boolean throwOnFileNotFound, ObjectHandleOnStack assemblyLoadContext, ObjectHandleOnStack retAssembly) at System.Reflection.RuntimeAssembly.InternalLoad(AssemblyName assemblyName, RuntimeAssembly requestingAssembly, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, AssemblyLoadContext assemblyLoadContext) at System.Reflection.Assembly.Load(AssemblyName assemblyRef) at RazorEngineCore.RazorEngineCompilationOptions..ctor() at RazorEngineCore.RazorEngineCompilationOptionsBuilder..ctor(RazorEngineCompilationOptions options) at RazorEngineCore.RazorEngine.Compile(String content, Action`1 builderAction)
If I do not use the "-p:PublicTrimmed=true" option, errors will not occur and work well. However, if I do not use the "-p:PublicTrimmed=true" option, the executable size will increase from 50MB to 80MB.