Skip to content

DRNJ

Light at the end of the Technology Tunnel

  • Home
  • About
  • Contact
DRNJ

Month: June 2021

NHIbernate, Sybase and .NET Core

June 28, 2021

The Problem

I was working on a system utilising .NET 4.x and Sybase. This combination is not supported by Entity Framework so NHibernate was used.

It was planned to migrate the project to .NET Core, however a number of issues were encountered ustilising NHibernate.

Much investigation was performed, espcially using Resharper to disassemble the Sybase driver

The solution is shown below. Voila, you can use .NET Core and NHibernate and Sybase.

Solution Attempt Number 1

Code

  • Create WebAPI project on DotNet Core 3.1
  • Add references to NHibernate 5.2.7

Errors

Discussion

It appears that the NHibernate code cannot find the the Sybase ASE driver Sybase.ADONet2.AseClient installed as part of the nuget package

 

Solution Attempt Number 2

Code

As per Verrsion 1 but with

  • NHibernate 5.2.7 Source code downloaded and .csproj added to solution and references instead of NHibernate nuget package (so can step through code)
  • Reference added to Sysbase DLLs

Errors

Discussion

An exception is thrown in the Sybase.AdoNet2.ASeClient.dll in the constructor which calls LoadLibraries():

NB Disassembly of the driver done by ReSharper

The error is thrown at the line 252 on the Directory.GetAccessControl method – this is not supported in .Net Core:

https://stackoverflow.com/questions/41584932/support-for-file-security-in-net-core

The “workaround” suggested does not appear to work within the context of the Driver (not known why but driver might run in a restricted execution context). This article also discusses the driver error and that some System.IO methods have been removed in dotnetcore.

The Real Solution

Code

  • Add AdoNetCore.AseClient nuget package – this is a 3rd party Sybase ASE driver
  • Reference NHibernate nuget version 5.2.7
  • Add Driver classes as below

These files  are “driver” classes customised to use the AdoNetCore.AseClient driver. These are “copies” of the equivalent files in the NHibernate source code with the following modifications

The above specification for connection.driver_class is necessary as “full assembly specification” giving assembly name and class name otherwise NHibernate doesn’t know in which DLL to “looK” for the class.

The CustomDialect class was changed to reference these files:

 

Discussion

he  connection.driver_class specification in SybaseASECoreDialect was the only “tricky” thing to “get right”.  In the NHibernate “virgin” SysbaseASE15Dialect only specifies the “Driver” class name for the connection.driver_class

 

The NHibernate can “find” Nhibernate.Driver.SybaseAseClientDriver as it is contained within the NHibernate DLL. Using the custom classes it is necessary to specify the “full name” as the code is in separate assembly

.NET Core, WebAPI

API Versioning and Swagger

June 28, 2021

The Problem

API Versioning was added to a Microsoft C# Web API project .NET Core.

[ApiVersion("2.1")]
public class MyController: ApiController
{
}

The Swagger page for the API then did not list the API endpoints

The Solution

Simply add the [ApiController] attribute to the class

[ApiVersion("2.1")]
[ApiController]
public class MyController: ApiController
{
}

 

 

.NET Core, WebAPI

Recent Posts

  • AutoMapper and “Could not load type ‘SqlGuidCaster'” Error
  • OpenVPN on Docker and the Strange Error Message Saga
  • Docker CLI and Compose Information Message
  • Docker Containers and Azure – An Introduction
  • Serilog in .Net Core 6

Recent Comments

    Archives

    • April 2025
    • December 2024
    • April 2024
    • September 2022
    • November 2021
    • June 2021
    • March 2021
    • July 2020
    • April 2020
    • November 2019
    • September 2019
    • July 2019
    • May 2019
    • February 2019
    • July 2018
    • June 2018

    Categories

    • .NET Core
    • Azure
    • Docker
    • DotNet
    • Security
    • Uncategorized
    • WebAPI
    • Windows

    Meta

    • Log in
    • Entries feed
    • Comments feed
    • WordPress.org

    Idealist by NewMediaThemes