AOT下StackOverFlow错误 返回

SqlSugar 沟通中
15 308
该叫什么 Melon 发布于1个月前
悬赏:0 飞吻

我是在Avalonia下使用的,除了Avalonia标准包(都是最新版)以外,还包括CommunityToolkit.Mvvm(最新版),SqlSugarCore(最新版5.1.4.182),SQLitePCLRaw.bundle_e_sqlcipher(最新版2.1.11)。


这是代码:

using Avalonia;

using Avalonia.Controls;

using Avalonia.Controls.Documents;

using Avalonia.Markup.Xaml.Styling;

using Avalonia.Media;

using CommunityToolkit.Mvvm.ComponentModel;

using Microsoft.Data.Sqlite;

using SqlSugar;

using System;


namespace AvaloniaApplication2;


public partial class MainWindow : Window

{

    public MainWindow()

    {

        InitializeComponent();

        StaticConfig.EnableAot = true;

        var _databasePath = System.IO.Path.Combine(AppContext.BaseDirectory, "GNSefer.si");

        var _sqliteConnectionStringBuilder = new SqliteConnectionStringBuilder()

        {

            DataSource = _databasePath,

            Mode = SqliteOpenMode.ReadWriteCreate,

            Password = "123456",

            Pooling = true

        }.ToString();

        SqlSugarClient? _SqlSugarClient = new SqlSugarClient(new ConnectionConfig()

        {

            ConnectionString = _sqliteConnectionStringBuilder,

            DbType = DbType.Sqlite,

            IsAutoCloseConnection = true

        });


        _SqlSugarClient.DbMaintenance.CreateDatabase();

        _SqlSugarClient.CodeFirst.InitTables<SourceTypeModel>();

        _SqlSugarClient.Ado.ExecuteCommand("PRAGMA journal_mode=WAL;");

        _SqlSugarClient.Insertable<SourceTypeModel>(new SourceTypeModel() { SourceId = "123" }).ExecuteCommand();

        var _result = _SqlSugarClient.Queryable<SourceTypeModel>().ToList();

    }     

    public class SourceTypeModel : ObservableObject

    {

        string _SourceId = "";

                  

        [SugarColumn(IsPrimaryKey = true)]

        public string SourceId

        {

            get => _SourceId; set

            {

                if (_SourceId != value)

                {

                    _SourceId = value;

                    OnPropertyChanged();

                }

            }

        }


       

        public string EnglishName { get; set; } = "";

      

        public string FormalName { get; set; } = "";


       

        public string Alias { get; set; } = "";


        string _DisplayedName = "";

                 

        [SugarColumn(IsIgnore = true)]

        public string DisplayedName

        {

            get => _DisplayedName; set

            {

                if (_DisplayedName != value)

                {

                    _DisplayedName = value;

                    OnPropertyChanged();

                }

            }

        }

      

      


        InlineCollection _InlineCollection = new InlineCollection();

        [SugarColumn(IsIgnore = true)]

        public InlineCollection InlineCollection

        {

            get => _InlineCollection;

            set

            {

                if (_InlineCollection != value)

                {

                    _InlineCollection = value;

                    OnPropertyChanged();

                }

            }

        }

       

    }

}



运行到var _result = _SqlSugarClient.Queryable<SourceTypeModel>().ToList();这一步,立刻会提示StackOverFlow错误。

如果把StaticConfig.EnableAot = true;这一段删了,运行一切正常。


