08-13-2010 09:45 AM
Hello everybody,
I have created a .NET Controller succesfully from an assembly written in C# I got.
I called the Initialize_...( ) and the Close_...( ) routine which seem to work fine.
Now I'm trying to call in between this two functions another function that should initialize a driver and needs CDotNetHandle *Exception_Handle as a parameter.
I declared this parameter with
CDotNetHandle *Exception_Handle;
But now i get the error:
Local 'Exception_Handle' was referenced before being initialized.
Now how and with which value do I initialize this pointer?
Pls be detailed as my C knowledge is a little bit rusty
Solved! Go to Solution.
08-13-2010 09:58 AM
Hello daeda -
You will actually want to declare an instance of a CDotNetHandle and then pass the address of this instance to the call - as below:
You should check out the example genericlist for further demonstration of this. There are multiple other examples located in the samples\dotnet folder that should be helpful to you.
NickB
National Instruments
08-16-2010 03:53 AM
Hi thank you for your fast answer. I had a look at the generic list example and other things I found in the help/find exeamples area.
But now when I try to call the function I get an error concerning the function call.
Is there any mistake I made or does the assembly has some problems beeing called from C?
Here is the error
Function CDotNetInvokeGenericStaticMember: (return value == -6571 [0xffffe655]
Here is my code I removed some other code that I know is working
void main(int argc, char **argv); void main(int argc, char **argv) { // Exception handles für die DotNet Bibliothek static CDotNetHandle exception = 0; // Muss aufgerufen werden bevor etwas aus der .NET Assembly aufgerufen werden kann Initialize_RmIntAdapter (); // startet und initialisiert die Bibliothek RmIntAdapter_RmIntAdapterCtrl_Start (&exception); // Schließt die Library wieder Close_RmIntAdapter (); exit(1); }
08-17-2010 09:22 AM
Hmmm... It looks like your assembly is throwing an exception on the call to Start. Error -6571 indicates that the assembly you're calling has thrown an exception. Because you know this, you can check the exception object from CVI to see if you can get some more information, with code something like the following:
Let me know if this doesn't help solve things.
NickB
National Instruments
08-17-2010 10:01 AM
Ok I will try this tomorrow.
During my research I found someone that had a simililar problem.
May this whole thing has something to do with the fact that my assembly is not in the GAC and not signed?
08-18-2010 03:37 AM
So here is the message I get when I use your code
Exception occurred!
The message is Der Typeninitialisierer f³r "RmIntAdapter.RmIntAdapterCtrl" hat eine Ausnahme verursacht.
The source is RmIntAdapter
The stack trace is bei RmIntAdapter.RmIntAdapterCtrl.Start()
This is in german since the assembly is written by a german developer
Exception occurred!
The message is The type initializer for "RmIntAdapter.RmIntAdapterCtrl" has caused an exception
The source is RmIntAdapter
The stack trace is at RmIntAdapter.RmIntAdapterCtrl.Start()
08-18-2010 08:49 AM
Based on that exception, my guess is that the assembly you're loading has dependencies that can't be found. They are likely in the same folder as the assembly you're loading, but because you're application is not in that same folder, the CLR has no way of finding them. You can verify this by checking the fusion logs generated durning the assembly binding process.
If my guess is correct, the easiest way to solve what you're seeing is to either strongly name all of your assemblies and place them in the GAC, or move your CVI application into the same directory as all the assemblies it depends on.
NickB
National Instruments
08-19-2010 03:46 AM
This seemed to be one problem.
Now I added all files I have in the folder where my project is, this leads to disappearing of this initializing problem on the one hand.
But also leads to a new error which isn't helping me either.
FATAL-RUN-TIME ERROR
Unknown source position, thread id 0x00000E34
A non-debuggable thread caused a 'Unknown' fault at address 0x7C812AFB
08-19-2010 04:43 AM
Ok it seems like I got this thing to work.
I guess this error occurs due to the fact that the dll is not debuggable since this happens when I press the green button "debug project".
If I only build a debuggable executable and don't start it from the Labwindows IDE but by executing the exe in the windows explorer it runs smoothly.
Do I have to talk to the dll programmers and ask them to recompile the dlls as debuggable or do I have to make some changes to my settings in LabWindows.