GribApiDotNet / GribApi.NET

A powerful .NET library for reading and writing GRIB 1 and 2 files
Apache License 2.0
54 stars 28 forks source link

GribApi in Azure functions #52

Closed moab360 closed 7 years ago

moab360 commented 7 years ago

Hi there, I'm finally getting around to moving my workflows (currently using wgrib2.exe) over to GribApi. The 1.0 beta is doing a great job chewing through the Canadian Meteorological Center's grib files.

I'm also migrating my workflows into Azure Functions to reduce the load on my server when publishing new forecasts. And that's where I'm running into problems.

I'm setting the Environment variable to point at the GribApi root

Environment.SetEnvironmentVariable("GRIB_API_DIR_ROOT", @"D:\home\data\Functions\packages\nuget\grib.api\1.0.0-beta", EnvironmentVariableTarget.Process);

But the second I call using (GribFile file = new GribFile(TemporaryGribLocation)){...

I get the following exception. I've checked the location where the dll is being looked for and it is there. One thing that I'm investigating is that I think Azure Functions are on 64bit, so it's strange the x86 dll is being called on...

System.TypeInitializationException: The type initializer for 'Grib.Api.GribFile' threw an exception. ---> System.Exception: Can't load DLL D:\home\data\Functions\packages\nuget\grib.api\1.0.0-beta\Grib.Api\lib\win\x86\Grib.Api.Native.dll ---> System.ComponentModel.Win32Exception: The specified module could not be found
   --- End of inner exception stack trace ---
   at Grib.Api.Interop.Util.Win32.LoadWin32Library(String libPath) in c:\Users\eric\GribApi.NET\src\GribApi.NET\Grib.Api\Interop\Util\Win32.cs:line 36
   at Grib.Api.GribEnvironmentLoadHelper.BootStrapLibrary() in c:\Users\eric\GribApi.NET\src\GribApi.NET\Grib.Api\GribEnvironmentLoadHelper.cs:line 13
   at Grib.Api.GribEnvironment.Init() in c:\Users\eric\GribApi.NET\src\GribApi.NET\Grib.Api\GribEnvironment.cs:line 64
   at Grib.Api.GribFile..cctor() in c:\Users\eric\GribApi.NET\src\GribApi.NET\Grib.Api\GribFile.cs:line 45

Any ideas/help would be great

Thanks!

0x1mason commented 7 years ago

What I would do is add a ton of logging and look for the file. Does it work without SetEnvVar? Also, log the bitness to be sure.

moab360 commented 7 years ago

Okay, after some debugging I think I found the issue. I'm using 1.0.0-beta, and Grib.Api.Native.dll depends on the following

Besides Kernel32.dll, the others are not available on the server. Sadly I can't add and register dlls either.

I'm noticing that version 0.7.1, Grib.Api.Native.dll relies on

these are available and registered on the server, but I require the 1.0.0-beta to work with the Canadian Meteorological Centeres grib files (blurg). I'm not sure if the dependencies changed or the compile options changed with 1.0.0. Any help would be great!

jnyrup commented 7 years ago

This is a duplicate of #64. In short the Grib.Api.Native.dll in 1.0.0-beta is build against debug dlls from Microsoft Visual C++ Redistributable 2015.

moab360 commented 7 years ago

Yup that's it. Thanks for the pointer

scottcha commented 6 years ago

@moab360 were you ever able to get this working in an azure function? I'm using the 1.0.0-beta4 and get
System.DllNotFoundException: 'Unable to load DLL 'Grib.Api.Native.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)' When attempting to load the native dll. Its specifically on this line in Grib.Api.Interop.Util.GribApiNative.cs: [DllImport("Grib.Api.Native.dll")] internal static extern void SetDefaultDefinitionsPath([MarshalAs(UnmanagedType.LPStr)]string path); Just jumping in to see if I can determine if a dependency is missing or some other config is off. Was there any other special steps you took to get this running in an Azure function? Have you tried the beta4? Thanks!

scottcha commented 6 years ago

Well, turns out copying the Grib.Api.Native.dll to the functions bin folder worked.

jnyrup commented 6 years ago

I've had a similar experience for a project of this structure: MyConsoleApp --> MyLibrary --> GribApi.Net

The bin folder of MyLibrary contains the Grib.Api dlls. The dependency on MyLibrary does not causes Grib.Api dlls to be copied to the bin folder of MyConsoleApp.

RudyCo commented 6 years ago

Hi, I managed to use Grib.Api with a WebJobs app (Functions rely on WebJobs behind the scene). In order to do this, you need to copy the full Grib.Api folder to Azure and reference this folder in your code.