HDFGroup / HDF.PInvoke

Raw HDF5 Power for .NET
http://www.hdfgroup.org/HDF5
Other
80 stars 29 forks source link

Issue with H5F.open #145

Closed raghu-iitm closed 4 years ago

raghu-iitm commented 6 years ago

Hello, I am creating a trial office VSTO project using HDF.PInvoke in VS2017 (vb.net). I have installed the HDF.PInvoke from NuGet. Unfortunately, I am struggling at opening the file itself. The code is throwing an exception as shown below. The funniest thing is that I do not see the same problem when I create a form application. Am I really missing something?. I am new to HDF.Pinvoke.

`Imports HDF.PInvoke Imports System.IO

Module ExtractHDF5Data

Public Sub hdftextract() Dim filename as String="E:\testfolder\test.h5" Dim fileId As Long = H5F.open(filename, H5F.ACC_RDONLY, H5P.DEFAULT) 'Code fails here End Sub

End Module`

The issue is same for Any CPU, x64, x86. Below is the exception.

System.TypeInitializationException HResult=0x80131534 Message=The type initializer for 'HDF.PInvoke.H5F' threw an exception. Source= StackTrace:

Inner Exception 1: EntryPointNotFoundException: Unable to find an entry point named 'H5open' in DLL 'hdf5.dll'.
gheber commented 6 years ago

What do you see when you run dumpbin /exports hdf5.dll | findstr H5open?

raghu-iitm commented 6 years ago

Here is the output of dumpbin /exports hdf5.dll | findstr H5open in the folders

....packages\HDF.PInvoke.1.10.2.0\build\bin64 2989 BAC 00003D41 H5open = @ILT+11580(H5open)

....packages\HDF.PInvoke.1.10.2.0\build\bin32 2989 BAB 00001C85 H5open = @ILT+3200(_H5open)

raghu-iitm commented 6 years ago

It looks like the issue is coming from H5P due to Static initialization. My code crashed with the following error

'H5P.FILE_ACCESS' threw an exception of type 'System.TypeInitializationException'

raghu-iitm commented 6 years ago

@gheber, I did thorough check of what could have gone wrong. The code crashes with the type initializer exception at line 38 of H5Pglobals.cs static readonly hid_t H5P_CLS_ROOT_g = H5DLLImporter.Instance.GetHid("H5P_CLS_ROOT_ID_g"); I believe it is mostly to do with the issue #96.

Etschbeijer commented 5 years ago

Hello, I have a similar error. I wanted to test some example code, in order to integrate an HDF5 reader into our F# library. When calling:

H5.open()

The following error is thrown:

System.EntryPointNotFoundException: Unable to find an entry point named 'H5open' in DLL 'hdf5.dll'. at HDF.PInvoke.H5.open() at <StartupCode$FSI_0003>.$FSI_0003.main@() in C:\Users\Student\source\repos\HDF5\HDF5\Script.fsx:line 21 Stopped due to error

I use Microsoft Visual Studio 2017; version 1.18.1104.625 The Nuget-Package: HDF.PInvoke V1.10.5.2 Microsoft Windows 10 Pro; 64 bit

Apollo3zehn commented 5 years ago

Maybe its a F# related issue. Are you using .NET Framework or .NET Core? If the latter, you may try HDF.PInvoke.1.10 which was published yesterday and which uses a different mechanism to find the native DLL.

Do you also have HDF installed in your computer? If yes, it may happen that the wrong DLL is loaded.

JanWosnitza commented 5 years ago

@Etschbeijer is your F# interactive running with 64bit? Default is 32bit AFAIK.

Etschbeijer commented 5 years ago

Hi, Sry, I forgot to answer, after I got the dll running I've got lost in work.... @Apollo3zehn I created a new solution based on .Net Framework and it worked with HDF.PInvoke V1.10.5.2 but not HDF.PInvoke.1.10 due to the same error message. Previous I used .NET Core. I am only using HDF View and not HDF.

@JanWosnitza I use Any CPU and I have no trouble reading whole data sets.

raghu-iitm commented 4 years ago

Hi, I am able to resolve the issue related to importing the HDF5 results into the Excel spreadsheet using C# wrappers. The issue with H5F.open was mainly due to MS Excel COM interface and it has nothing to do with HDF5.

The issue that I was not able to read before was due to the fact that the Workbook object of the MS Excel cannot be accessed after HDF5 is invoked. However, the WorkSheet Object can be accessed.

The solution I have found was that. The excel workbook and worksheet objects needs to be set before the H5P.create() call.

    Excel.Workbook wb = Globals.ThisAddIn.Application.ActiveWorkbook;
    Excel.WorkSheet ws = wb .ActiveSheet;

    hid_t faplist_id = H5P.create(H5P.FILE_ACCESS)

The data queried from the HDF5 results can be populated to excel worksheet using the worksheet object (ws in my case).

    ws.Cells[Row,Column].Value=someHDF5Value;

The below scenario will fail since the wb object is not accessible once HDF5 is invoked. wb.Worksheet["SomeSheetName"].Cells[Row,Column].Value=someHDF5Value; //Code fails

I tried various options like creating separate threads in Excel but nothing worked due to inaccessible workbook object. Finally, I am happy that we have a solution although it is a bit late.

gheber commented 4 years ago

Glad to hear that you were able to make it work and thank your for letting us know.