2

I have installed the latest OpenCVSharp 2 (2.4.10.201...) with the NuGet manager in my project. Everything concerning OpenCVSharp.CvMat is working OK (loading, manipulation etc) so I am sure the installation is correct.

However I cannot use OpenCVSharp.CPlusPlus at all! I am trying to simply create a Mat but to no avail:

using OpenCvSharp;
using OpenCvSharp.CPlusPlus;
using MyCVSharp;
using System.Diagnostics;
using System.Collections;

class MainClass
{
    static void Main()
    {
        Mat test3 = new Mat( new Size( 100, 100 ), MatType.CV_8UC1 ); // ERROR
        Mat test2 = new Mat( "f1.png", LoadMode.Color ); // ERROR

        CvMat test = new CvMat( "f1.png", LoadMode.Color ); //; THIS WORKS

The error is:

An unhandled exception of type 'System.TypeInitializationException' occurred in MyCVSharpTEST.exe

Additional information: The type initializer for 'OpenCvSharp.CPlusPlus.Mat' threw an exception.

Lots of dlls are deployed alongside my project. OpenCvSharp.CPlusPlus.dll and OpenCvSharp.dll are deployed in the same folder next to MyCVSharpTEST.exe, while a dll folder is created with x86 and x64 subfolders containing another 22 related dlls, each.

I have even tried creating a Mat from an already created CvMat but still, same error.

Edit: Error shown from try-catch block:

System.TypeInitializationException: The type initializer for 'OpenCvSharp.CPlusPlus.Mat' threw an exception. ---> System.DllNotFoundException: Unable to load DLL 'OpenCvSharpExtern': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
   at OpenCvSharp.CPlusPlus.NativeMethods.core_Mat_sizeof()
   at OpenCvSharp.CPlusPlus.Mat..cctor()
   --- End of inner exception stack trace ---
   at OpenCvSharp.CPlusPlus.Mat..ctor()
   at MainClass.Main() in C:\Users\kotsias\Documents\Visual Studio 2015\Projects\MyCVSharp\ConsoleApplication1\Test.cs:line 14

Since the problem now seems dll-related, I decided to write an all-new question about it.

Jeru Luke
  • 20,118
  • 13
  • 80
  • 87
Bill Kotsias
  • 3,258
  • 6
  • 33
  • 60
  • 1
    Can you show us inner exception? – Leonid Vasilev May 19 '17 at 13:57
  • @LeonidVasilyev Sorry, how can I show that with Visual Studio 2015? – Bill Kotsias May 19 '17 at 14:55
  • 1
    There are multiple ways to do that. You can wrap `new Mat()` with try-catch block, then launch your application with attached debugger and manually inspect `Exception.InnerException` property. Check [What is inner Exception?](http://stackoverflow.com/a/22826428/2594597) discussion, [try-catch](https://learn.microsoft.com/en-us/dotnet/articles/csharp/language-reference/keywords/try-catch) C# reference and [Managing Exceptions with the Debugger](https://msdn.microsoft.com/en-us/library/x85tt0dd.aspx) MSDN page. – Leonid Vasilev May 20 '17 at 17:06

0 Answers0