Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Common Language Runtime detected an invalid program.

I have an app that reads and writes to both digital and analog IO, and it keeps getting stuck.  This is my first NI app so I would believe that I am doing something wrong, but I do not know what.  What happens is that the code gets this far...

 

lock (locker)
{
try
{
using (Task myTask = new Task())
{
myTask.AOChannels.CreateVoltageChannel(pathToChannel, "aoChannel" + pathToChannel.Substring(pathToChannel.Length - 1, 1), 0.0, 10.0, AOVoltageUnits.Volts);  <-HERE
AnalogSingleChannelWriter writer = new AnalogSingleChannelWriter(myTask.Stream);
writer.WriteSingleSample(true, Voltage);
}
}
catch (DaqException ex)
{
MessageBox.Show(ex.Message);
}
}

And then does not return.  Then, any subsequent attempts to communicate with the NI chassis (DOChannels.CreateChannel(pathtoNI9472 + ":7", "", ChannelLineGrouping.OneChannelForAllLines); for example) , return the following exception

 

System.InvalidProgramException was unhandled
HResult=-2146233030
Message=Common Language Runtime detected an invalid program.
Source=NationalInstruments.DAQmx
StackTrace:
at nNIMSAI100.tTaskSyncManager.getInstance()
at NationalInstruments.DAQmx.Channel..ctor(Task task, tCaseInsensitiveBasicString<unsigned short\,_STL::char_traits<unsigned short>\,_STL::allocator<unsigned short>\,nNIDMXS100::tLocaleConsideringWideStringComparitor\,nNIDMXS100::tLocaleConsideringWideStringCaseForcer>* virtualChannelName, tCaseInsensitiveBasicString<unsigned short\,_STL::char_traits<unsigned short>\,_STL::allocator<unsigned short>\,nNIDMXS100::tLocaleConsideringWideStringComparitor\,nNIDMXS100::tLocaleConsideringWideStringCaseForcer>* physicalChannelName, Int32 usageType, tChannelType channelType, tLineGrouping lineGrouping, tCaseInsensitiveBasicString<unsigned short\,_STL::char_traits<unsigned short>\,_STL::allocator<unsigned short>\,nNIDMXS100::tLocaleConsideringWideStringComparitor\,nNIDMXS100::tLocaleConsideringWideStringCaseForcer>* customScaleName)
at NationalInstruments.DAQmx.DOChannel..ctor(Task task, tCaseInsensitiveBasicString<unsigned short\,_STL::char_traits<unsigned short>\,_STL::allocator<unsigned short>\,nNIDMXS100::tLocaleConsideringWideStringComparitor\,nNIDMXS100::tLocaleConsideringWideStringCaseForcer>* virtualChannelName, tCaseInsensitiveBasicString<unsigned short\,_STL::char_traits<unsigned short>\,_STL::allocator<unsigned short>\,nNIDMXS100::tLocaleConsideringWideStringComparitor\,nNIDMXS100::tLocaleConsideringWideStringCaseForcer>* physicalChannelName, tLineGrouping lineGrouping)
at NationalInstruments.DAQmx.DOChannelCollection.CreateChannel(String lines, String nameToAssign, ChannelLineGrouping grouping)
at BalanceBoard.Calibrator.frmMain.EngageCylinders(Boolean Engage) in c:\Sandbox\balanceboard\src\BalanceBoard.Calibrator\frmMain.cs:line 47
at BalanceBoard.Calibrator.frmMain.btnToggle_Click(Object sender, EventArgs e) in c:\Sandbox\balanceboard\src\BalanceBoard.Calibrator\frmMain.cs:line 361
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at BalanceBoard.Calibrator.Program.Main() in c:\Sandbox\balanceboard\src\BalanceBoard.Calibrator\Program.cs:line 18
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:

 

What's going on?

 

Thanks,

-Seth

0 Kudos
Message 1 of 4
(6,505 Views)

Seth, this person solved this issue by unchecking "code optimization" in Visual Studio.

Please read through this post and make sure all of your software is up to date, including DAQmx and Measurement Studio.

 

http://stackoverflow.com/questions/23563299/invalidprogramexception-common-language-runtime-detected...

 

-CB

Casey B.
Applications Engineer
National Instruments
0 Kudos
Message 2 of 4
(6,490 Views)

Thanks for the reply.  I just realized that using visual studio is not the same as Measurement Studio.  in VS, "code optimization" has always been unchecked.  I have udapted everything I know how to.  The samples work, but when I cpy that code into my solution, it does not.  I still think I may be using it wrong....  I have 4 modules.  Digital I and O, analog I and O.  Is there a good example of how to repeatadly get and set analog and digital values from them?  The examples I have seen create a new task each time they want a reading.  Is that best practice?

 

Thanks,

-Seth

0 Kudos
Message 3 of 4
(6,464 Views)

I kinfd of "figured it out".  It was acting too fast.  I had a routine in my form initialization that cleared my values and set them back to 0.  If I moved that clearing routine from frmLoad to a Click event, it started working.  

 

My question still stand tho about a best practices example for multiple mods and lots of IO.

 

Thanks!

0 Kudos
Message 4 of 4
(6,461 Views)