How to use fluent nHibernate from an ArcGIS Pro 3.1 AddIn with C#?

138
0
2 weeks ago
RaStar
by
New Contributor

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: https://stackoverflow.com/questions/47718924/fixing-platformnotsupportedexception-when-referencing-s... 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="FluentNHibernate" Version="3.2.1" />
<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>```

I already asked the question on stackOverflow but ESRI-Support told me to ask here too:

https://stackoverflow.com/questions/76920951/how-to-use-fluent-nhibernate-from-an-arcgis-pro-3-1-add...

 

 

Tags (3)
0 Kudos
0 Replies