热忱回答15

  • fate sta fate sta VIP0
    1个月前

    你有没有用到AOT,如果没用到可以删掉 StaticConfig.EnableAot = true

    0 回复
  • Melon Melon VIP0
    1个月前

    @fate sta:有用到AOT

    CSPROJ是这样设置的:

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

      <PropertyGroup>

        <OutputType>WinExe</OutputType>

        <TargetFramework>net9.0</TargetFramework>

        <Nullable>enable</Nullable>

        <BuiltInComInteropSupport>true</BuiltInComInteropSupport>

        <ApplicationManifest>app.manifest</ApplicationManifest>

        <AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>

        <PublishAot>true</PublishAot>

      <AotDiagnostic>true</AotDiagnostic>

    <IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>

      <EnableAOTCompilation>true</EnableAOTCompilation>

      <AvaloniaAOTCompilationMode>Enabled</AvaloniaAOTCompilationMode>

      </PropertyGroup>

      <ItemGroup>

        <None Remove="rd.xml" />

      </ItemGroup>

      <ItemGroup>

        <Content Include="rd.xml">

          <CopyToOutputDirectory>Always</CopyToOutputDirectory>

        </Content>

      </ItemGroup>

      <ItemGroup>

        <RdXmlFile Include="rd.xml" />

      </ItemGroup>

      <ItemGroup>

        <PackageReference Include="Avalonia" Version="11.2.5" />

        <PackageReference Include="Avalonia.Desktop" Version="11.2.5" />

        <PackageReference Include="Avalonia.Themes.Fluent" Version="11.2.5" />

        <PackageReference Include="Avalonia.Fonts.Inter" Version="11.2.5" />

        <!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->

        <PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.2.5" />

        <PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.0" />

        <PackageReference Include="SQLitePCLRaw.bundle_e_sqlcipher" Version="2.1.11" />

        <PackageReference Include="SqlSugarCore" Version="5.1.4.182" />

      </ItemGroup>

    </Project>



    RD.XML是这样设置的:

    <Directives>

    <Application>

    <Assembly Name="SqlSugar"  Dynamic="Required All">

    </Assembly>

    </Application>

    </Directives>


    这是Debug下运行的:

    image.png


    这是编译后运行的:

    image.png

    0 回复
  • fate sta fate sta VIP0
    1个月前

    删掉OBJ和BIN打包一个DEMO

    0 回复
  • fate sta fate sta VIP0
    1个月前

    你实体换成普通的get ;set试一下。我看了你这个实体好像有了事件

    0 回复
  • fate sta fate sta VIP0
    1个月前

    安装时 sqlsugarcore换成 SqlSugarCoreNoDrive.Aot 试一下

    0 回复
  • Melon Melon VIP0
    1个月前


    这是DEMO:

    AvaloniaApplication2.zip

    另外我发现删除了InlineCollection那个属性AOT运行就没事了,但是这个属性我已经标明了IsIgnore了,不知道为什么还会影响到。


    0 回复
  • Melon Melon VIP0
    1个月前

    @fate sta:刚尝试过sqlsugarcore换成 SqlSugarCoreNoDrive,还是一样。

    0 回复
  • fate sta fate sta VIP0
    1个月前
    public InlineCollection _InlineCollection =null;
    [SugarColumn(IsIgnore = true)]
    public InlineCollection InlineCollection
    {
        get => _InlineCollection;
        set
        {
            if (_InlineCollection == null) 
            {
                _InlineCollection = new InlineCollection();
            }
            if (_InlineCollection != value)
            {
                _InlineCollection = value;
                OnPropertyChanged();
            }
        }

    改成这样好像就可以了,不在初始化类的时候去new

    0 回复
  • fate sta fate sta VIP0
    1个月前
    public InlineCollection _InlineCollection =null;
    [SugarColumn(IsIgnore = true)]
    public InlineCollection InlineCollection
    {
        get => _InlineCollection;
        set
        {
            if (_InlineCollection == null) 
            {
                _InlineCollection = new InlineCollection();
            }
            if (_InlineCollection != value)
            {
                _InlineCollection = value;
                OnPropertyChanged();
            }
        }

    改成这样好像就可以了,不在初始化类的时候去new

    0 回复
  • Melon Melon VIP0
    1个月前

    @fate sta:刚测试过你给的代码,还是不行。我甚至把InlineCollection改成可空类型也同样不行,很是奇怪。

    0 回复
  • Melon Melon VIP0
    2周前

    @fate sta:我发现问题原因,是AOT下[SugarColumn(IsIgnore = true)]这个标签根本不起作用,我发现这个情况(https://github.com/DotNetNext/SqlSugar/issues/1292)和我差不多,但是按照这个网址上面说的添加[JsonIgnore]也是同样不起作用。

    0 回复
  • @MelonSugarColumn(IsIgnore = true)] 肯定是起作用的。。你写个简单类型的CRUD。测试

    0 回复
  • SugarColumn(IsIgnore = true)]

    public object xxx{get;set;}

    改成简单的DEMO

    0 回复
  • 我怀疑是AOT InlineCollection 这个类型有问题

    0 回复
  • Melon Melon VIP0
    5天前

    @fate sta:我发现并不只是InlineCollection,我同一个项目另外有个地方自己写了一个复杂的叫做Source的类,在连接数据库的时候虽然也标记了这个类是[SugarColumn(IsIgnore = true)]的,但也同样报错。这个类太复杂,我没办法一个个拆解排查。后面在AOT的时候我只好把数据和UI层的都分割开去处理。

    0 回复