Solution, add a configuration section in App. Config:startup
<?xml version= "1.0"?>
<configuration>
<startup uselegacyv2runtimeactivationpolicy= "true" >
<supportedruntime version= "v4.0" SKU = ". netframework,version=v4.0 "/>
<supportedruntime version= "v2.0.50727"/>
</startup>
</configuration>
The meaning of this section of the configuration is (refer to from MSDN, specific address: http://msdn.microsoft.com/zh-cn/library/bbx34a2h.aspx):
You enable the. NET Framework version 2.0 runtime activation policy, which is loaded by using the latest supported runtime for all assemblies.
Note: Due to the nature of the config configuration file, if the configsections node exists in the config configuration file, you must put configsections in one, otherwise an exception will be thrown: configuration system failed to initialize
In the original. net2.0,.net3.5, due to the nature of the operating environment of the program or. NET2.0, and to the. NET4.0 because the entire assembly version is updated, the previously used. NET2.0 assembly with the. NET4.0 Assembly continues to be screwed interop when the above mentioned compatibility issues occur.
With MSDN, we know that the useLegacyV2RuntimeActivationPolicy property in the Startup configuration section is new in. NET4.0, and the default is False, which means:
Using the default. NET Framework 4 activation policy, the activation policy will load the. NET Framework 4 assemblies created by using the common language runtime (CLR) version 4, as well as earlier versions of the CLR by using a supported version of the highest CLR versions below version 4 The assembly that was created.
Now if the program is in. You must set the useLegacyV2RuntimeActivationPolicy to True when you want to use the. NET2.0 and. NET3.5 programs in the NET4.0 environment, and also note that you need to add supportedruntime configuration in the bytes of the Startup configuration section section, and is specified as "v4.0", which indicates use. NET4.0 the runtime to run the program.
For more startup and its children, you can view MSDN:
Startup:http://msdn.microsoft.com/zh-cn/library/bbx34a2h.aspx
Supportedruntime:http://msdn.microsoft.com/zh-cn/library/w4atty68.aspx
The
Mixed-mode assembly is generated for the run-time version of "v2.0.50727" and cannot be loaded in the 4.0 runtime without additional information being configured.