David
David

Reputation: 21

System.TypeInitializationException: 'The type initializer for 'Teigha.Core.GlobalsPINVOKE' threw an exception.'

I'm developing a C# desktop application that uses C++ dll's. I'm facing an issue that I cant resolve:

System.TypeInitializationException: 'The type initializer for 'Teigha.Core.GlobalsPINVOKE' 
threw an exception.'
1 of 2 Inner Exceptions:
TypeInitializationException: The type initializer for 'SWIGExceptionHelper' threw an 
exception.
2 of 2 Inner Exceptions:
DllNotFoundException: Unable to load dll 'TD_SwigCore_22.7_16.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E).
  1. My first try was to add the dll by going to project reference -> add reference but then I go a error message:

    A reference to C:\blablabla\TD_SwigCore_22.7_16.dll could not be added. Please make sure that the file is accessible, and that it is a valid assembly or COM component.

  2. Second try was to try it with DllImport as described here: https://learn.microsoft.com/en-us/dotnet/api/system.runtime.interopservices.dllimportattribute?redirectedfrom=MSDN&view=net-5.0 I get a compiler error:

    C50592: Attribute #dllImport' is not valid on this declaration type. it is only valid on 'method' declarations.

  3. Third try was to use regsvr32 as explained as one of the possible solutions on: How do I resolve "Please make sure that the file is accessible and that it is a valid assembly or COM component"?

    regsvr32 "C:\blablabla\TD_SwigCore_22.7_16.dll"

    And got the error message:

    the module "C:\blablabla\TD_SwigCore_22.7_16.dll" was loaded but the entry-point DllRegisterServer was not found. Make sure that "C:\blablabla\TD_SwigCore_22.7_16.dll" is a valid DLL or OCX file and then try again

  4. My fourth and last try was to find out what all dependencies of my 'TD_SwigCore_22.7_16.dll' are, and I have done it like this:

    dumpbin /DEPENDENTS "C:\blablabla\TD_SwigCore_22.7_16.dll"

    and I have gotten a list with all dependencies, and then I have added all those dll's in the folder bin\x64\Debug as explained in one of the stack overflow solutions, but I still got the same error.

By now I feel like I have tried all solutions that I can find on the internet, but nothing works. It is important to know that my program works perfectly fine on release mode, only not on debug mode.

Target framework is: .NET Framework 4.8

And help would be appreciated!

Upvotes: 1

Views: 1068

Answers (1)

David
David

Reputation: 21

The solution was in the project settings under debug more the wrong folder was chosen. I chose the folder (same as for release) with all the dll's and it worked.

Upvotes: 1

Related Questions