Skip to content
This repository was archived by the owner on Sep 25, 2026. It is now read-only.
This repository was archived by the owner on Sep 25, 2026. It is now read-only.

Crash in linker building with .NET 6 RC1 #2274

Closed

Description

@slluis

Building VSMac with .NET 6 RC1 I get this error:

ILLink : error IL1012: IL Linker has encountered an unexpected error. Please report the issue at https://github.com/mono/linker/issues [/Users/lluis/prog/work/vsmac/test/main/src/tools/vstool/vstool.csproj]
  Fatal error in IL Linker
  Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.
     at Mono.Linker.CustomAttributeSource.HasAny(ICustomAttributeProvider provider)
     at Mono.Linker.AnnotationStore.GetLinkerAttributes[T](IMemberDefinition member)
     at Mono.Linker.AnnotationStore.TryGetLinkerAttribute[T](IMemberDefinition member, T& attribute)
     at Mono.Linker.Steps.MarkStep.MarkType(TypeReference reference, DependencyInfo reason, Nullable`1 origin)
     at Mono.Linker.Steps.MarkStep.MarkField(FieldDefinition field, DependencyInfo& reason)
     at Mono.Linker.Steps.MarkStep.MarkEntireType(TypeDefinition type, DependencyInfo& reason)
     at Mono.Linker.Steps.MarkStep.MarkEntireAssembly(AssemblyDefinition assembly)
     at Mono.Linker.Steps.MarkStep.MarkAssembly(AssemblyDefinition assembly, DependencyInfo reason)
     at Mono.Linker.Steps.MarkStep.ProcessMarkedPending()
     at Mono.Linker.Steps.MarkStep.Initialize()
     at Mono.Linker.Steps.MarkStep.Process(LinkContext context)
     at Mono.Linker.Pipeline.ProcessStep(LinkContext context, IStep step)
     at Mono.Linker.Pipeline.Process(LinkContext context)
     at Mono.Linker.Driver.Run(ILogger customLogger)
     at Mono.Linker.Driver.Main(String[] args)
  Optimizing assemblies for size, which may change the behavior of the app. Be sure to test after publishing. See: https://aka.ms/dotnet-illink
/usr/local/share/dotnet/sdk/6.0.100-rc.1.21458.32/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.ILLink.targets(108,5): error NETSDK1144: Optimizing assemblies for size failed. Optimization can be disabled by setting the PublishTrimmed property to false. [/Users/lluis/prog/work/vsmac/test/main/src/tools/vstool/vstool.csproj]

The dotnet version is 6.0.100-rc.1.21458.32

Activity

  1. marek-safar commented on Sep 15, 2021

    @marek-safar
    Contributor
  2. added this to the .NET 6.0 milestone on Sep 15, 2021
  3. sbomer commented on Sep 15, 2021

    @sbomer
    Member

    By inspection I think this could be caused by an unresolved base type here:

    _context.Annotations.TryGetLinkerAttribute (_context.TryResolve (type.BaseType), out RequiresUnreferencedCodeAttribute effectiveRequiresUnreferencedCode)) {

    Turning on nullable annotations for Annotations.cs will probably catch this issue too.

  4. sbomer commented on Sep 16, 2021

    @sbomer
    Member

    @slluis are you able to share a repro? We think we know the issue but would like to be able to validate that it actually fixes the exception in your scenario.

  5. agocke commented on Sep 16, 2021

    @agocke
    Member

    @tlakollo Can you turn on nullable here and confirm that we get a warning, and then fix the bug?

  6. tlakollo commented on Sep 16, 2021

    @tlakollo
    Contributor

    So the warning is actually in the TryResolve call, which can return null. TryGetLinkerAttribute assumes that the provider is not null, we never check for it and end up using the null member to get its attributes.
    We have two options:

    • Return an empty list of attributes as soon as we see the provider is null
    • Fail inside TryGetLinkerAttribute if it sees a null provider, and in MarkStep only get the attributes if the TryResolve was not null

    I think I don't have a strong preference on either of those, and I will try to enable nullable on Annotations.cs as part of the PR

  7. sbomer commented on Sep 16, 2021

    @sbomer
    Member

    I would suggest fixing it in the caller in MarkStep and annotating the input to TryGetLinkerAttribute as non-nullable. Once everything is annotated this should ensure it never gets a null input. I personally wouldn't add any null check inside TryGetLinkerAttribute.

  8. added a commit that references this issue on Sep 17, 2021
    4ea3d7b
  9. slluis commented on Sep 17, 2021

    @slluis
    Author

    I verified the fix work using a local copy of the fixed linker 👍

  10. added a commit that references this issue on Sep 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions