You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
"Optimizing assemblies for size failed" - Core 9 Preview 6 Maui Mac Catalyst Build #104945
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.
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!
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?
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?
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.
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.
@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.
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.
Activity
github-actions commentedon Jul 15, 2024
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:
cbdg-mitch commentedon Jul 15, 2024
AbMobileMaui-csproj.txt
PureWeen commentedon Jul 15, 2024
Can you create and attach a binlog please?
https://github.com/dotnet/maui/wiki/Capturing-Binary-Logs
cbdg-mitch commentedon Jul 15, 2024
msbuild.binlog.zip
@PureWeen attached :)
vitek-karas commentedon Jul 15, 2024
@sbomer - for ideas on why this fails (maybe we should print out the full exception in this case?)
sbomer commentedon Jul 15, 2024
The binlog shows a stacktrace:
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?
cbdg-mitch commentedon Jul 16, 2024
@sbomer it feels like the same issue, but really I have very few packages referenced.
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?
cbdg-mitch commentedon Jul 16, 2024
@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
dotnet-policy-service commentedon Jul 16, 2024
Tagging subscribers to this area: @agocke, @sbomer, @vitek-karas
See info in area-owners.md if you want to be subscribed.
sbomer commentedon Jul 16, 2024
@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.
sbomer commentedon Jul 16, 2024
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:
cbdg-mitch commentedon Jul 18, 2024
@sbomer thank you for addressing this :)
Fix feature switch IL when feature attributes are removed (dotnet#104995