Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

NI DAQmx System.AccessVilolationException

Solved!
Go to solution

Hello all,

 

I've been developing an application using the NI DAQmx dll and have suddenly had issue with being able to interact with the DAQ (cDAQ-9174). The Examples that come with NI DAQmx .NET also fall over with the same exception. 

 

From Example in \National Instruments\NI-DAQ\Examples\DotNET4.5\Analog In\Measure Voltage\AcqOneVoltageSample\CS

physicalChannelComboBox.Items.AddRange(DaqSystem.Local.GetPhysicalChannels(PhysicalChannelTypes.AI, PhysicalChannelAccess.External));
if (physicalChannelComboBox.Items.Count > 0)
physicalChannelComboBox.SelectedIndex = 0;

 

The exception is thrown when I get to:

DaqSystem.Local.GetPhysicalChannels(PhysicalChannelTypes.AI, PhysicalChannelAccess.External)

 

Exception information:

System.AccessViolationException
HResult=0x80004003
Message=Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Source=<Cannot evaluate the exception source>
StackTrace:
<Cannot evaluate the exception stack trace>

 

I've been able to interact with the DAQ using NI MAX without any issues. I've tried reinstalling NI DAQmx using the NI Package Manager and this hasn't solved the issue.

 

Any help would be much appreciated.

 

Tom

0 Kudos
Message 1 of 6
(3,379 Views)

Hey Tom,

 

That's not something I've came across before, and there's limited info on that internally too.

My guess is that there's something in the stack that deals with locating physical channels that's having an error, typically through NI SystemConfig API.

 

Can you try resetting your MAX database? NI MAX -> Tools -> Reset Configuration Data.

It'd also be good to see what gets called with NI IO Trace (open IO Trace, configure to track DAQmx and NI System Configuration) when you perform this call and which part errors out.

 

Otherwise, it'd be worth opening up a service request and getting some more eyes on this 🙂

 

Cheers,

Nick

0 Kudos
Message 2 of 6
(3,284 Views)

Hi.  I cannot get a single example to run in .net (VS2019).  Exact same error at the exact same place.  I am trying to read a NI USB-6501 from .NET.  The device monitor finds it, and reads it, but VS2019 under Admin rights throws this every time.

 

Pretty much any unmodified example code, so you have the code I'm using.

 

Any help would be appreciated.

 

Thanks,

 

Eric

0 Kudos
Message 3 of 6
(3,237 Views)

Hey again.  Not 5 min after posting that issue, I came across the solution.  Build was set to Any CPU.  Change it to x86, and everything works.  I am running VS2019 on a x64 notebook, so that's what it was compiling for, trying to read 32 bit..

 

Sorry for the waste of your time.

 

Thanks,

 

Eric

0 Kudos
Message 4 of 6
(3,234 Views)
Solution
Accepted by topic author teebee2019

Hello there,

 

I solved the issue sometime ago now. The problem was creating multiple instances of a service that use the NIDAQmx dll. I solved the issue my ensuring the service was a singleton.

 

Hope this helps!

0 Kudos
Message 5 of 6
(3,224 Views)

Hi ,


I am facing same issue when I am build the code in VS2022 and I am using Framework .net4.5
Could somebody guide through the steps how to solve this issue. I am not able to get the solutions posted on this channel, it's quite confusing which one to follow as there is no one posted clear solution to this issue.

 

Thanks.

0 Kudos
Message 6 of 6
(664 Views)