NativeAssemblies loading issues with SqlServerTypes

tamasoz 21 Reputation points
2022-11-09T11:35:43.607+00:00

Hi,

We are in the process of migrating a monolithic set of applications from a IIS/Windows server environment to Azure Webapps. Whilst we have faced significant challenges at many aspects of this migration project yet we still managed to find a decent solution for all matters.

However, this one doesn't seem to be working despite several tries.

As far as I understand on the legacy server environment, the SqlServerTypes were installed on Windows (applications work with spatial data in the SQL server). The application itself is composed of various smaller Class library projects and after migrating from the legacy server environment I installed the SqlServerTypes successfully with Nuget (there is one version available there, 14.0 or something). I followed up the library's readme's requirements to load the DLL's.

The required assembly loading routine is added to the Global.asax application start section - it loads in fine, during debugging I can see the Spatial library is loaded in and the system is working ok via the web application as well as via the subsequent class library dll's.

However, now we need to do the same with console applications. The Microsot.SqlServer.Types nuget is added to the console app and the necessary call to load in the library is added like this...

        static void Main(string[] args)  
        {  
            SqlServerTypes.Utilities.LoadNativeAssemblies(AppDomain.CurrentDomain.BaseDirectory);  

Regrettably the system does not behave the same way how it does with the web application. I have debugged the application and stepped through the routine through the nitty gritty of Loader.cs. There is no exception thrown and the loading process is seemingly going through fine. Yet there are no Spatial library loaded in and upon calling the SQL table with spatial columns it keeps bellying up.

I checked all paths in the Loader.cs and they are all correct, everything is where it should be. There is a call where the logic should say something if the load is not happening:

  var ptr = LoadLibrary(path);  
            if (ptr == IntPtr.Zero)  
            {  
                throw new Exception(string.Format(  
                    "Error loading {0} (ErrorCode: {1})",  
                    assemblyName,  
                    Marshal.GetLastWin32Error()));  
            }  

...but in my case the ptr is not IntPtr.Zero but something else.

I tried build/deploy on both 64 and 32 bit architecture. It is just not getting it.

The odd thing is that with web application - it all seems working fine.

I tried finding solutions on forums but I couldn't.

Well - any help will be appreciated.

Thanks

.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,399 questions
{count} votes