An unhandled exception of type 'System.StackOverflowException.Cannot evaluate expression because the current thread is in a stack overflow state

public class ConnectionElement : ConfigurationElement
{
     [ConfigurationProperty("uri", DefaultValue = "/")]

     public String Uri
     {
         get
         { return(String)this. Uri; }            
         set
         { this.Uri = value; }
     }
 }

It is throwing error stating An unhandled exception of type System.StackOverflowException. Please help

Jon Skeet
people
quotationmark

Both your getter and your setter are calling themselves. Remember that properties are just groups of methods, effectively. Your class really looks like this, but with a bit of extra metadata:

public class ConnectionElement : ConfigurationElement
{
     public string GetUri()
     {
         return (string) GetUri();
     }

     public void SetUri(string value)
     {
         SetUri(value);
     }
}

Now can you see why it's failing?

It's not clear why you're casting in the getter, but it looks like an automatically implemented property might do:

[ConfigurationProperty("uri", DefaultValue = "/")]
public string Uri { get; set; }

EDIT: If, as noted in comments, you're really trying to use the indexer, you need to do that instead of calling your property recursively:

public class ConnectionElement : ConfigurationElement
{
     [ConfigurationProperty("uri", DefaultValue = "/")]
     public string Uri
     {
         get { return (string) this["uri"]; }
         set { this["uri"] = value; }
     }
}

people

See more on this question at Stackoverflow