Skip to content
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

[FEATURE REQ] Resolve Native AOT Warnings in Microsoft.Azure.Cosmos #4458

Open
eerhardt opened this issue Apr 26, 2024 · 0 comments
Open

[FEATURE REQ] Resolve Native AOT Warnings in Microsoft.Azure.Cosmos #4458

eerhardt opened this issue Apr 26, 2024 · 0 comments
Labels
customer-reported Issue created by a customer needs-investigation

Comments

@eerhardt
Copy link
Member

Is your feature request related to a problem? Please describe.
I would like to use Microsoft.Azure.Cosmos in a native AOT'd application. However, it is not currently possible.

Describe the solution you'd like
Make Microsoft.Azure.Cosmos compatible with native AOT. See https://devblogs.microsoft.com/dotnet/creating-aot-compatible-libraries/ for instructions/tips for how to do this. We should drive the warnings to 0.

Describe alternatives you've considered
N/A

Additional context
When I publish an app that has the following code:

            var cosmosClient = _serviceProvider.GetRequiredService<CosmosClient>();

            var db = (await cosmosClient.CreateDatabaseIfNotExistsAsync("db")).Database;
            var container = (await db.CreateContainerIfNotExistsAsync("entries", "/Id")).Container;

            var newEntry = new ToDoActivity() { id = Guid.NewGuid().ToString(), status = message };
            await container.CreateItemAsync(newEntry);

I get the following warnings:

C:\Users\eerhardt\.nuget\packages\microsoft.azure.cosmos\3.38.1\lib\netstandard2.0\Microsoft.Azure.Cosmos.Client.dll : warning IL2104: Assembly 'Microsoft.Azure.Cosmos.Client' produced trim warnings. For more information see https://aka.ms/dotnet-illink/libraries [C:\Users\eerhardt\source\repos\AspireApp15\AspireApp15.ApiService\AspireApp15.ApiService.csproj]
ILC : warning IL3000: Microsoft.Azure.Documents.ServiceInteropWrapper.CheckIfAssembliesExist(String&): 'System.Reflection.Assembly.Location.get' always returns an empty string for assemblies embedded in a single-file app. If the path to the app directory is needed, consider calling 'System.AppContext.BaseDirectory'. [C:\Users\eerhardt\source\repos\AspireApp15\AspireApp15.ApiService\AspireApp15.ApiService.csproj]
ILC : warning IL3000: Microsoft.Azure.Documents.ServiceInteropWrapper.CheckIfAssembliesExist(String&): 'System.Reflection.Assembly.Location.get' always returns an empty string for assemblies embedded in a single-file app. If the path to the app directory is needed, consider calling 'System.AppContext.BaseDirectory'. [C:\Users\eerhardt\source\repos\AspireApp15\AspireApp15.ApiService\AspireApp15.ApiService.csproj]
C:\Users\eerhardt\.nuget\packages\system.configuration.configurationmanager\6.0.0\lib\net6.0\System.Configuration.ConfigurationManager.dll : warningIL2104: Assembly 'System.Configuration.ConfigurationManager' produced trim warnings. For more information see https://aka.ms/dotnet-illink/libraries[C:\Users\eerhardt\source\repos\AspireApp15\AspireApp15.ApiService\AspireApp15.ApiService.csproj]
C:\Users\eerhardt\.nuget\packages\newtonsoft.json\10.0.2\lib\netstandard1.3\Newtonsoft.Json.dll : warning IL2104: Assembly 'Newtonsoft.Json' produced trim warnings. For more information see https://aka.ms/dotnet-illink/libraries [C:\Users\eerhardt\source\repos\AspireApp15\AspireApp15.ApiService\AspireApp15.ApiService.csproj]
C:\Users\eerhardt\.nuget\packages\newtonsoft.json\10.0.2\lib\netstandard1.3\Newtonsoft.Json.dll : warning IL3053: Assembly 'Newtonsoft.Json' produced AOT analysis warnings. [C:\Users\eerhardt\source\repos\AspireApp15\AspireApp15.ApiService\AspireApp15.ApiService.csproj]
C:\Users\eerhardt\.nuget\packages\runtime.win-x64.microsoft.dotnet.ilcompiler\8.0.2\framework\System.Linq.Expressions.dll : warning IL3053: Assembly'System.Linq.Expressions' produced AOT analysis warnings. [C:\Users\eerhardt\source\repos\AspireApp15\AspireApp15.ApiService\AspireApp15.ApiService.csproj]
C:\Users\eerhardt\.nuget\packages\runtime.win-x64.microsoft.dotnet.ilcompiler\8.0.2\framework\Microsoft.CSharp.dll : warning IL3053: Assembly 'Microsoft.CSharp' produced AOT analysis warnings. [C:\Users\eerhardt\source\repos\AspireApp15\AspireApp15.ApiService\AspireApp15.ApiService.csproj]
C:\Users\eerhardt\.nuget\packages\microsoft.azure.cosmos\3.38.1\lib\netstandard2.0\Microsoft.Azure.Cosmos.Direct.dll : warning IL2104: Assembly 'Microsoft.Azure.Cosmos.Direct' produced trim warnings. For more information see https://aka.ms/dotnet-illink/libraries [C:\Users\eerhardt\source\repos\AspireApp15\AspireApp15.ApiService\AspireApp15.ApiService.csproj]
C:\Users\eerhardt\.nuget\packages\microsoft.azure.cosmos\3.38.1\lib\netstandard2.0\Microsoft.Azure.Cosmos.Direct.dll : warning IL3053: Assembly 'Microsoft.Azure.Cosmos.Direct' produced AOT analysis warnings. [C:\Users\eerhardt\source\repos\AspireApp15\AspireApp15.ApiService\AspireApp15.ApiService.csproj]

When I try to run the produced executable the first error I hit is:

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.Configuration.ConfigurationManager.get_AppSettings() + 0x11
   at Microsoft.Azure.Cosmos.DocumentClient.Initialize(Uri, ConnectionPolicy, Nullable`1, HttpMessageHandler, ISessionContainer, Nullable`1, IStoreClientFactory, TokenCredential, String, RemoteCertificateValidationCallback, CosmosClientTelemetryOptions) + 0x1bd
   at Microsoft.Azure.Cosmos.DocumentClient..ctor(Uri, AuthorizationTokenProvider, EventHandler`1, ConnectionPolicy, Nullable`1, JsonSerializerSettings, ApiType, EventHandler`1, HttpMessageHandler, ISessionContainer, Nullable`1, Func`2, IStoreClientFactory, Boolean, String, RemoteCertificateValidationCallback, CosmosClientTelemetryOptions, IChaosInterceptorFactory) + 0x1fd
   at Microsoft.Azure.Cosmos.ClientContextCore.Create(CosmosClient, CosmosClientOptions) + 0x1bd
   at Microsoft.Azure.Cosmos.CosmosClient..ctor(String, AuthorizationTokenProvider, CosmosClientOptions) + 0x10e
   at Microsoft.Extensions.Hosting.AspireMicrosoftAzureCosmosDBExtensions.<>c__DisplayClass3_0.<AddAzureCosmosDB>g__ConfigureDb|3() + 0xc3

Note that Newtonsoft.Json is not currently AOT compatible (and looks likely it will never be). See JamesNK/Newtonsoft.Json#2732. The only JSON object serialization and deserialization that works with native AOT is the System.Text.Json source generator. Or else you need to use the reader/writer APIs or JsonDocument/JsonNode APIs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
customer-reported Issue created by a customer needs-investigation
Projects
None yet
Development

No branches or pull requests

1 participant