<VS2010> mixed-mode assemblies are generated for the "v2.0" version of the runtime and cannot be loaded in the 4.0 runtime without additional information being configured

Source: Internet
Author: User

In putting the previously written code generation tool from the original. When the NET3.5 is upgraded to. NET4.0, after the assembly is updated, a run-time program invokes an exception in one of the method call times:

Mixed-mode assemblies are generated for the "v2.0.50727" version of the runtime and cannot be loaded in the 4.0 runtime without additional information being configured

Its call method is from the SQLite database to get the original used database connection, then did not notice, is ready to set breakpoints and then single-step debugging, the result is a breakpoint can not enter the method body, and then carefully looked at the method body when found a problem, That's the existing System.Data.Sqlite. This data access provider is developed for the. NET2.0 environment , and the current official has not given the latest. NET4 data access support.

Finally, the solution is to add a configuration section in App. Config:startup

1 <startup uselegacyv2runtimeactivationpolicy="true">2   <supportedruntime version="v4.0"/>3 </startup>

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: The 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:

uses the default. NET Framework 4 activation policy, which loads the. NET Framework 4 assemblies created by using the common language runtime (CLR) version 4, and earlier versions of the CLR By using a supported assembly that is created under the highest CLR version of version 4.

 

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 can view MSDN:

startup:http://msdn.microsoft.com/zh-cn/ library/bbx34a2h.aspx

Supportedruntime:http://msdn.microsoft.com/zh-cn/library/w4atty68.aspx

<VS2010> mixed-mode assemblies are generated for the "v2.0" version of the runtime and cannot be loaded in the 4.0 runtime without additional information being configured

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.