automatic properties still must declare a body?

Answered automatic properties still must declare a body?

  • Freitag, 27. April 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


Alle Antworten

  • Freitag, 27. April 2012 22:24
     
     Beantwortet Enthält Code

    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)

    • Als Antwort vorgeschlagen Prabhu Ramasamy Samstag, 28. April 2012 04:00
    • Als Antwort markiert smetah Samstag, 28. April 2012 12:36
    • Tag als Antwort aufgehoben smetah Montag, 30. April 2012 13:05
    • Als Antwort markiert smetah Montag, 30. April 2012 13:32
    •  
  • Montag, 30. April 2012 13:06
     
     Beantwortet Enthält Code

    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;
        }
    


    • Bearbeitet smetah Montag, 30. April 2012 13:08
    • Als Antwort vorgeschlagen Kris444 Montag, 30. April 2012 13:36
    • Als Antwort markiert smetah Montag, 30. April 2012 16:03
    •  
  • Montag, 30. April 2012 13:33
     
     
    Found out that I was using the wrong "compilation" directives.