type initializer for 'win32DllPINVOKE' threw an exception

sam ch <[email protected]>
Newsgroups gmane.comp.windows.dotnet.nant.user
Message-ID <[email protected]>
Hello,

I am new to swig and I am attempting to use it by first creating a simple project. Everything compiled correctly, but I get an exception while running. I believe it is something simple, but I am just not sure where to look. Any tips would be appreciated, thanks.


joe

STEPS I TOOK:

1. Within VS2005, created a new C++ Win32 DLL project called "win32Dll"
2. Added code files "code.h" and "code.cpp"
3. Within the "code" files, created a function called "getNumber()" which returns an integer 5
    int getNumber(){
        return 5;
    }
??? Note: I originally had "__declspec(dllexport)" in the function declaration but received an error ("code.h:3: Error: Syntax error in input(1).") ???
4. Built the project which created a "win32Dll.dll"
5. Created "win32_dll.i" which just referenced "code.h"
6. Within Cygwin, ran "swig -csharp -c++ win32_dll.i"
7. Within the "VSS Command Prompt", ran "csc /target:library /out:win32 Dll_wrap.dll *.cs" which resulted in "Dll_wrap.dll" being created
8. Created a new C# project called "dllTester" and set it as the startup project
9. Added a reference to "Dll_wrap.dll" and called "win32Dll.getNumber()"

Error result: "The type initializer for 'win32DllPINVOKE' threw an exception." with InnerException.Message "The type initializer for 'win32DllPINVOKE' threw an exception."

***Note: To ensure that my DLL actually works, I was able to get to the function to work through InteropServices. 



      

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.