通过反射从.Net 4.5的应用程序构建中调用Net 4.6.1程序集的方法是否明智? [英] Is it wise to call methods of a Net 4.6.1 assembly from an application build with .Net 4.5 via reflection?

查看:218
本文介绍了通过反射从.Net 4.5的应用程序构建中调用Net 4.6.1程序集的方法是否明智?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的方案如下:

我们正在开发第三方插件。我们的程序集通过使用.Net 4.5的另一个应用程序构建的反射来加载和调用。

We developing 3rd party addons. Our assemblies are loaded and called via reflection from another application build with .Net 4.5.

我们可以确保 每个需要运行时(4.6.1或4.7)都安装在运行应用程序和插件的机器上。

We can ensure  that every need runtime (4.6.1 or 4.7) is installed on the machine the application and addon is running on.

我们可以用.Net 4.6.1(甚至4.7)构建程序集)当应用程序在.Net 4.5下运行或者是否容易出错? 

Can we build our assemblies with .Net 4.6.1 (or even 4.7) when the applications runs under .Net 4.5 or is this error prone? 

谢谢

Harald

推荐答案

这通常是一个坏主意。

It's generally a bad idea.

如果程序集被加载到在.NET 4.5环境中,反射将失败,您需要能够处理它。如果你确定装配将被加载到4.6.1+环境中,那么你应该只定位更高的
版本。

If the assembly is loaded into a .NET 4.5 environment, then the reflection will fail and you would need to be able to handle that. If you know for certain that the assembly will be loaded into a 4.6.1+ environment, then you should just target the higher version.

如果你决定这样做的话,你应该避免非公开成员/类型。外部可见的东西可能会在没有通知的情况下发生变化,导致您的反射中断。

If you decide to do this anyway, you should avoid non-public members/types. things that are not externally visible may change without notice, causing your reflection to break.


这篇关于通过反射从.Net 4.5的应用程序构建中调用Net 4.6.1程序集的方法是否明智?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