# Error when opening DeviceFactory: RuntimeError C-API call failed, LoadImageFileW

**URL:** <https://forum.commonvisionblox.com/t/error-when-opening-devicefactory-runtimeerror-c-api-call-failed-loadimagefilew/796>\
**Category:** Python API\
**Created:** [May 28, 2019, 7:55am UTC](https://forum.commonvisionblox.com/t/error-when-opening-devicefactory-runtimeerror-c-api-call-failed-loadimagefilew/796 "2019-05-28T07:55:05Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tom](https://avatars.discourse-cdn.com/v4/letter/t/3d9bf3/32.png) [@Tom](https://forum.commonvisionblox.com/u/Tom)\
**Post date:** [May 28, 2019, 7:55am UTC](https://forum.commonvisionblox.com/t/error-when-opening-devicefactory-runtimeerror-c-api-call-failed-loadimagefilew/796/1 "2019-05-28T07:55:05Z")

</div>

Hello,

I am trying to connect a camera via the CVB Python wrapper.

When I start with the following simple Python code…

```
import cvb
GenICamDevice = cvb.DeviceFactory.open(cvb.install_path()+"/Drivers/GenICam.vin")

```

, I very often (and sometimes very persistently) get the following error message:

```
Traceback (most recent call last):

  File "<ipython-input-3-bcd6810e309b>", line 1, in <module>
    GenICamDevice = cvb.DeviceFactory.open(cvb.install_path()+"/Drivers/GenICam.vin")

RuntimeError: {C-API call failed} ({LoadImageFileW})

```

The installation was done according to the example in this forum. It has also already worked before, so the camera and / or installation seems _principally_ correct.  
Running the CVB Management Console shows, that the camera is working (sending images).

Can anybody help me, solving the problem? Do you need more information?

My system:  
Win 10  
Python 3.6.5 (run via Spyder)  
Common Vision Blox Bindings 1.00.000 (x64)  
CommonVisionBlox 13.01.006 (x64).exe  
Camera (Dalsa Nano) connected via GigE and PoE injector

---

<div class="post-metadata">

**Author:** ![Chris](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.commonvisionblox.com/chris/32/1154_2.png) [@Chris](https://forum.commonvisionblox.com/u/Chris)\
**Post date:** [May 28, 2019, 12:34pm UTC](https://forum.commonvisionblox.com/t/error-when-opening-devicefactory-runtimeerror-c-api-call-failed-loadimagefilew/796/2 "2019-05-28T12:34:55Z")

</div>

Hi Tom,

welcome to our forum.

One obvious question first:  
When you run your code, are all other applications that could possibly block the driver closed (eg. ManagementConsole)?

Cheers  
Chris

---

<div class="post-metadata">

**Author:** ![Tom](https://avatars.discourse-cdn.com/v4/letter/t/3d9bf3/32.png) [@Tom](https://forum.commonvisionblox.com/u/Tom)\
**Post date:** [May 28, 2019, 1:21pm UTC](https://forum.commonvisionblox.com/t/error-when-opening-devicefactory-runtimeerror-c-api-call-failed-loadimagefilew/796/3 "2019-05-28T13:21:09Z")

</div>

Hi Chris,

Currently (after a complete restart) it’s working (with ManagementConsole closed).  
But before I tried it both with and without ManagementConsole.

I figured that after startup of the computer, I can only run my test program after I had made a quick shot with the ManagementConsole before.  
And after stopping a Python code, it can be only re-run without above error, after killing the Python interpreter.

Could it be that there are still processes running in the background? If so, can I identify them somehow?

Best wishes and thanks for your help,  
Tom

---

<div class="post-metadata">

**Author:** ![Chris](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.commonvisionblox.com/chris/32/1154_2.png) [@Chris](https://forum.commonvisionblox.com/u/Chris)\
**Post date:** [May 28, 2019, 3:03pm UTC](https://forum.commonvisionblox.com/t/error-when-opening-devicefactory-runtimeerror-c-api-call-failed-loadimagefilew/796/4 "2019-05-28T15:03:41Z")

</div>

Do you launch your application from autostart?

---

<div class="post-metadata">

**Author:** ![Tom](https://avatars.discourse-cdn.com/v4/letter/t/3d9bf3/32.png) [@Tom](https://forum.commonvisionblox.com/u/Tom)\
**Post date:** [May 29, 2019, 5:13am UTC](https://forum.commonvisionblox.com/t/error-when-opening-devicefactory-runtimeerror-c-api-call-failed-loadimagefilew/796/5 "2019-05-29T05:13:05Z")

</div>

No, from within Spyder (Python IDE).

---

<div class="post-metadata">

**Author:** ![Andreas](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.commonvisionblox.com/andreas/32/75_2.png) [@Andreas](https://forum.commonvisionblox.com/u/Andreas)\
**Post date:** [May 29, 2019, 6:14am UTC](https://forum.commonvisionblox.com/t/error-when-opening-devicefactory-runtimeerror-c-api-call-failed-loadimagefilew/796/6 "2019-05-29T06:14:58Z")

</div>

Hi @Tom

As the error says the call fails at the C-API level. Therefore it is most likely that it has nothing to do with Python in general.

But as you wrote:

> [@Tom](#):
>
> Could it be that there are still processes running in the background? If so, can I identify them somehow?

Unfortunately that is quite common as Python and especially Spider is not very transparent about resource management. I suggest using the the “with” statement.

```python
with cvb.DeviceFactory.open(...) as device:
  pass # do something with the device here, the device will be closed after you left the with scope

```

For a quick check if the device is accessible you can run GenICam Browser to discover devices, a red camera icon indicates that the device is currently inaccessible.

---

<div class="post-metadata">

**Author:** ![Tom](https://avatars.discourse-cdn.com/v4/letter/t/3d9bf3/32.png) [@Tom](https://forum.commonvisionblox.com/u/Tom)\
**Post date:** [June 6, 2019, 2:19pm UTC](https://forum.commonvisionblox.com/t/error-when-opening-devicefactory-runtimeerror-c-api-call-failed-loadimagefilew/796/7 "2019-06-06T14:19:39Z")

</div>

Hi Andreas,

Opening with the “with” statement works without errors. So the problem is solved.

Thanks,  
Tom

---

<div class="post-metadata">

**Author:** ![jolewen](https://avatars.discourse-cdn.com/v4/letter/j/7ab992/32.png) [@jolewen](https://forum.commonvisionblox.com/u/jolewen)\
**Post date:** [August 19, 2020, 10:50am UTC](https://forum.commonvisionblox.com/t/error-when-opening-devicefactory-runtimeerror-c-api-call-failed-loadimagefilew/796/8 "2020-08-19T10:50:37Z")

</div>

I know it is late, but maybe it helps:  
the connection needs to be closed properly for Python to reopen it later.

```
device = cvb.DeviceFactory.open(cvb.install_path() + "/drivers/GenICam.vin")
img_stream = device.stream
img_stream.start()
img_stream.stop()
device.close()

```

this works fine for me

---

<div class="post-metadata">

**Author:** ![Tom](https://avatars.discourse-cdn.com/v4/letter/t/3d9bf3/32.png) [@Tom](https://forum.commonvisionblox.com/u/Tom)\
**Post date:** [August 19, 2020, 11:29am UTC](https://forum.commonvisionblox.com/t/error-when-opening-devicefactory-runtimeerror-c-api-call-failed-loadimagefilew/796/9 "2020-08-19T11:29:22Z")

</div>

Thanks for the answer! I’ll try it ASAP (I currently don’t have access to the camera).

---

<div class="post-metadata">

**Author:** ![fang](https://avatars.discourse-cdn.com/v4/letter/f/96bed5/32.png) [@fang](https://forum.commonvisionblox.com/u/fang)\
**Post date:** [December 17, 2021, 8:02am UTC](https://forum.commonvisionblox.com/t/error-when-opening-devicefactory-runtimeerror-c-api-call-failed-loadimagefilew/796/10 "2021-12-17T08:02:36Z")

</div>

pip install cython  
work for me 😉

---

<div class="post-metadata">

**Author:** ![kreinert](https://avatars.discourse-cdn.com/v4/letter/k/e9c0ed/32.png) [@kreinert](https://forum.commonvisionblox.com/u/kreinert)\
**Post date:** [June 23, 2022, 9:27am UTC](https://forum.commonvisionblox.com/t/error-when-opening-devicefactory-runtimeerror-c-api-call-failed-loadimagefilew/796/11 "2022-06-23T09:27:40Z")

</div>

Hello guys,

I am having the same issue that @Tom described, however none of the proposed solutions have fixed my problem. My error message also is less specific.

```auto
RuntimeError Traceback (most recent call last)
<ipython-input-11-efb389850ddd> in <module>
----> 1 with cvb.DeviceFactory.open(cvb.install_path() + "drivers\GenICam.vin") as device:
      2 pass
RuntimeError: C-API call failed

```

I am working in JupyterLab instead of Spyder.  
The camera I am trying to find is connected by USB and shows up green when I check in the ManagementConsole.  
Other cvb functions seem to be working just fine.

Thanks,  
Kyra

---

<div class="post-metadata">

**Author:** ![illusive](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.commonvisionblox.com/illusive/32/61_2.png) [@illusive](https://forum.commonvisionblox.com/u/illusive)\
**Post date:** [June 23, 2022, 9:49am UTC](https://forum.commonvisionblox.com/t/error-when-opening-devicefactory-runtimeerror-c-api-call-failed-loadimagefilew/796/12 "2022-06-23T09:49:04Z")

</div>

Can you try with `"drivers\\GenICam.vin"` instead (double backslash)?

---

<div class="post-metadata">

**Author:** ![kreinert](https://avatars.discourse-cdn.com/v4/letter/k/e9c0ed/32.png) [@kreinert](https://forum.commonvisionblox.com/u/kreinert)\
**Post date:** [June 23, 2022, 10:40am UTC](https://forum.commonvisionblox.com/t/error-when-opening-devicefactory-runtimeerror-c-api-call-failed-loadimagefilew/796/13 "2022-06-23T10:40:35Z")

</div>

Thanks for the quick reply!

Sadly neither `"drivers\\GenICam.vin"` nor `"\drivers\\GenICam.vin"`changes anything.

If anyone has an idea where I should be looking to find the cause of the issue (file paths, module documentation, etc.) that would also be incredible helpful.

---

<div class="post-metadata">

**Author:** ![illusive](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.commonvisionblox.com/illusive/32/61_2.png) [@illusive](https://forum.commonvisionblox.com/u/illusive)\
**Post date:** [June 23, 2022, 12:58pm UTC](https://forum.commonvisionblox.com/t/error-when-opening-devicefactory-runtimeerror-c-api-call-failed-loadimagefilew/796/14 "2022-06-23T12:58:05Z")

</div>

I assume this is running on Windows. I would then expect `cvb.install_path()` to point to something like C:\Program Files\STEMMER IMAGING\Common Vision Blox\ (mind the trailing `\\` and the double backslashes). If you can confirm that for your system then I would expect `"Drivers\\GenICam.vin"` to work (upper/lower case should not be an issue).

Just to be sure: You did configure and save a suitable “GenICam.ini” file with the GenICamBrowser? That is actually needed for this approach to opening. And the GenICamBrowser is closed when you call `open`?

---

<div class="post-metadata">

**Author:** ![kreinert](https://avatars.discourse-cdn.com/v4/letter/k/e9c0ed/32.png) [@kreinert](https://forum.commonvisionblox.com/u/kreinert)\
**Post date:** [June 29, 2022, 7:47am UTC](https://forum.commonvisionblox.com/t/error-when-opening-devicefactory-runtimeerror-c-api-call-failed-loadimagefilew/796/15 "2022-06-29T07:47:37Z")

</div>

I am running everything on Windows and `print(cvb.install_path())` returns  
`"C:\Program Files\STEMMER IMAGING\Common Vision Blox\"` just like you said.

I didn’t explicitly configured the file by hand, but there is a “GenICam.ini” at the end of the file path `"C:\ProgramData\STEMMER IMAGING\Common Vision Blox\Drivers"`.  
The camera I want to use shows up and is green in the GenICamBrowser.

And yes, the GenICamBrowser is closed while I am trying to access the camera.

---

<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:** [June 29, 2022, 9:17am UTC](https://forum.commonvisionblox.com/t/error-when-opening-devicefactory-runtimeerror-c-api-call-failed-loadimagefilew/796/16 "2022-06-29T09:17:12Z")

</div>

Hi @kreinert ,

it is not sufficient that the camera is visible on the **left hand** side in the GCBrowser. What is needed (and what @illusive meant) is the configuration of that device into the **right hand** section called **“Configured Devices”**

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

Try to

- right click on the device in the “Available Devices” section
- then select “Add to configured devices” and finally
- hit the Save button in the Configured Devices section (see yellow marked button in the image)  
 ![image](https://canada1.discourse-cdn.com/flex027/uploads/commonvisionblox/original/2X/8/8a6276cf6ce17692f006166cb45cb884c014b526.png)

As a result, the Genicam.ini is filled with the required information to open the driver from software. Retry your python script.

---

<div class="post-metadata">

**Author:** ![kreinert](https://avatars.discourse-cdn.com/v4/letter/k/e9c0ed/32.png) [@kreinert](https://forum.commonvisionblox.com/u/kreinert)\
**Post date:** [June 30, 2022, 7:10am UTC](https://forum.commonvisionblox.com/t/error-when-opening-devicefactory-runtimeerror-c-api-call-failed-loadimagefilew/796/17 "2022-06-30T07:10:09Z")

</div>

Thanks for the advice @illusive and @s-woe, turns out i was missing the actual configuration because I had an issue actually saving the configuration file.  
Once that issue was resolved, the configuration could be saved and the  
`RuntimeError: C-API call failed` disappeared.

The program still freezes and doesn’t do what it is supposed to, but that is a problem for another thread.

---

<div class="post-metadata">

**Author:** ![kreinert](https://avatars.discourse-cdn.com/v4/letter/k/e9c0ed/32.png) [@kreinert](https://forum.commonvisionblox.com/u/kreinert)\
**Post date:** [July 7, 2022, 7:39am UTC](https://forum.commonvisionblox.com/t/error-when-opening-devicefactory-runtimeerror-c-api-call-failed-loadimagefilew/796/18 "2022-07-07T07:39:36Z")

</div>

After a lot of trial and error, I wanted to add what I have figured out in the hopes that it might save someone with the same problem a lot of time.

It turns out that my program only works on the first run after the camera is plugged into the computer. I am opening the camera in a `with` statement.

If I restart the kernel or simple try to run the cell that opens the device again, it throws the `RuntimeError: C-API call` described above.

---

<div class="post-metadata">

**Author:** ![c.hartmann](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.commonvisionblox.com/c.hartmann/32/247_2.png) [@c.hartmann](https://forum.commonvisionblox.com/u/c.hartmann)\
**Post date:** [July 7, 2022, 3:56pm UTC](https://forum.commonvisionblox.com/t/error-when-opening-devicefactory-runtimeerror-c-api-call-failed-loadimagefilew/796/19 "2022-07-07T15:56:24Z")

</div>

Did/Do you by any change abort the execution of the program, i.e. during a successful run?  
Or another execption is uncatched?  
Or does it exit normally?

Background for this question is, that a camera depending on the camera technology might be in an undefined state, if an appliction uses the camera crashes.  
I.e. catch all exceptions.  
However this is an assuption, not really sure if this relates to your issue.

---

<div class="post-metadata">

**Author:** ![kreinert](https://avatars.discourse-cdn.com/v4/letter/k/e9c0ed/32.png) [@kreinert](https://forum.commonvisionblox.com/u/kreinert)\
**Post date:** [July 14, 2022, 8:35am UTC](https://forum.commonvisionblox.com/t/error-when-opening-devicefactory-runtimeerror-c-api-call-failed-loadimagefilew/796/20 "2022-07-14T08:35:36Z")

</div>

At the moment the image processing code takes only a file as input and doesn’t have anything to do with accessing the camera. I do not throw any exceptions in my code.  
I am opening the device using a `with` statement, and I am manually aborting the stream afterwards (see below).  
Does `stream.abort()` not release the camera? What should I be using instead?

```auto
with cvb.DeviceFactory.open("C:\Program Files\STEMMER IMAGING\Common Vision Blox\Drivers\GenICam.vin") as device:
    stream = device.stream()
    stream.start()
    
    image, status = stream.wait()
    if status == cvb.WaitStatus.Ok:  
        image.save("acquired_image.jpg")
        # image processing code:
        ri_1 = rip.rectangle_image("acquired_image.jpg")
        ri_1.evaluate_image(high_threshold=200, low_threshold=100)
        
    stream.abort()

```

[Next page](https://forum.commonvisionblox.com/t/error-when-opening-devicefactory-runtimeerror-c-api-call-failed-loadimagefilew/796.md?page=2)
