Closed VishmayShah closed 8 years ago
Ok, I'll take a look at it. Do you need a temporary workaround? Should be simple.
You shouldn't need to make any of those calls to GC. Dispose
gets called when control leaves the using
block. That in turn calls GC::SuppressFinalize
. Furthermore, Collect
only collects managed memory.
For now, you can use FileInfo::Length
to check the file length before creating the GribFile. https://msdn.microsoft.com/en-us/library/system.io.fileinfo.length(v=vs.110).aspx
Thanks for quick resolution, i will implement it and reply . but this is not complete because reason of going to catch may be other like Half downloaded file will throw error of end of file reached Still my temp solution is done thank you
and also dispose and collect was used just for purpose of safety nothing else
do we have any progress in resolution of this bug?
Not yet. Is the workaround working for you? On Dec 30, 2015 5:54 AM, "VishmayShah" notifications@github.com wrote:
do we have any progress in resolution of this bug?
— Reply to this email directly or view it on GitHub https://github.com/0x1mason/GribApi.NET/issues/18#issuecomment-167976456 .
Half downloaded file will throw error of end of file reached. so not 100% working
Ok, sorry about that. I'll try to get to it by Monday. Until then, try the following:
FileInfo::Length
check, read the file and check for the terminating characters.(37 37 37 37)7777 i am getting at last point grib2 is my version
If you check for that in the downloads, that will tell you if you have a good file or not.
Hi Vishmay,
Thanks for your patience. Can you try installing 0.6.4-beta and let me know if it resolves your issues?
You should get a FileLoadException
for the empty file and a GribApiException
for an incomplete file. You'll have to handle those exceptions as you would other valid exceptions. However, you shouldn't get any AccessViolationExceptions
.
@VishmayShah I'm hoping this is resolved for you. If not, let me know.
For the actual 0.6.4 release, I've changed it so both situations throw FileLoadException
. I also hardened the EOF check for 7777.
i am not sure on will it work or not as i am not upgrading it now as it is used. the origin of problem was that in try catch block if flow goes to catch block then gribapi was not disposing
so we think that not let flow go in catch, so that check for empty file if not then try to read else don’t initialize grib api same was needed for half downloaded files (that is pending in my proj) so FileLoadException will properly dispose grib.api for 7777 is required. is it solving it? and how to use it?
From: Eric Millin Sent: Sunday, January 24, 2016 5:10 AM To: 0x1mason/GribApi.NET Cc: VishmayShah Subject: Re: [GribApi.NET] An unhandled exception of type 'System.AccessViolationException' occurred in Grib.Api.dll (#18)
For the actual 0.6.4 release, I've changed it so both situations throw FileLoadException. I also hardened the EOF check for 7777.
— Reply to this email directly or view it on GitHub.
Thank you for your great responce
If your current solution works for you, then I would not make any changes. Here's how you would use the new changes:
SomeType data = null;
try
{
using (GribFile file = new GribFile("mygrib.grb"))
{
// set `data`
}
} catch (FileLoadException e)
{
Console.WriteLine("The file is empty or incomplete: " + e.Message);
}
if (data == null)
{
// handle failure
}
I Find a special case when this exception is thrown in my code i have
function1() { try { using (GribFile gribFile = new GribFile(readPath)) { //some work gribFile.Dispose(); GC.Collect(); GC.WaitForPendingFinalizers(); } } catch (Exception ex) { GC.Collect(); GC.WaitForPendingFinalizers(); } } function2() { XDocument doc=XDocument.Parse(bigxml); } void main() { function1(); function2();
}
the above main is executed and works perfectly when we have complete file,both functions are executed properly. but when readPath Files is empty(0KB), the execution goes to catch statement with error This file is empty or invalid. and function1 completes.when function2 is called and it works with big data, it is throwing
An unhandled exception of type 'System.AccessViolationException' occurred in Grib.Api.dll
Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
function2 has not any call to gribFile
if you can replicate this case please resolve this issue, i am using V6.0.3, sounds like jump to catch does not dispose gribFile completly Thank you