[英]Using 4.6v dll without upgrading current project target framework from v4.0 to v4.6 C#
I have a requirement where I should not upgrade my WPF application of 4.0 version to 4.6, because we are using some legacy third party controls which is leading to hell number of error, but I should use a dll of version 4.6 in my WPF project. 我有一个要求,我不应该将我的WPF应用程序的4.0版本升级到4.6,因为我们使用的是一些旧式第三方控件,这会导致错误数,但是我应该在WPF项目中使用版本4.6的dll。 Please suggest me some workaround to achieve this.
请为我建议一些解决方法。
I am new to COM programming. 我是COM编程新手。 I think the above is possible for example, we use outlook 2016 dlls, etc., which uses 4.5v in our 4.0 projects by adding them as COM components to our projects.
我认为上述情况是可能的,例如,我们使用Outlook 2016 dll等,通过将它们作为COM组件添加到我们的项目中,在我们的4.0项目中使用4.5v。 All it needs is to runtime version of the OS should be 4.5.
它所需要的只是操作系统的运行时版本应为4.5。
You cannot use .Net 4.6 assemblies in a process which has been initialized with the 4.0 runtime. 您不能在已用4.0运行时初始化的进程中使用.Net 4.6程序集。 The reason is that the runtime for 4.6 is the same runtime for 4.0, and thus it can't run side-by-side like 2.0 assemblies can.
原因是4.6的运行时与4.0的运行时相同,因此它不能像2.0程序集那样并排运行。 The VM that gets loaded in process will not interpret the method table of the loaded types correctly, even if they are exported as COM interfaces.
即使正在导出的VM作为COM接口导出,也将无法正确解释已加载类型的方法表。 The reason is that even if is going through a layer of Runtime / COM / Runtime indirection, the same 4.0 CLR and system assemblies are loaded in that process, and the instantiation of a runtime type from 4.6 assembly appears to cause the CLR method
RuntimeTypeHandle::CreateInstance
to interpret the method table incorrectly. 原因是,即使正在通过Runtime / COM / Runtime间接层,该进程中也会加载相同的4.0 CLR和系统程序集,并且从4.6程序集实例化运行时类型似乎会导致CLR方法
RuntimeTypeHandle::CreateInstance
以错误地解释方法表。
The only way you could do this is if you hosted the 4.6 assembly in another process and remoted to it. 唯一的方法是将4.6程序集托管在另一个进程中,并远程安装到该程序集中。 This is likely what is happening with the Outlook add-ins anyway, they are being hosted by
dllhost.exe
or similar shell process out of the Outlook process. 无论如何,这可能都是Outlook加载项所发生的事情,它们是由
dllhost.exe
或Outlook进程之外的类似Shell进程托管的。
You can find the screenshot here for my above comment. 您可以在此处找到上述评论的屏幕截图。 As long as we have 4.6 runtime in the machine.
只要我们在机器上有4.6运行时。 we can do it using reflection:
我们可以使用反射来做到这一点:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.