0

I am programming a ArcGIS Pro 3.1 AddIn with C#.

I try to initialize a fluent nHibernate connection:

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(); //Here the exception is thrown
}

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

throws this exception:

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.

I use this packages:

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

I tried:

  • Calling the code as as QueuedTask like this. The result is the same:

    QueuedTask.Run(() => CreateSessionFactory(...));

  • Calling the code from the main thread like this. The result is the same:

    Application.Current.Dispatcher.Invoke(new Action(() => { CreateSessionFactory(...); }));

  • Using nuget System.Data.SqlClient in every project which is involved (The result is the same):

  • Called CreateSessionFactory later and outside of Module1. The result is the same.

  • Created a test application with nothing but the minimum involved. The result is the same.

  • Added a reference to Microsoft.Data.SqlClient as suggested here: Fixing PlatformNotSupportedException when referencing System.Data.SqlClient from C# Azure Function The result is the same.

  • removed System.Data.SqlClient and only referenced Microsoft.Data.SqlClient. The result is the same.

  • Tried to use Microsoft.EntityFrameworkCore, Microsoft.EntityFrameworkCore.SqlServer and Microsoft.EntityFrameworkCore.Tools as suggested here: https://github.com/dotnet/SqlClient/issues/2030 The result is the same:

    <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>```
Gener4tor
  • 414
  • 3
  • 12
  • 40
  • there is this issue https://github.com/dotnet/SqlClient/issues/2030. Have you tried the suggestions there? – Firo Aug 22 '23 at 06:45
  • FluentInterfaces are meant to be used like this: `var factory = Fluently.Configure()DefaultSchema("xxx").Database(MsSqlConfiguration.MsSql2012.ConnectionString(connection)).Mappings(m => m.FluentMappings.AddFromAssemblyOf())ExposeConfiguration(BuildSchema).BuildSessionFactory();`. Just saying – Firo Aug 22 '23 at 06:48
  • I know I can add them all together. But the code here is the one I optimized for this question. In my original code there are some ifs between the lines + its easier to debug because its easier to see the line which throws a exception. – Gener4tor Aug 24 '23 at 15:07
  • @Firo: I tried the suggestion there https://github.com/dotnet/SqlClient/issues/2030 but it did not work (See edits in question). Maybe I missed something. – Gener4tor Aug 25 '23 at 09:10

0 Answers0