-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Multiple RuntimeHostConfigurationOption for the same switch #28568
Comments
I filed this in dotnet/linker, but maybe this is a dotnet/sdk problem? |
@vitek-karas @sbomer what do you think? |
To me this looks like it falls out of the fact that the property feature switches take precedence over This happens because the It would technically be possible to fix this in the linker targets (by checking for existing items in I would argue that |
Another point is that some of the feature switch properties have other behaviors in addition to setting The supported way to turn back on features which are by default off in trimmed apps is to use the MSBuild properties. Using |
@dotnet/linker-contrib a new issue has been filed in the ILLink area, please triage |
Potentially the SDK could throw an error when we detect duplicate values for the runtime config but that would be a "breaking change". Leave it to do Daniel if he wants to make that change but it doesn't seem high priority to me. A better solution is to detect that the value is already set and not overwrite the value from what the customer set. |
@vitek-karas @sbomer moved this to the backlog (so lower priority). Please comment if you feel that we should try to solve this. Seems fairly niche. |
Software Versions
I'm using .NET 7 RC1 on macOS ARM64.
Overview
Let's use the switch
System.Threading.Thread.EnableAutoreleasePool
for an example.In the linker's Microsoft.NET.ILLink.targets file, it sets the property
AutoreleasePoolSupport
to true if it is not currently set. This will cause the SDK's Microsoft.NET.Sdk.targets file to create aRuntimeHostConfigurationOption
item forSystem.Threading.Thread.EnableAutoreleasePool
. If the user had already created their ownSystem.Threading.Thread.EnableAutoreleasePool
item for theSystem.Threading.Thread.EnableAutoreleasePool
switch, they will now have multipleRuntimeHostConfigurationOption
entries for the same switch. What finally ends up in the runtime config might not be what they expect.This problem applies to other properties the linker sets, not just
AutoreleasePoolSupport
.Reproduction Program
Use
dotnet new console
and then edit the csproj file to contain:Then run:
dotnet publish -r osx-arm64 --self-contained cat bin/Debug/net7.0/osx-arm64/publish/*.runtimeconfig.json
Expected
The
dotnet publish
command prints a single entry forSystem.Threading.Thread.EnableAutoreleasePool
and themytest.runtimeconfig.json
has the switch set totrue
.Actual
Dotnet publish output
Note that
System.Threading.Thread.EnableAutoreleasePool
appears multiple times, oncetrue
and oncefalse
.Runtime config file:
Note that
System.Threading.Thread.EnableAutoreleasePool
is false, despite what our project file specified.Workaround
Use the
AutoreleasePoolSupport
property instead of theRuntimeHostConfigurationOption
item.Possible fixes
Perhaps the
Microsoft.NET.ILLink.targets
file should also check if the user has set aRuntimeHostConfigurationOption
for the switch before setting theAutoreleasePoolSupport
property.Another possibility is the SDK's targets should check for existing
RuntimeHostConfigurationOption
item before setting it second time.Or perhaps something should check for duplicate
RuntimeHostConfigurationOption
entries for the same switch.For what it's worth, NativeAOT's ILC exits with a failure message when it see the same app context switch multiple times.
The text was updated successfully, but these errors were encountered: