Skip to content

"Optimizing assemblies for size failed" - Core 9 Preview 6 Maui Mac Catalyst Build #104945

Closed

Description

@cbdg-mitch

Description

I am trying to build for mac catalyst - this seemed to work in Preview 4 with the same command line, but what I did for that was to clear old preview SDK's out and that fixed it - where as here, all I have is core 8 final and 9 preview 6.

ILLink : error IL1011: Failed to write 'obj/Release/net9.0-maccatalyst/maccatalyst-x64/linked/System.Private.CoreLib.dll'.
/Users/mitch/.nuget/packages/microsoft.net.illink.tasks/9.0.0-preview.6.24327.7/build/Microsoft.NET.ILLink.targets(95,5): error NETSDK1144: Optimizing assemblies for size failed.
AbMobileMaui net9.0-maccatalyst failed with 16 warning(s) (3.8s)

Steps to Reproduce

I am using this command line:
dotnet publish -f net9.0-maccatalyst -c Release
-p:ArchiveOnBuild=true
-p:CreatePackage=true
-p:EnableCodeSigning=true
-p:CodesignKey="Apple Distribution: AlzBetter LLC (8DVSMQ7G8N)"
-p:CodesignProvision="MacOS Distribution"
-p:CodesignEntitlements="Platforms/MacCatalyst/Entitlements.plist"
-p:UseHardenedRuntime=true

And here's my CSProj - I could be way off base on how I have things configured, so please feel free to tell me what I might have set up wrong here.

Edit: Attaching CSProj as a file due to formatting.

Link to public reproduction project repository

No response

Version with bug

9.0.0-preview.6.24327.7

Is this a regression from previous behavior?

Yes, this used to work in .NET MAUI

Last version that worked well

9.0.0-preview.4.10690

Affected platforms

macOS

Affected platform versions

No response

Did you find any workaround?

No response

Relevant log output

No response

