簡體   English   中英

System.StackOverflowException是未處理的錯誤

[英]System.StackOverflowException was unhandled error

我對存儲庫和模擬存儲庫還很陌生,因此我想幫助您理解此錯誤的確切含義以及如何避免該錯誤。 我查看了其他帖子並進行了研究,但是它們過於具體於他們的錯誤。 破壞的代碼是

public int PersistComponentDb(Core.Models.ComponentDbModel componentDb)
{
    return PersistComponentDb(componentDb);
}

我知道該函數正在調用自身,但是如何阻止它呢? 它正在持久保存模擬存儲庫,並且硬編碼的值看起來像這樣

public DataTable GetComponentDbs(int? forComponentId = null, int? forDbServerId = null, int? forEntityId = null)
{
    DataTable componentDbs = new DataTable();
    componentDbs.Columns.Add("ComponentDbID", typeof(Int32));
    componentDbs.Columns.Add("ComponentID", typeof(Int32));
    componentDbs.Columns.Add("DbServerID", typeof(Int32));
    componentDbs.Columns.Add("EntityID", typeof(int));
    componentDbs.Columns.Add("SecurableGuid", typeof(String));
    componentDbs.Columns.Add("FriendlyName", typeof(String));
    componentDbs.Columns.Add("DbName", typeof(String));
    componentDbs.Rows.Add(new object[] { 1, 2, 2, 3822, "SecureableGuid", "Test #1", "DB #1" });
    return componentDbs;
}

public DataRow GetComponentDb(int id)
{
    DataTable componentDbs = new DataTable();   
    componentDbs.Columns.Add("ComponentDbID", typeof(Int32));
    componentDbs.Columns.Add("ComponentID", typeof(Int32));
    componentDbs.Columns.Add("DbServerID", typeof(Int32));
    componentDbs.Columns.Add("EntityID", typeof(Int32));
    componentDbs.Columns.Add("SecurableGuid", typeof(String));
    componentDbs.Columns.Add("FriendlyName", typeof(String));
    componentDbs.Columns.Add("DbName", typeof(String));
    componentDbs.Rows.Add(new object[] { 123, 121, 12, null, "SecurableGuid", "Name", "Database name" });
    return componentDbs.Rows[0];
}

PersistComponentDb后面的其余代碼是

public int PersistComponentDb(ComponentDbModel componentDb)
{
    // Example implementation.
    return _repository.PersistComponentDb(componentDb);
}

int PersistComponentDb(ComponentDbModel componentDb);

該方法正在調用自身。 因此,stackoverflow。

public int PersistComponentDb(Core.Models.ComponentDbModel componentDb)
{
    return PersistComponentDb(componentDb);
}

該代碼應為:

public int PersistComponentDb(Core.Models.ComponentDbModel componentDb)
{
    return _repository.PersistComponentDb(componentDb);
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM