How to Get a Unique Identifier for a Device Within Windows 10 Universal

Emgu.CV.CvInvoke' threw an exception

The following error: "An attempt was made to load a program with an incorrect format." is shown if the unmanaged assembly is compiled for different platform than your .NET code is currently executing on.

For example:
take some dll that is compiled for x86, import some function call to C# and run. If you have 64-bit Windows this will fail, because .NET code is compiled to x64.

To overcome this you have two possibilities:
1) to use unmanaged dll version that matches your platform
2) Project -> Properties -> Build -> tick the platform that matches the platform for which an unmanaged dll is compiled (x86, x64) (it is probably set to Any CPU).


Copy your unmanaged dlls into \bin\Debug and/or \bin\Release project, not into some subfolder!!
If you really want to use dlls from some subfolder, than edit the process environment variable like this:

Environment.SetEnvironmentVariable(path, Environment.GetEnvironmentVariable(path) + Path.PathSeparator + );

this will add your subfolder into search path. This variable is process variable meaning that all changes will be undone when process stops executing.

Deploying OpenCV on Raspberry Pi 4 - The type initializer for 'Emgu.CV.CvInvoke' threw an exception

With Emgucv, the primary purpose of the library is to be a c# wrapper of the c++ library opencv. In order to make this work, you need the runtime package for the platform that you are coding on to be included in the references.

As of Febuary 2020, you will have to build the native binary for the Raspberry pie.

You can read more about the issue below.

https://github.com/emgucv/emgucv/issues/298



Related Topics



Leave a reply



Submit