Skip to content
This repository has been archived by the owner on Feb 21, 2023. It is now read-only.

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

Open
vabed opened this issue Apr 17, 2018 · 13 comments
Open

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

vabed opened this issue Apr 17, 2018 · 13 comments

Comments

@vabed
Copy link

vabed commented Apr 17, 2018

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
Copy link
Collaborator

jnyrup commented Apr 17, 2018

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
Copy link
Author

vabed commented Apr 18, 2018

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
Copy link
Collaborator

jnyrup commented Apr 18, 2018

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
Copy link
Author

vabed commented May 10, 2018

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
Copy link
Collaborator

jnyrup commented May 11, 2018

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
Copy link
Author

vabed commented May 11, 2018

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
Copy link
Collaborator

jnyrup commented May 11, 2018

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
Copy link
Author

vabed commented May 11, 2018

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
Copy link
Collaborator

jnyrup commented May 11, 2018

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
Copy link
Author

vabed commented May 13, 2018

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
Copy link
Author

vabed commented May 15, 2018

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

@jnyrup
Copy link
Collaborator

jnyrup commented May 15, 2018

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

@vabed
Copy link
Author

vabed commented May 15, 2018

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); } }

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants