dotnetdevcsharp
dotnetdevcsharp

Reputation: 3980

An unhandled exception of type 'System.StackOverflowException' Entity Framework

I am getting the weirdest of issues; I downgraded to ef5 6 is still playing up for me but now I am getting the follow it crashes on the line below

 /// <summary>
 /// Initializes a new SMBASchedulerEntities object using the connection string found in the 'SMBASchedulerEntities' section of the application configuration file.
 /// </summary>
public SMBASchedulerEntities() : base("name=SMBASchedulerEntities", "SMBASchedulerEntities")
{
    this.ContextOptions.LazyLoadingEnabled = true;
    OnContextCreated();
}

The error in question is

An unhandled exception of type 'System.StackOverflowException' occurred in mscorlib.dll

I have a property that allows me to call my save context on other forms

private SMBASchedulerEntities _SourceEntities;

public SMBASchedulerEntities SourceEntities
{
    get
    {
         _SourceEntities = new SMBASchedulerEntities();
         return SourceEntities;
    }
}

I don't know what is going on here as I have never come across this error before.

Upvotes: 0

Views: 925

Answers (1)

rokkerboci
rokkerboci

Reputation: 1167

You are referencing your property in your property getter

 private SMBASchedulerEntities _SourceEntities;
 public SMBASchedulerEntities SourceEntities
 {
      get
      {

          _SourceEntities = new SMBASchedulerEntities();


          return SourceEntities; <-- should be _SourceEntities 
      }
}

Basicly, this exception is thrown if there are too many calls within calls. (or as in this case "infinite")

Upvotes: 7

Related Questions