Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

dll: Method contains unsupported native code

I am using NI usb 6211, based on .NET2.0

 

Here is my code:


using NationalInstruments.DAQmx;

 

   using (Task digitalWriteTask = new Task())
              
            {  //  Create an Digital Output channel and name it.
                    digitalWriteTask.DOChannels.CreateChannel("Dev1/Port1/line0", "",ChannelLineGrouping.OneChannelForAllLines);

                    //  Write digital port data. WriteDigitalSingChanSingSampPort writes a single sample
                    //  of digital data on demand, so no timeout is necessary.
                    DigitalSingleChannelWriter writer = new DigitalSingleChannelWriter(digitalWriteTask.Stream);
                    writer.WriteSingleSamplePort(true, 3); }

 

when using (Task digitalWriteTask = new Task()) is called, error shows:

 

MissingMethodException: Method contains unsupported native code
<Module>.<CrtImplementationDetails>.LanguageSupport.Initialize (<CrtImplementationDetails>.LanguageSupport* )
<Module>..cctor ()

 

Anyone knows what is wrong here?

 

Thanks.

0 Kudos
Message 1 of 6
(5,076 Views)

Annie,

 

I could not reproduce this error. I copied and pasted your code and did not receive the error. Could you post more of your code? Maybe a small project that reproduces this error.

National Instruments
0 Kudos
Message 2 of 6
(5,075 Views)

Thank you for looking into my problem.

I probably have to mention that I use MonoDevelop as IDE here.

Is there some sort of compatibility issue here? Somehow .dll files (nationalinstruments.daqmx.dll, nationalinstruments.common.dll, nationalinstruments.common.native.dll) use .net native code thats not present in mono?

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

I used traditional NI-DAQ plus VC to control NI card,

except for .dll files, we have to specify in head files the library nidaq32.lib, nidex32.lib.

I am wondering whether, in NI-DAQmx + .Net, there is an equivalent definition?

0 Kudos
Message 4 of 6
(5,002 Views)

I got NIDAQmx.lib from C:\Program Files\National Instruments\Shared\ExternalCompilerSupport\C\lib32 and \include

and also add all dll files (nationalintruments.daqmx.dll, nationalintruments.common.dll, nationalintruments.common.native, dll);

 

but still catch error message:

An exception was thrown by the type initializer for <Module> 

when I try to create the task.

 

Here is my code:

 

using System.Collections;

using System;
using NationalInstruments.DAQmx;
using System.IO;

public class IO_control_NI : MonoBehaviour {

    void Start () {      }
    void Awake() {   }   
    // Update is called once per frame
    public void performActions(int cont_v)
    {
   
        if (cont_v == 2)   // reward deliver
        {  
           
                    try
            { 
                // private DigitalSingleChannelWriter digitalWriter;
         
                using (Task digitalWriteTask = new Task())
              
              { 
                   digitalWriteTask.DOChannels.CreateChannel("Dev1/Port1/line0", "",ChannelLineGrouping.OneChannelForAllLines);
                    DigitalSingleChannelWriter writer = new DigitalSingleChannelWriter(digitalWriteTask.Stream);
                    writer.WriteSingleSamplePort(true, 3);
                }

   
    }
            catch (Exception ex)
            {
             var sw = new StreamWriter("nierror.txt",true);   
               
             sw.WriteLine(ex.Message);
             sw.Close();
          
            }

        }
   

            }

   
}

0 Kudos
Message 5 of 6
(5,000 Views)

Unfortunately, NI-DAQmx does not support development in Mono. Our DAQmx .NET assemblies are mixed-mode, which is probably why you are running into problems. It may be possible to get it to work in Mono, but I do not understand enough about Mono to really help much. It is my understanding that there is little to no support for mixed-mode assemblies in Mono (although it is a heavily requested feature). Currently National Instruments does not provide any support for this.

National Instruments
0 Kudos
Message 6 of 6
(4,983 Views)