# stream.Wait() Exception

**URL:** <https://forum.commonvisionblox.com/t/stream-wait-exception/2201>\
**Category:** .Net API\
**Tags:** csharp, acquisition, genicam\
**Created:** [July 25, 2024, 8:28am UTC](https://forum.commonvisionblox.com/t/stream-wait-exception/2201 "2024-07-25T08:28:16Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Danv](https://avatars.discourse-cdn.com/v4/letter/d/e9c0ed/32.png) [@Danv](https://forum.commonvisionblox.com/u/Danv)\
**Post date:** [July 25, 2024, 8:28am UTC](https://forum.commonvisionblox.com/t/stream-wait-exception/2201/1 "2024-07-25T08:28:16Z")

</div>

Hi,  
I am experiencing an issue with my GenICam camera.  
I encountered the following exception: “Native handle is not an IImageVPA type.” This error occurs on the line where I attempt to acquire an image using the `stream.Wait(out status)` method.

```auto
public void Test()
 {
     // discover devices
     try
     {
         using (var devices = DeviceFactory.Discover(DiscoverFlags.IgnoreVins))
         {
             // open first device
             using (var device = DeviceFactory.Open(devices[0], AcquisitionStack.GenTL))
             {
                 // start streaming
                 var stream = ((GenICamDevice)device).GetStream<ImageStream>(0);
                 stream.Start();

                 // acquire data
                 WaitStatus status;
                 using (var image = stream.Wait(out status))
                 {

                 }

                 // stop streaming
                 stream.Abort();
             }
         }
     }
     catch (Exception ex)
     {

     }
 }

```

 ![image](https://canada1.discourse-cdn.com/flex027/uploads/commonvisionblox/original/2X/1/1050369832bffcaaa71440e0a56f48e5da5127b6.png)

---

<div class="post-metadata">

**Author:** ![s-woe](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.commonvisionblox.com/s-woe/32/572_2.png) [@s-woe](https://forum.commonvisionblox.com/u/s-woe)\
**Post date:** [July 25, 2024, 10:53am UTC](https://forum.commonvisionblox.com/t/stream-wait-exception/2201/2 "2024-07-25T10:53:55Z")

</div>

Hi @Danv ,  
what camera do you use?  
When using ImageStream, you require the payload to be something, that is interpretable as a CVB Image.  
You could allow a more generic representation of returned payloads if you use a CompositeStream:

```auto
class SimpleStreamingGen3
{
  static void Main(string[] args)
  {
    using (var devices = DeviceFactory.Discover(DiscoverFlags.IgnoreVins))
    {
      using (var device = DeviceFactory.Open(devices[0], AcquisitionStack.GenTL))
      {
        var stream = ((GenICamDevice)device).GetStream<CompositeStream>(0);
        stream.Start();
        for (int i = 0; i < 10; i++)
        {
          WaitStatus status;
          using (var composite = stream.Wait(out status))
          {
            using (var nodeMaps = NodeMapDictionary.FromComposite(composite))
            {
              Console.WriteLine($"Acquired image: {i}");

              if (composite.Purpose == CompositePurpose.Image)
                Console.WriteLine("is image");
              else if (composite.Purpose == CompositePurpose.ImageList)
                Console.WriteLine("is image list");
              else if (composite.Purpose == CompositePurpose.MultiAoi)
                Console.WriteLine("is multi aoi");
              else if (composite.Purpose == CompositePurpose.RangeMap)
                Console.WriteLine("is range map");
              else if (composite.Purpose == CompositePurpose.PointCloud)
                Console.WriteLine("is point cloud");
              else if (composite.Purpose == CompositePurpose.ImageCube)
                Console.WriteLine("is image cube");
              else if (composite.Purpose == CompositePurpose.Custom)
                Console.WriteLine("is custom");
              else
                Console.WriteLine("is something else");
            }
          }
        }
        stream.Abort();
      }
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![Danv](https://avatars.discourse-cdn.com/v4/letter/d/e9c0ed/32.png) [@Danv](https://forum.commonvisionblox.com/u/Danv)\
**Post date:** [August 17, 2024, 5:34pm UTC](https://forum.commonvisionblox.com/t/stream-wait-exception/2201/3 "2024-08-17T17:34:11Z")

</div>

Hi @s-woe ,

I’m using a line scan hyperspectral camera that captures Mono16 frames with a resolution of 366x640 pixels (where the width represents physical pixels and the height represents spectral information per wavelength). After executing your code, I found that `composite.Purpose` is set to “custom.”

I’m looking for a way to directly access the image’s raw data using pointers or to copy the raw data into my own buffer. I attempted the following code:

```auto
var image = MultiPartImage.FromComposite(composite);
image.Planes[0].TryGetLinearAccess(out LinearAccessData imageData);
Marshal.Copy(imageData.BasePtr, _imageBuffer, 0, imageSize);

```

However, the line `var image = MultiPartImage.FromComposite(composite)` throws an exception: “Native handle is not an IImageVPA type.”

What should the correct code be to access the image raw data when the composite is custom?  
Thanks.

---

<div class="post-metadata">

**Author:** ![s-woe](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.commonvisionblox.com/s-woe/32/572_2.png) [@s-woe](https://forum.commonvisionblox.com/u/s-woe)\
**Post date:** [August 21, 2024, 8:53am UTC](https://forum.commonvisionblox.com/t/stream-wait-exception/2201/4 "2024-08-21T08:53:24Z")

</div>

The least you can expect, that is somehow interpretable would be a PFNCBuffer. Try to find it inside the composite. Then the last resort would be a Buffer.

---

<div class="post-metadata">

**Author:** ![Danv](https://avatars.discourse-cdn.com/v4/letter/d/e9c0ed/32.png) [@Danv](https://forum.commonvisionblox.com/u/Danv)\
**Post date:** [September 1, 2024, 8:03am UTC](https://forum.commonvisionblox.com/t/stream-wait-exception/2201/5 "2024-09-01T08:03:02Z")

</div>

Hi @s-woe,

Thanks for your help!  
The following code worked for me:

```auto
var imageData = Stemmer.Cvb.Driver.Buffer.FromHandle(composite[0].Handle, Stemmer.Cvb.Runtime.InteropServices.ShareObject.No);
Marshal.Copy(imageData.BasePtr, _imageBuffer[curIdx], 0, imageSize);

```

One last question if you don’t mind!

1. How does the `Stemmer.Cvb.Driver.Buffer.FromHandle` function work? Does it copy the original data, or does it just return a pointer to the original data?
2. I’m trying to work with the `BasePtr` directly to avoid unnecessary copying. There might also be situations where I need to work on 2-3 images in parallel. Is it possible to use a `FlowSetPool` mechanism to hold the buffers I receive from `Stemmer.Cvb.Driver.Buffer.FromHandle` in a collection and release them when they’re no longer needed by calling the `.Dispose()` method?  
Any advice about this?

---

<div class="post-metadata">

**Author:** ![Sebastian](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.commonvisionblox.com/sebastian/32/1267_2.png) [@Sebastian](https://forum.commonvisionblox.com/u/Sebastian)\
**Post date:** [September 2, 2024, 11:29am UTC](https://forum.commonvisionblox.com/t/stream-wait-exception/2201/6 "2024-09-02T11:29:26Z")

</div>

Hi Danv,

1. FromHandle does return the pointer to the original data
2. In your case you are already copying the image data which is not necessary at all. You can use the existing managed flow set pool (if you configured it big enough) and wait for all images you want to process in parallel. Then you can access them. To be sure that the internal flows are disposed to be able to be used for the next images you either should use a using block or call dispose on the returned imageData.
