You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

ArcGIS Pro 3.1 C#插件使用Fluent NHibernate遇平台不支持异常

ArcGIS Pro 3.1插件Fluent NHibernate初始化异常问题

我用C#开发ArcGIS Pro 3.1插件时,初始化Fluent NHibernate连接抛出异常,相关信息如下:

初始化代码

public ISessionFactory CreateSessionFactory()
{
    Action<MappingConfiguration> mappings = m => m.FluentMappings.AddFromAssemblyOf<Domain>();
    string connection = "Data Source=xxx;Initial Catalog=xxx;Integrated Security=True;Connect Timeout=15;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False";
    var configure = Fluently.Configure();
    var dbConfig = MsSqlConfiguration.MsSql2012.ConnectionString(connection);
    var dbConfigWithSchema = dbConfig.DefaultSchema("xxx");
    var fluentDb = configure.Database(dbConfigWithSchema);
    var fluentMap = fluentDb.Mappings(mappings);

    fluentMap = fluentMap.ExposeConfiguration(BuildSchema);

    return fluentMap.BuildSessionFactory(); //此处抛出异常
}

private void BuildSchema(NHibernate.Cfg.Configuration obj)
{
    new SchemaUpdate(obj)
        .Execute(true, true);
}

异常信息

FluentNHibernate.Cfg.FluentConfigurationException
  HResult=0x80131500
  Message=An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.

  Source=FluentNHibernate
  StackTrace:
   at FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory()
   at ChecknHibernate.Button1.CreateSessionFactory() in C:\Daten\RadSvn\Prototypes\ChecknHibernate\Button1.cs:line 47
   at ChecknHibernate.Button1.OnClick() in C:\Daten\RadSvn\Prototypes\ChecknHibernate\Button1.cs:line 30
   at ArcGIS.Desktop.Framework.Wrappers.CommandWrapper.OnClick()
   at ActiproSoftware.Windows.Controls.Ribbon.Input.RibbonCommand.ExecuteCommandSource(ICommandSource commandSource)
   at ActiproSoftware.Windows.Controls.Ribbon.Controls.Primitives.ButtonBase.OnClick(ExecuteRoutedEventArgs e)
   at ActiproSoftware.Windows.Controls.Ribbon.Controls.Primitives.ControlBase.<>c__DisplayClass113_0.<RaiseClickEvent>b__0(Object <p0>)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
   at System.Windows.Threading.DispatcherOperation.InvokeImpl()
   at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
   at MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(Object obj)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)

  This exception was originally thrown at this call stack:
    [External Code]

Inner Exception 1:
TargetInvocationException: Exception has been thrown by the target of an invocation.

Inner Exception 2:
PlatformNotSupportedException: System.Data.SqlClient is not supported on this platform.

当前使用的NuGet包

<ItemGroup>
    <PackageReference Include="FluentNHibernate" Version="3.2.1" />
    <PackageReference Include="System.Data.SqlClient" Version="4.8.5" />
</ItemGroup>

已尝试的解决方案

  • 使用QueuedTask.Run调用CreateSessionFactory,结果相同;
  • 在主线程通过Application.Current.Dispatcher.Invoke调用,结果相同;
  • 在所有关联项目中引用System.Data.SqlClient,结果相同;
  • 在Module1外部延迟调用CreateSessionFactory,结果相同;
  • 创建仅包含必要代码的测试应用,结果相同;
  • 添加Microsoft.Data.SqlClient引用,结果相同;
  • 移除System.Data.SqlClient仅保留Microsoft.Data.SqlClient,结果相同;
  • 尝试使用Microsoft.EntityFrameworkCore相关包,结果相同:
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.1.1" />
    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.10" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.10" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.10">
          <PrivateAssets>all</PrivateAssets>
          <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>

已在ESRI社区提问,仍未解决,寻求有效解决方案。

内容的提问来源于stack exchange,提问作者Gener4tor

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.13 04:22:19