Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.NET 5 Trimmed Single File Crashes at Trim Stage #3158

Closed
thenadz opened this issue Nov 11, 2020 · 3 comments
Closed

.NET 5 Trimmed Single File Crashes at Trim Stage #3158

thenadz opened this issue Nov 11, 2020 · 3 comments

Comments

@thenadz
Copy link

thenadz commented Nov 11, 2020

Using NSwag version 13.9.0 with a .NET 5-based build pipeline, publishing a single file trimmed executable fails where it was successful with .NET Core 3.1. We're able to work around this issue by removing trimming for now.

Below is the command line invocation and relevant error output from the trim process:

> dotnet publish Project.csproj -c Release -r linux-x64 /p:PublishSingleFile=true /p:PublishTrimmed=true -o /app/publish
ILLink : error IL1005: NSwag.Generation.AspNetCore.AspNetCoreOpenApiDocumentGenerator.<>c__DisplayClass5_0.<GetJsonSerializerSettings>b__0(): Error processing method 'NSwag.Generation.AspNetCore.AspNetCoreOpenApiDocumentGenerator.<>c__DisplayClass5_0.<GetJsonSerializerSettings>b__0()' in assembly 'NSwag.Generation.AspNetCore.dll' [D:\Workspaces\Project.csproj]
  Mono.Linker.LinkerFatalErrorException: ILLink: error IL1005: NSwag.Generation.AspNetCore.AspNetCoreOpenApiDocumentGenerator.<>c__DisplayClass5_0.<GetJsonSerializerSettings>b__0(): Error processing method 'NSwag.Generation.AspNetCore.AspNetCoreOpenApiDocumentGenerator.<>c__DisplayClass5_0.<GetJsonSerializerSettings>b__0()' in assembly 'NSwag.Generation.AspNetCore.dll'
   ---> System.InvalidOperationException: Operation is not valid due to the current state of the object.
     at Mono.Linker.Dataflow.ReflectionMethodBodyScanner.GetValueNodeFromGenericArgument(TypeReference genericArgument)
     at Mono.Linker.Dataflow.ReflectionMethodBodyScanner.ProcessGenericArgumentDataFlow(GenericParameter genericParameter, TypeReference genericArgument, IMemberDefinition source)
     at Mono.Linker.Steps.MarkStep.MarkGenericArgumentConstructors(IGenericInstance instance, IMemberDefinition sourceLocationMember)
     at Mono.Linker.Steps.MarkStep.MarkGenericArguments(IGenericInstance instance, IMemberDefinition sourceLocationMember)
     at Mono.Linker.Steps.MarkStep.GetOriginalType(TypeReference type, DependencyInfo reason, IMemberDefinition sourceLocationMember)
     at Mono.Linker.Steps.MarkStep.MarkType(TypeReference reference, DependencyInfo reason, IMemberDefinition sourceLocationMember)
     at Mono.Linker.Steps.MarkStep.MarkTypeVisibleToReflection(TypeReference reference, DependencyInfo reason, IMemberDefinition sourceLocationMember)
     at Mono.Linker.Steps.MarkStep.MarkInstruction(Instruction instruction, MethodDefinition method, Boolean& requiresReflectionMethodBodyScanner)
     at Mono.Linker.Steps.MarkStep.MarkMethodBody(MethodBody body)
     at Mono.Linker.Steps.MarkStep.ProcessMethod(MethodDefinition method, DependencyInfo& reason)
     at Mono.Linker.Steps.MarkStep.ProcessQueue()
     --- End of inner exception stack trace ---
     at Mono.Linker.Steps.MarkStep.ProcessQueue()
     at Mono.Linker.Steps.MarkStep.ProcessPrimaryQueue()
     at Mono.Linker.Steps.MarkStep.Process()
     at Mono.Linker.Steps.MarkStep.Process(LinkContext context)
     at Mono.Linker.Pipeline.Process(LinkContext context)
     at Mono.Linker.Driver.Run(ILogger customLogger)
  Optimizing assemblies for size, which may change the behavior of the app. Be sure to test after publishing. See: https://aka.ms/dotnet-illink
C:\Program Files\dotnet\sdk\5.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.ILLink.targets(41,5): error NETSDK1144: Optimizing assemblies for size failed. Optimization can be disabled by setting the PublishTrimmed property to false. 
@RicoSuter
Copy link
Owner

RicoSuter commented Nov 11, 2020

Oh yeah, the fun starts 🙂
Any idea how to fix this?

@thenadz
Copy link
Author

thenadz commented Nov 11, 2020

@RicoSuter Doing some poking around, this appears to be related to known bug in linker (dotnet/linker#1559). This issue (dotnet/runtime#43222) notes some approaches for working around the linker bug.

@thenadz
Copy link
Author

thenadz commented Jan 4, 2022

dotnet/linker#1559 has since been resolved and confirmed the original NSwag issue reported no longer appears to be an issue. Closing.

@thenadz thenadz closed this as completed Jan 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants