GribApiDotNet / GribApi.NET

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

A problem using Grib.Api in Azure Functions project #100

Open vabed opened 6 years ago

vabed commented 6 years ago

When I call GribFile constructor at first time everything goes fine, but when I try iterate throught it application breaks down and exit. using (GribFile file = new GribFile(@"file_name.grib2")) { var msg = file.First(); }
It all looks similar to issue #22

jnyrup commented 6 years ago

Your title mentions Azure Functions, does that mean that you don't have any problem when running your program on a local machine?

"Application break down" sounds like an unhandled expcetion, that causes the program to terminate. If that is the case, try wrapping the code in side a Try/Catch to see which type of exception is thrown and what the exception message is.

What version of GribApi do you use?

Have you had a look at #52 ? It also described a problem when running in Azure Functions.

vabed commented 6 years ago

When I use it in Console project everything works. I surround this code with Try/Catch but it doesn't throw any exceptions and application just break down (maybe exception throws on lower levels). I use version 0.7.1 and I also looked at #52 but there used version 1.0.0

jnyrup commented 6 years ago

Please try upgrading to newest beta to see if that solves your problem. There once was a problem with uncatchable exceptions being thrown, but that should have been solved.

vabed commented 6 years ago

I have updated the package to beta version, after it I can run functions on my local PC but when I publishing on Azure and call the function the exception about Environment shows GribEnvironment::DefinitionsPath must be a valid path. Please see GribApi.NET's documentation for help. Path:

jnyrup commented 6 years ago

What is the value of GribEnvironment.DefinitionsPath? Is the folder Grib.Api correctly copied from the nuget package to the code you deploy?

The message you see indicates that GribApi.NET could not locate the definitions folder.

vabed commented 6 years ago

The value for GribEnvironment.DefinitionsPath looks like string.Empty from the exception message. Yes I copy Grib.Api folder to the wwwroot folder on Azure Functions and Grib.Api folder contains definitions folder, but it all doesn't help, I still get the same mistake

jnyrup commented 6 years ago

Have you to explictly set GribEnvironment.DefinitionsPath to the absolute path pointing to Grib.Api/definitions?

GribApi.NET has some heuristics to search for the definitions folder, but it won't do an exhaustive search for it.

vabed commented 6 years ago

Yes, it helps. But now I face the same problem as here #52. As I understand the solution is to manually copy Grib.Api.Native.dll to bin folder?

jnyrup commented 6 years ago

Glad it helped. To my knowledge there is no "official" way to make it work. If it was me, I would add a link in the csproj file to the right Grib.Api.Native.dll to force it being copied to the root of the bin folder.

vabed commented 6 years ago

I hurried up with results( GribEnvironment.DefinitionsPath = @"D:\somepath\wwwroot\Grib.Api\definitions"; log.Info("defPath: " + GribEnvironment.DefinitionsPath); when I run this code on AzureFunctions logs show me 2018-05-13T14:45:31.214 [Info] defPath: and then I still get an exception about GribEnvironment::DefinitionsPath must be a valid path. It looks like setter for GribEnvironment.DefinitionsPath doesn't work correctly. UPD: the same behavior is on my local PC also

vabed commented 6 years ago

UPD: I achive running beta-4 on Azure Functions, but setter for DefinitionsPath is still doesn't work.

jnyrup commented 6 years ago

Could you put a few words on how you got it working? It will help others with similar problems.

vabed commented 6 years ago

OK, maybe not all of this steps are obligatory but it helps me

  1. Copy Grib.Api folder from nuget packages on your local PC to .../site/wwwroot/ on Azure.Functions. Your could use Kudu for it.
  2. Set Global Environment variables on Azure Functions GRIB_API_DIR_ROOT:"D:\home\site\wwwroot\Grib.Api" GRIB_DEFINITION_PATH:"D:\home\site\wwwroot\Grib.Api\definitions".
  3. Put Grib.Api.Native.dll from ..\Grib.Api\lib\win\x86 to ...\site\wwwroot\bin folder on Azure Functions.
  4. Call this code before first use of GribFile private static void SetGribEnvironment(TraceWriter log) { Random rand = new Random(); try { GribEnvironment.Init(); } catch (Exception e) { log.Error(e.Message); Thread.Sleep(4000 + rand.Next(2000)); SetGribEnvironment(log); } }