简体   繁体   English

使用4.6v dll而不将当前项目目标框架从v4.0升级到v4.6 C#

[英]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: 我们可以使用反射来做到这一点:

demo_screenshot demo_screenshot

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Google Dialogflow 无法从 nuget 安装 .net v4.6 - Google Dialogflow does not install for .net v4.6 from nuget 无法在多个项目上更改目标框架从v4.0到V4.5或4.5.1 - Cannot change Target Framework on Several Projects From v4.0 to V4.5 or 4.5.1 将目标框架从v4.0更改为v3.5后,找不到命名空间 - Namespace cannot be found after changing target framework from v4.0 to v3.5 如何在没有.NET v4.0的目标环境上部署.NET v4.0应用程序? - How can I deploy .NET v4.0 application on target environment without .NET v4.0? .NET Framework从v3.5迁移到v4.0 - NET Framework migration from v3.5 to v4.0 VS2008上的“无法在对象浏览器中查看此项目”-ASP.NET C#v4.0 - “This project cannot be viewed in object browser” on VS2008 - ASP.NET C# v4.0 从 Serilog.Sinks.ApplicationInsights v3.1 升级到 v4.0 时出错 - Getting error when upgrading from Serilog.Sinks.ApplicationInsights v3.1 to v4.0 如何参考.NETPortable,Version = v4.6,Profile = Profile44 - Ho to reference .NETPortable,Version=v4.6,Profile=Profile44 unity3d v4.6中的动画按钮(向左滑动,向右滑动,向下滑动) - Animate buttons (slide left, slide right, slide down) in unity3d v4.6 Visual Studio 2010:无法解析目标框架“.NETFramework,Version=v4.0”的 mscorlib - Visual Studio 2010: Could not resolve mscorlib for target framework '.NETFramework,Version=v4.0'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM