MaxRev-Dev / gdal.netcore

GDAL 3.x C#/F# bindings for .NET apps
MIT License
162 stars 36 forks source link

mcr.microsoft.com/dotnet/core/sdk:3.1.404-nanoserver-1809 Issue calling registerAll() #67

Closed csviyyap closed 2 years ago

csviyyap commented 2 years ago

I'm facing issues with the allregister() method when running in a docker container. I'm not facing any issues in my local and remote VM.

System.TypeInitializationException: The type initializer for 'OSGeo.OGR.OgrPINVOKE' threw an exception.

Below is my docker file FROM mcr.microsoft.com/dotnet/core/sdk:3.1.404-nanoserver-1809 WORKDIR /app EXPOSE 80 EXPOSE 443

RUN dotnet tool install --global PowerShell --version 7.0.3 USER ContainerAdministrator ADD API/gdal-frame-dlls C:/Windows/System32/ COPY ["security.dll", "C:/Windows/System32"] COPY ["SampleAPI/Sampleoutput", "."] COPY ["generate-database-connection.ps1", "."]

USER ContainerAdministrator ENTRYPOINT ["pwsh", "-command", "Copy-Item 'C:/appsettings/appsettings.json' -Destination 'C:/app/appsettings.json';", "dotnet API.dll;"]

I'm referring to below Nuget sources MaxRev.Gdal.Core" Version="3.2.0.320" MaxRev.Gdal.WindowsRuntime.Minimal" Version="3.2.0.310" are installed.

Couldn't find 'MaxRev.Gdal.Core.Windows' assembly in loaded assemblies of current domain. Is it installed? Failed to configure Gdal for windows runtime [12:06:03 ERR] Exception in UploadShapeFile Controller Method:The type initializer for 'OSGeo.GDAL.GdalPINVOKE' threw an exception. info: Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker[2] Executed action API.Controllers.PolygonController.UploadShapeFile (API) in 105.3672ms info: Microsoft.AspNetCore.Routing.EndpointMiddleware[1] Executed endpoint 'API.Controllers.PolygonController.UploadShapeFile (API)' fail: Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware[1] An unhandled exception has occurred while executing the request. System.TypeInitializationException: The type initializer for 'OSGeo.GDAL.GdalPINVOKE' threw an exception. ---> System.TypeInitializationException: The type initializer for 'SWIGExceptionHelper' threw an exception. ---> System.DllNotFoundException: Unable to load DLL 'gdal_wrap' or one of its dependencies: The specified module could not be found. (0x8007007E) at OSGeo.GDAL.GdalPINVOKE.SWIGExceptionHelper.SWIGRegisterExceptionCallbacks_Gdal(ExceptionDelegate applicationDelegate, ExceptionDelegate arithmeticDelegate, ExceptionDelegate divideByZeroDelegate, ExceptionDelegate indexOutOfRangeDelegate, ExceptionDelegate invalidCastDelegate, ExceptionDelegate invalidOperationDelegate, ExceptionDelegate ioDelegate, ExceptionDelegate nullReferenceDelegate, ExceptionDelegate outOfMemoryDelegate, ExceptionDelegate overflowDelegate, ExceptionDelegate systemExceptionDelegate) at OSGeo.GDAL.GdalPINVOKE.SWIGExceptionHelper..cctor() --- End of inner exception stack trace --- at OSGeo.GDAL.GdalPINVOKE.SWIGExceptionHelper..ctor() at OSGeo.GDAL.GdalPINVOKE..cctor() --- End of inner exception stack trace --- at OSGeo.GDAL.GdalPINVOKE.GDALDestroyDriverManager() at OSGeo.GDAL.Gdal.GDALDestroyDriverManager()

MaxRev-Dev commented 2 years ago

It won't work on nanoserver. See https://github.com/MaxRev-Dev/gdal.netcore/issues/26. Use a docker container or azure functions.

csviyyap commented 2 years ago

Can you please suggest some Docker Container images where it would work along with the .Net Core 3.1 environment?

MaxRev-Dev commented 2 years ago

Just containerize it as .NET project. I created here a docker test project. https://github.com/MaxRev-Dev/gdal.netcore/blob/master/test/GdalCoreTest/Dockerfile

csviyyap commented 2 years ago

Thanks for the test project. It looks like it is built using .net framework. Can you please share any .net core-related samples?.

MaxRev-Dev commented 2 years ago

Please, read the docs: https://docs.docker.com/samples/dotnetcore/#create-a-dockerfile-for-an-aspnet-core-application

It's built using .NET 5.0 SDK and running on .NET 5.0 FROM mcr.microsoft.com/dotnet/sdk:5.0 You can find the list of runtime images here: https://hub.docker.com/_/microsoft-dotnet-runtime/