Skip to content

System.Runtime.Caching is not AOT compatible and isn't annotated #102341

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

Open
eerhardt opened this issue May 16, 2024 · 8 comments
Open

System.Runtime.Caching is not AOT compatible and isn't annotated #102341

eerhardt opened this issue May 16, 2024 · 8 comments

Comments

@eerhardt
Copy link
Member

Using the following project:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net8.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <PublishAot>true</PublishAot>
    <InvariantGlobalization>true</InvariantGlobalization>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="System.Runtime.Caching" Version="8.0.0" />
  </ItemGroup>
</Project>
using System.Runtime.Caching;

MemoryCache memoryCache = new MemoryCache("MyCache");

memoryCache.Add("key", "value", DateTime.UtcNow.AddMinutes(1440.0));

Console.WriteLine(memoryCache.Get("key"));

When you dotnet build you don't get any warnings that MemoryCache isn't going to work in a trimmed or AOT'd application.

However, when you dotnet publish the project, you do get a warning:

.nuget\packages\system.configuration.configurationmanager\8.0.0\lib\net8.0\System.Configuration.ConfigurationManager.dll : warning IL2104: Assembly 'System.Configuration.ConfigurationManager' produced trim warnings. For more information see https://aka.ms/dotnet-illink/libraries [C:\Users\eerhardt\source\repos\ConsoleApp123\ConsoleApp123\ConsoleApp123.csproj]

Then when you run the resulting .exe it fails with:

Unhandled Exception: System.Configuration.ConfigurationErrorsException: Configuration system failed to initialize
 ---> System.MissingMethodException: No parameterless constructor defined for type 'System.Configuration.ClientConfigurationHost'.
   at System.ActivatorImplementation.CreateInstance(Type, Boolean) + 0x119
   at System.Configuration.Internal.ConfigSystem.System.Configuration.Internal.IConfigSystem.Init(Type, Object[]) + 0x43
   at System.Configuration.ClientConfigurationSystem..ctor() + 0x47
   at System.Configuration.ConfigurationManager.EnsureConfigurationSystem() + 0x56
   --- End of inner exception stack trace ---
   at System.Configuration.ConfigurationManager.EnsureConfigurationSystem() + 0xea
   at System.Configuration.ConfigurationManager.PrepareConfigSystem() + 0x12
   at System.Configuration.ConfigurationManager.GetSection(String) + 0x18
   at System.Runtime.Caching.MemoryCacheStatistics.InitializeConfiguration(NameValueCollection) + 0x2c
   at System.Runtime.Caching.MemoryCacheStatistics..ctor(MemoryCache, NameValueCollection) + 0x4a
   at System.Runtime.Caching.MemoryCache.InitDisposableMembers(NameValueCollection) + 0xf1
   at Program.<Main>$(String[] args) + 0x26
   at ConsoleApp123!<BaseAddress>+0x3dc723

We should either make System.Runtime.Caching work with trimming/native AOT, or annotate it as incompatible with trimming.

This is related to #75480, but I didn't see System.Runtime.Caching in the list on that issue.

cc @agocke @LakshanF @MichalStrehovsky

@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label May 16, 2024
@MichalStrehovsky
Copy link
Member

This looks like a trimming issue, not AOT issue.

The exception is in ConfigurationManager. Looks like we didn't annotate it as such, and closed the underlying issue as by design :(.

<!-- opt-out of trimming until it works https://github.com/dotnet/runtime/issues/49062 -->
<IsTrimmable>false</IsTrimmable>
<EnableAOTAnalyzer>false</EnableAOTAnalyzer>

@stephentoub
Copy link
Member

@eerhardt, is this something that needs to be addressed in .NET 9?

@stephentoub stephentoub added this to the 9.0.0 milestone Jul 22, 2024
@eerhardt
Copy link
Member Author

@eerhardt, is this something that needs to be addressed in .NET 9?

No, it doesn't "need" to be addressed in .NET 9. The benefit of doing this work is that consumers using System.Runtime.Caching in trimmed/AOT apps/libraries would get warnings sooner in their development process - i.e. during "build", instead of at the end when they publish the app.

@stephentoub
Copy link
Member

Thanks. As #75480 is now in the 10.0 milestone, I'm moving this to the 10.0 milestone as well. If this is in the same camp as the other items in that issue, should this instead be closed and a line item added to that one?

@stephentoub stephentoub modified the milestones: 9.0.0, 10.0.0 Jul 23, 2024
@MichalStrehovsky
Copy link
Member

Thanks. As #75480 is now in the 10.0 milestone, I'm moving this to the 10.0 milestone as well. If this is in the same camp as the other items in that issue, should this instead be closed and a line item added to that one?

This one was presumably actually hit by someone. #75480 is tracking leftover work that nobody ran into yet and we're likely going to kick from one milestone to another for years to come, unless the work gets funded. This one feels higher priority than that.

@eerhardt
Copy link
Member Author

This one was presumably actually hit by someone.

Correct. This was hit by a team in Microsoft using native AOT.

@stephentoub
Copy link
Member

@steveharter

@dotnet-policy-service dotnet-policy-service bot removed the untriaged New issue has not been triaged by the area owner label Jul 24, 2024
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-configuration
See info in area-owners.md if you want to be subscribed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants