Skip to content

Support for AOT compilation #501

Open

Description

@jackmtpt

Currently this library does not support AOT compilation. You get the following error: PlatformNotSupportedException: Dynamic code generation is not supported on this platform.

We are building a small application that needs to query data from Dynamics and would ideally like to build it with AOT, but this is currently not possible.

Activity

  1. MattB-msft commented on Mar 31, 2025

    @MattB-msft
    Member

    This is an interesting.

    We have requests for this in the past but have not really invested in looking into this.. it "Should work"... from your message, your seeing this on compile?

  2. jackmtpt commented on Apr 1, 2025

    @jackmtpt
    Author

    On compile a whole bunch of warnings are generated, and the resulting binary crashes on start.

    Crash stack:

    Unhandled exception. System.NotSupportedException: 'Microsoft.Extensions.Options.OptionsManager`1[Microsoft.PowerPlatform.Dataverse.Client.Model.ConfigurationOptions]' is missing native code or metadata. This can happen for code that is not compatible with trimming or AOT. Inspect and fix trimming and AOT related warnings that were generated when the app was published. For more information see https://aka.ms/nativeaot-compatibility
       at System.Reflection.Runtime.General.TypeUnifier.WithVerifiedTypeHandle(RuntimeConstructedGenericTypeInfo, RuntimeTypeInfo[]) + 0x7e
       at System.Reflection.Runtime.TypeInfos.RuntimeTypeInfo.MakeGenericType(Type[]) + 0x207
       at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.TryCreateOpenGeneric(ServiceDescriptor, Type, CallSiteChain, Int32) + 0x95
       at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.TryCreateOpenGeneric(Type, CallSiteChain) + 0xad
       at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateCallSite(Type, CallSiteChain) + 0x53
       at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey, Func`2) + 0xa4
       at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.CreateServiceAccessor(Type serviceType) + 0x5b
       at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey, Func`2) + 0xa4
       at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.GetService(Type, ServiceProviderEngineScope) + 0x2e
       at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetService[T](IServiceProvider) + 0x2e
       at Microsoft.PowerPlatform.Dataverse.Client.ServiceClient..ctor(Uri, String, String, Boolean, ILogger) + 0x40
       at aot.test.Program.DynamicsTest() + 0x67
       at aot.test.Program.Main(String[] args) + 0x15
    

    Compiler warnings:

    > dotnet publish
    Restore complete (0.4s)
      aot.test succeeded with 36 warning(s) (38.3s) → bin\Release\net9.0\win-x64\publish\
        c:\users\me\.nuget\packages\microsoft.powerplatform.dataverse.client\1.1.32\lib\net6.0\Microsoft.PowerPlatform.Dataverse.Client.dll : warning IL2104: Assembly 'Microsoft.PowerPlatform.Dataverse.Client' produced trim warnings. For more information see https://aka.ms/il2104
        ILC : warning IL3000: Microsoft.PowerPlatform.Dataverse.Client.Environs..cctor(): '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'.
        ILC : warning IL3000: Microsoft.PowerPlatform.Dataverse.Client.Environs..cctor(): '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\me\.nuget\packages\microsoft.powerplatform.dataverse.client\1.1.32\lib\net6.0\Microsoft.Xrm.Sdk.dll : warning IL2104: Assembly 'Microsoft.Xrm.Sdk' produced trim warnings. For more information see https://aka.ms/il2104
        c:\users\me\.nuget\packages\microsoft.powerplatform.dataverse.client\1.1.32\lib\net6.0\Microsoft.Xrm.Sdk.dll : warning IL3053: Assembly 'Microsoft.Xrm.Sdk' produced AOT analysis warnings.
        c:\users\me\.nuget\packages\system.servicemodel.primitives\6.2.0\lib\net6.0\System.ServiceModel.Primitives.dll : warning IL2104: Assembly 'System.ServiceModel.Primitives' produced trim warnings. For more information see https://aka.ms/il2104
        c:\users\me\.nuget\packages\microsoft.extensions.dependencyinjection\3.1.8\lib\netcoreapp3.1\Microsoft.Extensions.DependencyInjection.dll : warning IL3053: Assembly 'Microsoft.Extensions.DependencyInjection' produced AOT analysis warnings.
        c:\users\me\.nuget\packages\system.configuration.configurationmanager\6.0.0\lib\net6.0\System.Configuration.ConfigurationManager.dll : warning IL2104: Assembly 'System.Configuration.ConfigurationManager' produced trim warnings. For more information see https://aka.ms/il2104
        c:\users\me\.nuget\packages\microsoft.extensions.dependencyinjection\3.1.8\lib\netcoreapp3.1\Microsoft.Extensions.DependencyInjection.dll : warning IL2104: Assembly 'Microsoft.Extensions.DependencyInjection' produced trim warnings. For more information see https://aka.ms/il2104
        c:\users\me\.nuget\packages\microsoft.extensions.logging\3.1.8\lib\netcoreapp3.1\Microsoft.Extensions.Logging.dll : warning IL2104: Assembly 'Microsoft.Extensions.Logging' produced trim warnings. For more information see https://aka.ms/il2104
        c:\users\me\.nuget\packages\newtonsoft.json\13.0.1\lib\netstandard2.0\Newtonsoft.Json.dll : warning IL2104: Assembly 'Newtonsoft.Json' produced trim warnings. For more information see https://aka.ms/il2104
        c:\users\me\.nuget\packages\microsoft.powerplatform.dataverse.client\1.1.32\lib\net6.0\Microsoft.PowerPlatform.Dataverse.Client.dll : warning IL3053: Assembly 'Microsoft.PowerPlatform.Dataverse.Client' produced AOT analysis warnings.
        c:\users\me\.nuget\packages\runtime.win-x64.microsoft.dotnet.ilcompiler\9.0.3\framework\Microsoft.CSharp.dll : warning IL3053: Assembly 'Microsoft.CSharp' produced AOT analysis warnings.
        c:\users\me\.nuget\packages\newtonsoft.json\13.0.1\lib\netstandard2.0\Newtonsoft.Json.dll : warning IL3053: Assembly 'Newtonsoft.Json' produced AOT analysis warnings.
        c:\users\me\.nuget\packages\system.servicemodel.primitives\6.2.0\lib\net6.0\System.ServiceModel.Primitives.dll : warning IL3053: Assembly 'System.ServiceModel.Primitives' produced AOT analysis warnings.
        c:\users\me\.nuget\packages\runtime.win-x64.microsoft.dotnet.ilcompiler\9.0.3\framework\System.Linq.Expressions.dll : warning IL3053: Assembly 'System.Linq.Expressions' produced AOT analysis warnings.
        c:\users\me\.nuget\packages\runtime.win-x64.microsoft.dotnet.ilcompiler\9.0.3\framework\System.Reflection.DispatchProxy.dll : warning IL3053: Assembly 'System.Reflection.DispatchProxy' produced AOT analysis warnings.
        ILC : warning IL3002: Microsoft.Xrm.Sdk.WebServiceClient.WebProxyClient`1.GetXrmSdkAssemblyFileVersion(): Using member 'System.Reflection.Module.Name.get' which has 'RequiresAssemblyFilesAttribute' can break functionality when embedded in a single-file app. Returns <Unknown> for modules with no file path.
        ILC : warning IL3000: Microsoft.Xrm.Sdk.WebServiceClient.WebProxyClient`1.GetXrmSdkAssemblyFileVersion(): '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'.
        ILC : warning IL3000: Microsoft.Xrm.Sdk.WebServiceClient.WebProxyClient`1.GetXrmSdkAssemblyFileVersion(): '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'.
        ILC : warning IL3000: Microsoft.Xrm.Sdk.WebServiceClient.WebProxyClient`1.GetXrmSdkAssemblyFileVersion(): '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\me\.nuget\packages\runtime.win-x64.microsoft.dotnet.ilcompiler\9.0.3\framework\System.Private.Xml.dll : warning IL3053: Assembly 'System.Private.Xml' produced AOT analysis warnings.
        /_/src/libraries/System.Data.Common/src/System/Data/DataSet.cs(3529): Trim analysis warning IL2026: System.Data.DataSet.System.Xml.Serialization.IXmlSerializable.WriteXml(XmlWriter): Using member 'System.Data.DataSet.WriteXmlInternal(XmlWriter)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. DataSet.WriteXml uses XmlSerialization underneath which is not trimming safe. Members from serialized types may be trimmed if not referenced directly.
        /_/src/libraries/System.Data.Common/src/System/Data/DataTable.cs(6722): Trim analysis warning IL2026: System.Data.DataTable.System.Xml.Serialization.IXmlSerializable.WriteXml(XmlWriter): Using member 'System.Data.DataTable.WriteXmlInternal(XmlWriter)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. DataTable.WriteXml uses XmlSerialization underneath which is not trimming safe. Members from serialized types may be trimmed if not referenced directly.
        /_/src/libraries/System.Data.Common/src/System/Data/DataSet.cs(3507): Trim analysis warning IL2026: System.Data.DataSet.System.Xml.Serialization.IXmlSerializable.ReadXml(XmlReader): Using member 'System.Data.DataSet.ReadXmlSerializableInternal(XmlReader)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. DataSet.ReadXml uses XmlSerialization underneath which is not trimming safe. Members from serialized types may be trimmed if not referenced directly.
        /_/src/libraries/System.Data.Common/src/System/Data/DataTable.cs(6704): Trim analysis warning IL2026: System.Data.DataTable.System.Xml.Serialization.IXmlSerializable.ReadXml(XmlReader): Using member 'System.Data.DataTable.ReadXmlSerializableInternal(XmlReader)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. DataTable.ReadXml uses XmlSerialization underneath which is not trimming safe. Members from serialized types may be trimmed if not referenced directly.
        /_/src/libraries/System.Data.Common/src/System/Data/DataSet.cs(3473): Trim analysis warning IL2026: System.Data.DataSet.System.Xml.Serialization.IXmlSerializable.GetSchema(): Using member 'System.Data.DataSet.WriteXmlSchema(DataSet,XmlWriter)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. DataSet.GetSchema uses TypeDescriptor and XmlSerialization underneath which are not trimming safe. Members from serialized types may be trimmed if not referenced directly.
        /_/src/libraries/System.Data.Common/src/System/Data/DataTable.cs(6668): Trim analysis warning IL2026: System.Data.DataTable.System.Xml.Serialization.IXmlSerializable.GetSchema(): Using member 'System.Data.DataTable.GetXmlSchema()' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. DataTable.GetSchema uses TypeDescriptor and XmlSerialization underneath which are not trimming safe. Members from serialized types may be trimmed if not referenced directly.
        c:\users\me\.nuget\packages\runtime.win-x64.microsoft.dotnet.ilcompiler\9.0.3\framework\System.Private.DataContractSerialization.dll : warning IL3053: Assembly 'System.Private.DataContractSerialization' produced AOT analysis warnings.
        ILC : Trim analysis warning IL2026: System.Security.Cryptography.Xml.SignedXml.ComputeSignature(): Using member 'System.Security.Cryptography.SignatureDescription.CreateDigest()' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. CreateDigest is not trim compatible because the algorithm implementation referenced by DigestAlgorithm might be removed.
        ILC : Trim analysis warning IL2026: System.Security.Cryptography.Xml.SignedXml.ComputeSignature(): Using member 'System.Security.Cryptography.SignatureDescription.CreateFormatter(AsymmetricAlgorithm)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. CreateFormatter is not trim compatible because the algorithm implementation referenced by FormatterAlgorithm might be removed.
        ILC : Trim analysis warning IL2026: System.Security.Cryptography.Xml.CryptoHelpers.CreateFromName<T>(String): Using member 'System.Security.Cryptography.CryptoConfig.CreateFromName(String)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. The default algorithm implementations might be removed, use strong type references like 'RSA.Create()' instead.
        c:\users\me\.nuget\packages\system.security.cryptography.xml\6.0.1\lib\net6.0\System.Security.Cryptography.Xml.dll : warning IL2104: Assembly 'System.Security.Cryptography.Xml' produced trim warnings. For more information see https://aka.ms/il2104
        ILC : Trim analysis warning IL2026: System.Security.Cryptography.Xml.DSASignatureDescription.CreateFormatter(AsymmetricAlgorithm): Using member 'System.Security.Cryptography.CryptoConfig.CreateFromName(String)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. The default algorithm implementations might be removed, use strong type references like 'RSA.Create()' instead.
        ILC : Trim analysis warning IL2026: System.Security.Cryptography.Xml.RSAPKCS1SignatureDescription.CreateFormatter(AsymmetricAlgorithm): Using member 'System.Security.Cryptography.CryptoConfig.CreateFromName(String)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. The default algorithm implementations might be removed, use strong type references like 'RSA.Create()' instead.
        c:\users\me\.nuget\packages\system.security.cryptography.xml\6.0.1\lib\net6.0\System.Security.Cryptography.Xml.dll : warning IL3053: Assembly 'System.Security.Cryptography.Xml' produced AOT analysis warnings.
    
    Build succeeded with 36 warning(s) in 38.8s
    

    Test app code:

    using Microsoft.PowerPlatform.Dataverse.Client;
    
    namespace aot.test
    {
        internal class Program
        {
            static void Main(string[] args)
            {
                Console.WriteLine("Hello, World!");
                DynamicsTest();
            }
    
            static string DynamicsTest()
            {
                ServiceClient c = new ServiceClient(new Uri("https://dummy"), "clientId", "clientSecret", true);
                return c.ConnectedOrgId.ToString();
            }
        }
    }
    

    csproj:

    <Project Sdk="Microsoft.NET.Sdk">
    
      <PropertyGroup>
        <OutputType>Exe</OutputType>
        <TargetFramework>net9.0</TargetFramework>
        <ImplicitUsings>enable</ImplicitUsings>
        <Nullable>enable</Nullable>
        <PublishAot>true</PublishAot>
        <InvariantGlobalization>true</InvariantGlobalization>
      </PropertyGroup>
    
      <ItemGroup>
        <PackageReference Include="Microsoft.PowerPlatform.Dataverse.Client" Version="1.2.3" />
      </ItemGroup>
    
    </Project>
    
  3. MattB-msft commented on Apr 2, 2025

    @MattB-msft
    Member

    Thanks for the feedback here...
    Looking at your error list there, a lot of that is pretty deep in the system.

    I will take a look at trying to unwind this a bit when I have time.

    What is the use case for an AOT app if you can share, please?
    For cross plat the project build should generate the correct runtime files.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions