Skip to content

Native AOT compatibility #489

@RikkiGibson

Description

@RikkiGibson

It would be great to be able to use Native AOT in an game that references Myra.

When I try to publish with native AOT, while referencing Myra, the resulting app crashes on startup. I get the following warnings during publish:

    ILC : Trim analysis warning IL2057: Microsoft.Xna.Framework.Content.ContentTypeReaderManager.LoadAssetReaders(ContentReader): Unrecognized value passed to the parameter 'typeName' of method 'System.Type.GetType(String)'. It's not possible to guarantee the availability of the target type.
    ILC : Trim analysis warning IL2070: Microsoft.Xna.Framework.Content.ContentExtensions.GetDefaultConstructor(Type): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicConstructors', 'DynamicallyAccessedMemberTypes.NonPublicConstructors' in call to 'System.Type.GetConstructor(BindingFlags,Binder,Type[],ParameterModifier[])'. The parameter 'type' of method 'Microsoft.Xna.Framework.Content.ContentExtensions.GetDefaultConstructor(Type)' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.
    ILC : Trim analysis warning IL2075: Myra.MML.LoadContext.Load<T>(Object,XElement,!!0): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicEvents' in call to 'System.Type.GetEvent(String)'. The return value of method 'System.Object.GetType()' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.
    ILC : Trim analysis warning IL2090: Myra.MML.LoadContext.Load<T>(Object,XElement,!!0): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicMethods' in call to 'System.Type.GetMethod(String,BindingFlags)'. The generic parameter 'T' of 'Myra.MML.LoadContext.Load<T>(Object,XElement,!!0)' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.
    ILC : Trim analysis warning IL2075: Myra.MML.LoadContext.Load<T>(Object,XElement,!!0): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicEvents' in call to 'System.Type.GetEvent(String)'. The return value of method 'System.Object.GetType()' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.
    ILC : Trim analysis warning IL2026: Myra.MML.LoadContext.Load<T>(Object,XElement,!!0): Using member 'System.Reflection.Assembly.GetType(String)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. Types might be removed by trimming. If the type name is a string literal, consider using Type.GetType instead.
    ILC : Trim analysis warning IL2067: Myra.MML.BaseContext.ParseProperties(Type,Boolean,List`1<PropertyInfo>&,List`1<PropertyInfo>&): 'type' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicProperties', 'DynamicallyAccessedMemberTypes.NonPublicProperties' in call to 'System.Reflection.RuntimeReflectionExtensions.GetRuntimeProperties(Type)'. The parameter 'type' of method 'Myra.MML.BaseContext.ParseProperties(Type,Boolean,List`1<PropertyInfo>&,List`1<PropertyInfo>&)' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.
    ILC : Trim analysis warning IL2026: Myra.Graphics2D.UI.Project.GetWidgetTypeByName(String): Using member 'System.Reflection.Assembly.GetType(String)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. Types might be removed by trimming. If the type name is a string literal, consider using Type.GetType instead.
    ILC : Trim analysis warning IL2059: Myra.MML.AttachedPropertiesRegistry.GetPropertiesOfType(Type): Unrecognized value passed to the parameter 'type' of method 'System.Runtime.CompilerServices.RuntimeHelpers.RunClassConstructor(RuntimeTypeHandle)'. It's not possible to guarantee the availability of the target static constructor.
    ILC : Trim analysis warning IL2067: Myra.MML.LoadContext.<>c.<.ctor>b__11_0(Type,XElement): 'type' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicParameterlessConstructor' in call to 'System.Activator.CreateInstance(Type)'. The parameter 'type' of method 'Myra.MML.LoadContext.<>c.<.ctor>b__11_0(Type,XElement)' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.

Build succeeded with 10 warning(s) in 15.1s

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions