LabVIEW中使用.NET方法时出现错误1316 点击:222 | 回复:0



fjczd

    
  • 精华:0帖
  • 求助:0帖
  • 帖子:552帖 | 36回
  • 年度积分:703
  • 历史总积分:1294
  • 注册:2008年8月14日
发表于:2023-02-10 20:22:00
楼主

LabVIEW中使用.NET方法时出现错误1316

为什么不能调用带有泛型参数的方法?

LabVIEW不支持哪些.NET功能?

为什么会收到以下错误:

发生此错误的原因是正在调用LabVIEW中不支持的.NET功能。有关解决方法,请参阅“其他信息”部分。可以在下面找到LabVIEW中不支持的.NET功能列表。

.NET2.0及更高版本

泛型—LabVIEW不提供实例化泛型类或调用泛型方法的机制。.NET构造函数节点和.NET调用节点不允许指定要替换泛型类型的类型。

异常:

LabVIEW可以实例化对象并调用在.NET程序集中定义的方法,这些程序集还包含泛型类型定义或泛型方法定义。但是,LabVIEW只能访问这些装配件中不使用通用功能的部分。

LabVIEW可以在内部实例使用泛型类或方法的.NET对象。

LabVIEW可以在内部调用使用泛型类或方法的.NET方法。

.NET4.0

进程内并行执行(仅适用于LabVIEW 2013之前的LabVIEW版本。单击此处查看如何在LabVIEW 2013及更高版本的LabVIEW中加载混合模式装配程序)—LabVIEW不能对以不同版本的CLR运行为的.NET程序集使用不同版本的.NET公共语言运行库(CLR)。相反,LabVIEW只对它在单个应用程序实例中加载的所有.NET程序集使用一个版本的CLR。LabVIEW使用以下规则来确定使用哪个已安装的CLR版本:

默认情况下,LabVIEW使用CLR2.0,它随.NET2.0、3.0和3.5一起安装。

如果创建了相应的应用程序配置文件,LabVIEW将使用CLR4.0。

要更改CLR LabVIEW使用的哪个版本,必须退出LabVIEW并添加或移除应用程序配置文件。有关更多信息,请参阅LabVIEW帮助(链接如下)中的在LabVIEW中加载.NET4.0装配主题。

动态关键字-.NET4.0引入了关键字,该关键字指定在运行时之前不会确定或强制实施关联数据类型。但是,LabVIEW要求.NET对象具有定义的类型,以便在.NETI nvoke Node中显示可用的方法。因此,尽管LabVIEW允许调用返回动态数据类型的.NET方法,但不能使用返回的数据来调用其他方法。

异常:LabVIEW可以成功调用内部使用动态数据类型的装配程序。

可选参数的默认值-.NET程序集可能包含允许可选参数的方法。反过来,可选参数具有默认值,如果调用方未为参数指定值,则方法将使用这些值。但是,当从LabVIEW调用具有可选参数的方法时,LabVIEW始终会为参数传递其自己的缺省值,而不是让方法使用其自己预配置的缺省值。

最后,NI不保证LabVIEW完全支持所有.NET4.0类库。在可能的下,NI建议在使用LabVIEW2之前的LabVIEW版本时,使用针对CLR0.4的装配程序,而不是CLR0.2013。

通常,如果要使用LabVIEW不支持的.NET功能,可以创建一个包装的.NET程序集,用于在内部访问不支持的功能。由于自己创建包装器程序集,所以可以将公开的类型和方法定义限制为LabVIEW支持的类型和方法定义。

英文版如下所示:

Solution

Thiserror occurs because you are calling a .NET feature that is unsupported inLabVIEW. Refer to the "Additional Information" section for aworkaround. You can find a list of .NET features that are unsupported inLabVIEW below.

.NET2.0 and later

Generics—LabVIEWdoes not provide a mechanism to instantiate generic classes or to call genericmethods. The .NET Constructor Node and the .NET Invoke Node do not allow you tospecify which types you want to substitute for the generic types.

Exceptions:

LabVIEWcan instantiate objects and call methods that are defined in .NET assembliesthat also contain generic type definitions or generic method definitions.However, LabVIEW can access only the parts of these assemblies that do not usegeneric features.

LabVIEWcan instantiate .NET objects that use generic classes or methods internally.

LabVIEWcan call .NET methods that use generic classes or methods internally.

.NET4.0

In-processside-by-side execution (only applies to LabVIEW versions prior to LabVIEW 2013.Click here to see how to load mixed-mode assemblies in LabVIEW 2013 and laterversions of LabVIEW)—LabVIEW cannot use a different version of the .NET CommonLanguage Runtime (CLR) for .NET assemblies targeted to run in differentversions of the CLR. Instead, LabVIEW uses only one version of the CLR for allthe .NET assemblies that it loads in a single application instance. LabVIEWuses the following rules to determine which installed version of the CLR touse:

Bydefault, LabVIEW uses the CLR 2.0, which is installed with .NET 2.0, 3.0, and3.5.

If youcreate the appropriate application configuration file, LabVIEW uses the CLR4.0.

Tochange which version of the CLR LabVIEW uses, you must exit LabVIEW and add orremove the application configuration file. Refer to the Loading .NET 4.0Assemblies in LabVIEW topic in the LabVIEW Help (linked below) for moreinformation.

If youdo not know which version of the CLR a specific assembly is targeted to use,you can refer to the .NET Assemblies in Memory dialog box. Refer to the .NETAssemblies in Memory Dialog Boxtopic in the LabVIEW Help (linked below) formore information.

dynamickeyword—.NET 4.0 introduces the dynamic keyword, which specifies that the typeof associated data is not determined or enforced until run time. LabVIEW,however, requires .NET objects to have a defined type in order to display theavailable methods in the .NET Invoke Node. Therefore, although LabVIEW allowsyou to call .NET methods that return a dynamic data type, you cannot use thereturned data to call other methods.

Exception:LabVIEW can successfully call assemblies that use dynamic data typesinternally.

Defaultvalues for optional parameters—.NET assemblies may include methods that allowoptional parameters. Optional parameters, in turn, have default values that themethod uses if the caller does not specify a value for the parameter. However,when you call a method with an optional parameter from LabVIEW, LabVIEW alwayspasses its own default value for the parameter instead of letting the methoduse its own preconfigured defaults.

Finally,National Instruments does not guarantee that LabVIEW fully supports all .NET4.0 class libraries. When possible, National Instruments recommends that youuse assemblies targeted for the CLR 2.0 instead of the CLR 4.0 when workingwith LabVIEW versions prior LabVIEW 2013. 

AdditionalInformation

Workaround

Ingeneral, if you want to use a .NET feature that LabVIEW does not support, youcan create a wrapper .NET assembly that accesses the unsupported featureinternally. Because you create the wrapper assembly yourself, you can limit theexposed types and method definitions to those supported by LabVIEW.

 

什么是DLL封装,我什么时候需要使用DLL封装?

解决方案

所谓封装就是指为另一种软件提供兼容性接口的程序。由于第三方DLL的开发设计通常是为了从C语言(或者其它类似的底层语言)中调用,而不从是LabVIEW中调用,因此当使用LabVIEW进行应用程序开发时,往往会用到封装。例如,有的DLL会返回指针或者其它复杂的数据结构,而这在LabVIEW中却无法很容易的实现。

编写一个DLL封装,可以类比在C语言环境下,按照该DLL原始开发者设计的调用DLL方式,来编写一个完全独立的程序。反过来,这个封装程序也是专门针对在LabVIEW中调用DLL所设计的。也就是说,这个新的用C编写的“封装” 程序将原来的C程序(DLL)封装起来,形成一个接口层。使用封装的好处在于,不再需要使用原来的DLL的源代码,也不需要对这些源代码进行任何改动。

 

需要说明的是,上述的例程和文档,都是可以下载的,双击即可打开,其中压缩文件是可以采用粘贴复制的方式,拷贝到硬盘上。这不是图片,各位小伙伴看到后尝试一下,这个问题就不用加微信咨询了。有关LabVIEW编程、LabVIEW开发等相关项目,可联系们。附件中的资料这里无法上传,可去公司网站搜索下载。




楼主最近还看过


热门招聘
相关主题

官方公众号

智造工程师