CS0501:'blah blah' must declare a body because it is not marked abstract or extern

In this asp.net tutorial you will find the solution of CS0501 error which is CS0501:'blah blah' must declare a body because it is not marked abstract or extern. I got this error when I download an aspx page from some website and after some modification in c# code when I run my .aspx page then i got the error mentioned in following screenshot.




As you have seen, screenshot shows there is something wrong with the protected string country {get;set;}. Actually i decalred the protected type string variable country in .cs code behind file and after assigning some value to it i tried to get the variable on .aspx side using the following code snippet


my_page.aspx

<script language="javascript" type="text/javascript">
var country='<%=country %>';
</script>

and then I got this CS0501 error. So after performing some search, I got its solution. And solution is you have to add following compiler settings in your web.config file.

CS0501:'blah blah' must declare a body because it is not marked abstract or extern solution


<system.codedom>
<compilers>
<compiler compileroptions="/warnaserror-" extension=".cs" language="c#;cs;csharp" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" warninglevel="4">
<provideroption name="CompilerVersion" value="v3.5">
</compiler>
<compiler compileroptions="/optioninfer+" extension=".vb" language="vb;vbs;visualbasic;vbscript" type="Microsoft.VisualBasic.VBCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<provideroption name="CompilerVersion" value="v3.5">
</compiler>
</compilers>
</system.codedom>

Note:- These settings based on the version of .Net Framework you installed in your system.


So this is the solution of CS0501:'blah blah' must declare a body because it is not marked abstract or extern. If you have some more solutions then don't hesitate to share.

0 comments: