Apollo3zehn / PureHDF

A pure .NET library that makes reading and writing of HDF5 files (groups, datasets, attributes, ...) very easy.
MIT License
47 stars 16 forks source link

Trouble reading back a chunked 3D array of variable lists of structs #66

Closed marklam closed 3 months ago

marklam commented 3 months ago

I can write out a 3D array of variable-length lists of structs, but when I attempt to read them back I get an exception:

System.Reflection.TargetInvocationException
  HResult=0x80131604
  Message=Exception has been thrown by the target of an invocation.
  Source=System.Private.CoreLib
  StackTrace:
   at System.Reflection.MethodBaseInvoker.InvokeWithManyArgs(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) in /_/src/libraries/System.Private.CoreLib/src/System/Reflection/MethodBaseInvoker.cs:line 272
   at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) in /_/src/libraries/System.Private.CoreLib/src/System/Reflection/MethodBase.cs:line 56
   at PureHDF.VOL.Native.NativeDataset.Read[T](Selection fileSelection, Selection memorySelection, UInt64[] memoryDims, H5DatasetAccess datasetAccess) in /home/runner/work/PureHDF/PureHDF/src/PureHDF/VOL/Native/API.Reading/NativeDataset.cs:line 203
   at PureHDF.VOL.Native.NativeDataset.Read[T](Selection fileSelection, Selection memorySelection, UInt64[] memoryDims) in /home/runner/work/PureHDF/PureHDF/src/PureHDF/VOL/Native/API.Reading/NativeDataset.cs:line 161
   at Program.readBack@87-1.Invoke(Int32 j) in C:\Users\markl\source\repos\ConsolePureHDFroundtrip\ConsolePureHDFroundtrip\Program.fs:line 91
   at Program.readBack@85.Invoke(Int32 i) in C:\Users\markl\source\repos\ConsolePureHDFroundtrip\ConsolePureHDFroundtrip\Program.fs:line 86
   at <StartupCode$ConsolePureHDFroundtrip>.$Program.main@() in C:\Users\markl\source\repos\ConsolePureHDFroundtrip\ConsolePureHDFroundtrip\Program.fs:line 83

  This exception was originally thrown at this call stack:
    PureHDF.VFD.H5FileHandleDriver.ReadCore(System.Span<byte>) in H5FileHandleDriver.Reading.cs
    PureHDF.VFD.H5FileHandleDriver.ReadBytes(int) in H5FileHandleDriver.Reading.cs
    PureHDF.VOL.Native.GlobalHeapCollection.Decode(PureHDF.VOL.Native.NativeReadContext) in GlobalHeapCollection.cs
    PureHDF.VOL.Native.NativeCache.GetGlobalHeapObject(PureHDF.VOL.Native.NativeReadContext, ulong, bool) in NativeCache.cs
    PureHDF.VOL.Native.DatatypeMessage.GetDecodeInfoForVariableLengthSequence.__decode|0(PureHDF.IH5ReadStream) in DatatypeMessage.Reading.cs
    PureHDF.VOL.Native.DatatypeMessage.GetDecodeInfoForReferenceMemory.__decode|0(PureHDF.IH5ReadStream, System.Span<T>) in DatatypeMessage.Reading.cs
    PureHDF.Selections.SelectionHelper.DecodeStream<TResult>(System.Collections.Generic.IEnumerator<PureHDF.Selections.RelativeStep>, System.Collections.Generic.IEnumerator<PureHDF.Selections.RelativeStep>, PureHDF.Selections.DecodeInfo<TResult>, System.Span<TResult>) in SelectionHelper.cs
    PureHDF.Selections.SelectionHelper.Decode<TResult>(int, int, PureHDF.Selections.DecodeInfo<TResult>, System.Span<TResult>) in SelectionHelper.cs
    PureHDF.VOL.Native.NativeDataset.ReadCoreLevel3<TElement>(System.Span<TElement>, PureHDF.Selections.Selection, PureHDF.Selections.Selection, ulong[], ulong[], PureHDF.VOL.Native.H5DatasetAccess) in NativeDataset.cs
    PureHDF.VOL.Native.NativeDataset.ReadCoreLevel2<TElement>(PureHDF.Selections.Selection, PureHDF.Selections.Selection, ulong[], ulong[], System.Span<TElement>, PureHDF.VOL.Native.H5DatasetAccess) in NativeDataset.cs
    ...
    [Call Stack Truncated]

Inner Exception 1:
Exception: The file is too small

A project that shows the example is here:

https://github.com/marklam/Roundtrip3DArrayOfStructList

The writer gets disposed and the file closed before re-opening, so it shouldn't be that it was not fully written.

Apollo3zehn commented 3 months ago

Thanks for your report, I will check it later today

Apollo3zehn commented 3 months ago

Release v1.0.0-beta.8 should fix that problem. Thanks again for reporting :-)

Apollo3zehn commented 3 months ago

... will be on NuGet in a few minutes

marklam commented 3 months ago

It works (tested on my real code too). Outstanding! Thanks!