简体   繁体   中英

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."}

可能要迟了,但我刚刚通过的解决方案是将所有Dll(复制自gdcm building bin文件夹)复制到bin \\ debug或release文件夹

  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"

它通过将目标框架从4.5更改为4.0为我工作

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM