automatic properties still must declare a body?

Răspuns automatic properties still must declare a body?

  • 27 aprilie 2012 21:35
     
     

    I'm using automatic properties in VS 2010, as per

    Auto-Implemented Properties

    http://msdn.microsoft.com/en-us/library/bb384054.aspx

    It was OK before, but somehow (after I've tweak web.config?) all of sudden I get the following error:

    must declare a body because it is not marked abstract or extern

    It was OK before. What could be wrong? 

    Thanks


Toate mesajele

  • 27 aprilie 2012 22:24
     
     Răspuns Are cod

    You should have the following in the web config for auto-implemented properties to work:

    <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="v4.0" />
                           
    <providerOption name="WarnAsError" value="false" />
                   
    </compiler>
           
    </compilers>
    </system.codedom>


    Ali Hamdar (alihamdar.com - www.ids.com.lb)

    • Propus ca răspuns de Prabhu Ramasamy 28 aprilie 2012 04:00
    • Marcat ca răspuns de smetah 28 aprilie 2012 12:36
    • Anulare marcare ca răspuns de smetah 30 aprilie 2012 13:05
    • Marcat ca răspuns de smetah 30 aprilie 2012 13:32
    •  
  • 30 aprilie 2012 13:06
     
     Răspuns Are cod

    Ali, thanks for your reply, but FYI, it didn't work for me, my VS 2010. 

    I found the following works:

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


    thanks all the same

    FYI, my properties is defined as:

        public static string MyVal
        {
            get;
            set;
        }
    


    • Editat de smetah 30 aprilie 2012 13:07
    • Editat de smetah 30 aprilie 2012 13:08
    • Propus ca răspuns de Kris444 30 aprilie 2012 13:36
    • Marcat ca răspuns de smetah 30 aprilie 2012 16:03
    •  
  • 30 aprilie 2012 13:33
     
     
    Found out that I was using the wrong "compilation" directives.