Skip to content

CSharpCompilation.Assembly doesn't honor retargetable assembly flag #54836

@safern

Description

@safern

Version Used: Microsoft.CodeAnalysis package version: 4.0.0-2.21362.3

Steps to Reproduce:

Given the following test code:

[Fact]
public void AssemblyIsRetargetable()
{
    string syntax = @"
using System.Reflection;

[assembly: AssemblyFlags(AssemblyNameFlags.Retargetable)]
";

    CSharpCompilationOptions options = new(OutputKind.DynamicallyLinkedLibrary);
    IEnumerable<MetadataReference> defaultReferences = new[]
    {
        MetadataReference.CreateFromFile(typeof(object).Assembly.Location),
    };

    CSharpCompilation compilation = CSharpCompilation.Create(
                                        "foo",
                                        new[] { CSharpSyntaxTree.ParseText(syntax) },
                                        defaultReferences,
                                        options);

    Assert.Empty(compilation.GetDiagnostics());

    IAssemblySymbol assembly = compilation.Assembly;

    Assert.True(assembly.Identity.IsRetargetable);
}

Expected Behavior:
The test passes.

Actual Behavior:
Test fails at line Assert.True(assembly.Identity.IsRetargetable).

 Message: 
    Assert.True() Failure
    Expected: True
    Actual:   False

Note that if I get the assembly custom attributes the attribute is present. Also if I emit the assembly and then load it from it's file path, it sets the flag to true as expected.

cc: @jmarolf

Metadata

Metadata

Assignees

Labels

Area-CompilersBugResolution-FixedThe bug has been fixed and/or the requested behavior has been implemented

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions