ASP. NET labels

Source: Internet
Author: User

Recently, when I was working on a project in the company, I encountered a small problem, that is, the company uses VS2008. In the project, I used the simplified attributes in NET 3.5.

For example: public string Name {get; set ;}

In principle, there is no problem, but in ASP. NET, this attribute always reports an error: the subject must be declared because it is not marked as abstract or extern.
This error is obviously caused by the. Net Framework failing to identify this as a simplified property.

 

I was wondering why ASP. NET was developed under VS2008 (. Net 3.5). Why cannot I use simplified attributes? Check that the target Framework is selected. Net Framework 3.5 on the properties of the website, and the. Net 3.5 assembly is also introduced under the <assemblies> label in web. config. Why does the VS compiler not recognize the simplified attributes of. Net 3.5?

 

After searching for half a day, I finally found my company ASP.. NET project web. an important label <system. codedom> (it is estimated that this is a useless tag generated during the upgrade process after the project is upgraded from 2.0 to 3.5)

I will paste all the content of this label:

<System. codedom>
<Compilers>
<Compiler language = "c #; cs; csharp" extension = ". cs "type =" Microsoft. CSharp. CSharpCodeProvider, System, Version = 2.0.0.0, Culture = neutral, PublicKeyToken = b77a5c561934e089 "warningLevel =" 4 ">
<ProviderOption name = "CompilerVersion" value = "v3.5"/>
<ProviderOption name = "WarnAsError" value = "false"/>
</Compiler>
<Compiler language = "vb; vbs; visualbasic; vbscript" extension = ". vb "type =" Microsoft. visualBasic. VBCodeProvider, System, Version = 2.0.0.0, Culture = neutral, PublicKeyToken = b77a5c561934e089 "warningLevel =" 4 ">
<ProviderOption name = "CompilerVersion" value = "v3.5"/>
<ProviderOption name = "OptionInfer" value = "true"/>
<ProviderOption name = "WarnAsError" value = "false"/>
</Compiler>
</Compilers>
</System. codedom>

This label plays a vital role in telling. Net Framework which version of the compiler should be used to compile the code.

 

The sub-tag

<Compiler language = "c #; cs; csharp" extension = ". cs "type =" Microsoft. CSharp. CSharpCodeProvider, System, Version = 2.0.0.0, Culture = neutral, PublicKeyToken = b77a5c561934e089 "warningLevel =" 4 ">
<ProviderOption name = "CompilerVersion" value = "v3.5"/>
<ProviderOption name = "WarnAsError" value = "false"/>
</Compiler>

Is to set the version of the compiler used to compile the C # language, you can see that the attributes name = "CompilerVersion" and value = "v3.5" specify that the compiler version is 3.5. (do not believe that you should change this attribute to 2.0, when simplified attributes are used in the code, an error is returned ).

 

Other sub-tags

<Compiler language = "vb; vbs; visualbasic; vbscript" extension = ". vb "type =" Microsoft. visualBasic. VBCodeProvider, System, Version = 2.0.0.0, Culture = neutral, PublicKeyToken = b77a5c561934e089 "warningLevel =" 4 ">
<ProviderOption name = "CompilerVersion" value = "v3.5"/>
<ProviderOption name = "OptionInfer" value = "true"/>
<ProviderOption name = "WarnAsError" value = "false"/>
</Compiler>

Is to set the version of the compiler to be used to compile the VB language. It can be seen that it is also 3.5.

 

If the web. no <system. codedom> label configuration, then. net Framework uses a 2.0 compiler by default. Of course, the 2.0 compiler cannot recognize the 3.5 syntax such as simplified attributes and anonymous classes. Therefore, an error is reported during compilation. This is because. net Framework 3.5 is.. Net Framework 2.0 extension version, do not believe you can go to C: \ WINDOWS \ Microsoft. NET \ Framework \ v2.0.50727 \ CONFIG to view the machine. config and web. config and other root configuration files. net Framework 3.5. Most of the configurations are for version 2.0. net 3.5 has many related features in the project web. config. This is already in. net Framework 4.0 has been improved because. net Framework 4.0 is not an extended version of the old version. Most of its related features are configured in the root configuration file, and do not need to be configured in the project configuration file.

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.