Activity

  1. github-actions commented on Jul 15, 2024

    @github-actions
    Contributor

    Hi I'm an AI powered bot that finds similar issues based off the issue title.

    Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!

    Open similar issues:

    Closed similar issues:

    Note: You can give me feedback by thumbs upping or thumbs downing this comment.

  2. cbdg-mitch commented on Jul 15, 2024

    @cbdg-mitch
    Author
  3. cbdg-mitch commented on Jul 15, 2024

    @cbdg-mitch
    Author
  4. vitek-karas commented on Jul 15, 2024

    @vitek-karas
    Member

    @sbomer - for ideas on why this fails (maybe we should print out the full exception in this case?)

  5. sbomer commented on Jul 15, 2024

    @sbomer
    Member

    The binlog shows a stacktrace:

    Fatal error in IL Linker
    Unhandled exception. Mono.Linker.LinkerFatalErrorException: ILLink: error IL1011: Failed to write 'obj/Release/net9.0-maccatalyst/maccatalyst-x64/linked/System.Private.CoreLib.dll'.
     ---> System.ArgumentException: Member 'System.Boolean get_IsDynamicCodeSupported()' is declared in another module and needs to be imported
       at Mono.Cecil.MetadataBuilder.LookupToken(IMetadataTokenProvider provider)
       at Mono.Cecil.Cil.CodeWriter.WriteOperand(Instruction instruction)
       at Mono.Cecil.Cil.CodeWriter.WriteInstructions()
       at Mono.Cecil.Cil.CodeWriter.WriteResolvedMethodBody(MethodDefinition method)
       at Mono.Cecil.Cil.CodeWriter.WriteMethodBody(MethodDefinition method)
       at Mono.Cecil.MetadataBuilder.AddMethod(MethodDefinition method)
       at Mono.Cecil.MetadataBuilder.AddMethods(TypeDefinition type)
       at Mono.Cecil.MetadataBuilder.AddType(TypeDefinition type)
       at Mono.Cecil.MetadataBuilder.AddTypes()
       at Mono.Cecil.MetadataBuilder.BuildTypes()
       at Mono.Cecil.MetadataBuilder.BuildModule()
       at Mono.Cecil.MetadataBuilder.BuildMetadata()
       at Mono.Cecil.ModuleWriter.<>c.<BuildMetadata>b__2_0(MetadataBuilder builder, MetadataReader _)
       at Mono.Cecil.ModuleDefinition.Read[TItem,TRet](TItem item, Func`3 read)
       at Mono.Cecil.ModuleWriter.BuildMetadata(ModuleDefinition module, MetadataBuilder metadata)
       at Mono.Cecil.ModuleWriter.Write(ModuleDefinition module, Disposable`1 stream, WriterParameters parameters)
       at Mono.Cecil.ModuleWriter.WriteModule(ModuleDefinition module, Disposable`1 stream, WriterParameters parameters)
       at Mono.Cecil.ModuleDefinition.Write(String fileName, WriterParameters parameters)
       at Mono.Cecil.AssemblyDefinition.Write(String fileName, WriterParameters parameters)
       at Mono.Linker.Steps.OutputStep.WriteAssembly(AssemblyDefinition assembly, String directory, WriterParameters writerParameters)
       --- End of inner exception stack trace ---
       at Mono.Linker.Steps.OutputStep.WriteAssembly(AssemblyDefinition assembly, String directory, WriterParameters writerParameters)
       at Mono.Linker.Steps.OutputStep.WriteAssembly(AssemblyDefinition assembly, String directory)
       at Mono.Linker.Steps.OutputStep.OutputAssembly(AssemblyDefinition assembly)
       at Mono.Linker.Steps.OutputStep.ProcessAssembly(AssemblyDefinition assembly)
       at Mono.Linker.Steps.BaseStep.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)
       at Mono.Linker.Driver.Main(String[] args)
    The command exited with code 134.
    

    The failure mode looks potentially related to missing references, similar to #93797, but I'll need a repro. I haven't had any success creating a maui app today. @vitek-karas any chance your repro tool would be able to help get us a repro for this?

  6. cbdg-mitch commented on Jul 16, 2024

    @cbdg-mitch
    Author

    @sbomer it feels like the same issue, but really I have very few packages referenced.

    <PackageReference Include="Microsoft.Extensions.Http" Version="9.0.0-preview.6.24327.7" />
    		<PackageReference Include="Microsoft.Maui.Controls" Version="9.0.0-preview.6.24327.7" />
    		<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="9.0.0-preview.6.24327.7" />
    		<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="9.0.0-preview.6.24327.7" />
            <PackageReference Include="Plugin.Maui.Audio" Version="3.0.0" />
            <PackageReference Include="Blazored.FluentValidation" Version="2.2.0" />
            <PackageReference Include="FluentEmail.Mailgun" Version="3.0.2" />
            <PackageReference Include="Twilio" Version="7.2.2" />
    		<PackageReference Include="Microsoft.AspNetCore.Components.WebView.Maui" Version="9.0.0-preview.6.24327.7" />
    

    I feel like this error is super obscure especially since it doesn't tell me what packages are causing the problem - get_IsDynamicCodeSupported could be used in any given package probably, right? Is there anything in the CSProj I can change to bypass this check?

  7. cbdg-mitch commented on Jul 16, 2024

    @cbdg-mitch
    Author

    @sbomer I figured it out - I hope this helps you.

    I was referencing Twilio:
    <PackageReference Include="Twilio" Version="7.2.2" />

    but when I was trying to narrow down what 3rd party package was causing the problem and commented it out, my app started complaining that System.IdentityModel.Tokens.Jwt couldn't be found (I use JWT for log in the app) - so it seems System.IdentityModel.Tokens.Jwt was being pulled from a reference that Twilio's nuget had.

    <PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="7.6.3" />

    So I added this reference too, and now the app builds fine.

    I guess I feel like the error should be pretty verbose in somehow telling me like, hey, you're referencing System.IdentityModel.Tokens.Jwt, but not directly, so that's not cool, bro - instead of this super obscure error.

    LMK what you think :)

    Mitch

  8. transferred this issue fromdotnet/mauion Jul 16, 2024
  9. ghost added
    needs-area-label
    on Jul 16, 2024
  10. added
    untriaged
    on Jul 16, 2024
  11. added
    area-Tools-ILLink
    on Jul 16, 2024
  12. removed
    needs-area-label
    on Jul 16, 2024
  13. dotnet-policy-service commented on Jul 16, 2024

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @agocke, @sbomer, @vitek-karas
    See info in area-owners.md if you want to be subscribed.

  14. sbomer commented on Jul 16, 2024

    @sbomer
    Member

    @caliberdigitalllc thanks for the additional notes. After experimenting a little more with maui and your csproj I was able to get a repro. The error is definitely not by design - the fix should either allow the app to be trimmed even with the missing reference, or produce a better error. I'll investigate and report back soon.

  15. added this to the 9.0.0 milestone on Jul 16, 2024
  16. removed
    untriaged
    on Jul 16, 2024
  17. sbomer commented on Jul 16, 2024

    @sbomer
    Member

    Turns out this wasn't really about the missing reference. It just so happened that updating to a later version of that reference got rid of a call to IsDynamicCodeCompiled that was causing the problem.

    This was caused by a bug in the interaction between AggressiveAttributeTrimming, FeatureGuardAttribute, and IL rewriting for constant properties. #104995 has a fix, but we should consider disabling AggressiveAttributeTrimming in maui because that feature isn't really supported. See #88805.

    It's possible to work around this by setting:

    <_AggressiveAttributeTrimming>false</_AggressiveAttributeTrimming>
  18. self-assigned this
    on Jul 16, 2024
  19. cbdg-mitch commented on Jul 18, 2024

    @cbdg-mitch
    Author

    @sbomer thank you for addressing this :)

  20. locked and limited conversation to collaborators on Aug 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-Tools-ILLink

Type

No type

Projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions