Search Results for

    Show / Hide Table of Contents

    Using Native AOT

    In a script, you may use only classes available in the host app. Native AOT compiled host app may not contain a class (or a member of class) that you want to use in a script because the class/member was trimmed.

    Another problem is generics (types/methods). In Native AOT, you cannot create closed generic of any type; the generic you want to construct must present in a compiled host app. For example, your host app uses List<int> but does not use List<double>. In this case, you will be able to use List<int> in a script, but constructing a List<double> will throw an error.

    So it's your duty to ensure classes/methods are available in the compiled host app to use them in a script. Various techniques may be used to do this, for example, constructing instances of types, using attributes:

    [DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(List<>))]
    public void EnsureAOTVisible()
    {
        var list = new List<int>();
    }
    

    Note that generic parameters of reference types can be used if an open generic type is available in a host app. For example, having a List<> type available in your app, you may construct List<object> or List<List<...>> or List<Dictionary<...>>.

    Back to top © 1998-2025 Copyright Fast Reports Inc.