简体   繁体   English

PlatformNotSupportedException在.NET 4.0进程中加载​​.NET 2.0

[英]PlatformNotSupportedException Loading .NET 2.0 in .NET 4.0 Process

I'm attempting to load a .NET 2.0 assembly into a C# .NET 4.0 PowerShell module. 我正在尝试将.NET 2.0程序集加载到C#.NET 4.0 PowerShell模块中。 If I attempt to reference the assembly, I get a PlatformNotSupported message indicating the 2.0 assembly doesn't support .NET 4. I'm also loading the 2.0 assembly via reflection. 如果尝试引用该程序集,则会收到PlatformNotSupported消息,指示2.0程序集不支持.NET4。我还通过反射加载了2.0程序集。

I tried creating an net40AssemblyName.dll.config with the below configuration, but that doesn't work either. 我尝试使用以下配置创建一个net40AssemblyName.dll.config,但这也不起作用。

<?xml version="1.0" encoding="utf-8" ?> 
    <configuration> 
        <startup useLegacyV2RuntimeActivationPolicy="true"> 
             <supportedRuntime version="v4.0" />    
        </startup>
    </configuration>
 </xml>

I'm unsure if this is due to the dll.config not working, or if this would have to be applied at the PowerShell.exe.config level. 我不确定这是否是由于dll.config不起作用,还是必须在PowerShell.exe.config级别应用。

I ended up separating out the specific cmdlet that targeted one platform vs. another into separate projects. 最后,我将针对一个平台与另一个平台的特定cmdlet分离到了单独的项目中。 I was then able to package both projects into a single MSI and provide an option during installation about which platform to target. 然后,我能够将两个项目打包到一个MSI中,并在安装过程中提供有关目标平台的选项。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM