user4598741
user4598741

Reputation: 11

The type initializer for 'gdcm.gdcmPINVOKE' threw an exception

first time for using gdcm in c# has an exception in the first line. please, any help

gdcm.ImageReader gReader = new gdcm.ImageReader();
gReader.SetFileName(inputFile);

the error is: The type initializer for 'gdcm.gdcmPINVOKE' threw an exception

innerException is: {"The type initializer for 'SWIGExceptionHelper' threw an exception."}

Upvotes: 1

Views: 3117

Answers (4)

malat
malat

Reputation: 12496

From the FAQ:

dllnotfound exceptions

If you get dllnotfound exceptions, then that means that you didn't copy over the newly made dlls in steps 6 and 7.

This is a general error which means that a dll that's used by the executable hasn't been found. It does not necessarily mean that the dll which is directly referenced is the problem. Typically, if you didn't copy over the gdcm.dll and associated libraries, but have set gdcmsharpglue.dll as one of your program references, you'll get this error. It doesn't mean that gdcmsharpglue is missing, it means that an underlying library is missing.

For finding out which dll is missing, try using Dependency Walker. This program will find the missing library, and then you can put it in the path of the executable.

One way around this problem is to set up an 'includes' directory in your application tree (assuming you're in Windows, not Mono-- Mono may be different) which contains the gdcm libraries. From there, you can make a post-build event for your project, so files get copied when you do a build. This approach takes some time each time you do a build, but saves time when you are trying to figure out where your libraries are and why you're getting dll not found exceptions.

  1. open your solution
  2. right click on your project
  3. select 'build events' (third tab down from the top)
  4. put some dos commands in the 'post-build event command line' box. I have
mkdir Debug
mkdir Release
copy ..\..\..\Includes\gdcm\*.dll ..\Debug\*.dll
copy ..\..\..\Includes\gdcm\*.dll ..\Release\*.dll

The two mkdir's in there so that if you're rebuilding from scratch, you don't get an error on build. That is, if you're building debug and you don't have a release directory, the copy lines give you an error. If you don't copy to both directories, when you go to build your release build after working in debug all this time, your release build won't work and you'll be really frustrated when you figure out you forgot to copy the dll's to both release and debug.

Upvotes: 0

mahmoud nezar sarhan
mahmoud nezar sarhan

Reputation: 756

it worked for me by changing the target framework from 4.5 to 4.0

Upvotes: 0

Constantine
Constantine

Reputation: 1

  1. make progect.
  2. copy ALL dlls from gdcm bin/release into your debug/release project folder
  3. add to referese gdcm-sharp from your debug/release project folder. If its work try with another folder
  4. In "Solution Platforms" (i use Visual Studio 2015) set x86 or x64 (or create. Copy settings from "Any CPU")
  5. run.
  6. you are awesome!

PS When i build GDCM i not pay attention that build it for Win32, but try to build for "Any CPU"

Upvotes: 0

AMH
AMH

Reputation: 6451

may be to late, but I just passed by this the solution is to copy all the Dlls (fromd gdcm building bin folder ) to your bin\debug or release folder

Upvotes: 2

Related Questions