VimService55.XmlSerializers.dll 中发生了 'System.StackOverflowException' 类型的未处理异常
An unhandled exception of type 'System.StackOverflowException' occurred in VimService55.XmlSerializers.dll
我正在开发 asp.net mvc-5 网络应用程序,我正在使用 ap.net 4.5 版。
在我的网络应用程序中,我正在执行一些 power-shell 脚本来获取有关某些服务器和 VM 的一些硬件信息,并在我的代码中取回结果,如下所示:
var shell = PowerShell.Create();
string PsCmd =
"add-pssnapin VMware.VimAutomation.Core; $vCenterServer = '"
+ vCenterName.Trim() + "';$vCenterAdmin = '" + vCenterUsername.Trim()
+ "' ;$vCenterPassword = '" + vCenterPassword + "';"
+ System.Environment.NewLine;
PsCmd += "$VIServer = Connect-VIServer -Server $vCenterServer -User $vCenterAdmin -Password $vCenterPassword;" + System.Environment.NewLine;
PsCmd += "Get-VMHost " + System.Environment.NewLine;
shell.Commands.AddScript(PsCmd);
dynamic results = shell.Invoke();
var temp_result = results[0].BaseObject == null ? results[0] : results[0].BaseObject;
var otherIdentityInfo = temp_result.ExtensionData.Hardware.SystemInfo.OtherIdentifyingInfo;
现在,当我 运行 在我的 Visual Studio 2012 专业中使用它时,我将得到以下异常 :-
System.WhosebugException was unhandled
An unhandled exception of type 'System.WhosebugException' occurred in VimService55.XmlSerializers.dll
在
var otherIdentityInfo = temp_result.ExtensionData.Hardware.SystemInfo.OtherIdentifyingInfo;
所以有人可以就此提出建议吗?我知道通常 "WhosebugException" 异常与堆栈内存在太多数据这一事实有关,但在我的情况下,我无法控制这些数据,因为我正在扫描 VM 服务器信息。那么有人可以就此提出建议吗?
编辑
我不确定引发错误的真正原因是什么(调试器或代码)?因为当我尝试在 IIS 内(而不是 Visual Studio 内)的托管应用程序上调用此代码时,我将获得 otherIdentityInfo
变量的空值,而不是获得异常。但是,当我使用 Autos 调试 Visual Studio 内的代码时,我会得到异常,所以正如@JmaesP 提到的,调试器正在引发异常,但不确定我如何调试这个值以查看我得到的原因空??
来自 XML 序列化程序的堆栈溢出异常可能表示其中一种可序列化类型存在问题。如果类型声明本身有点递归,则默认的 XML 序列化程序将以无限递归结束。考虑这个例子:
[Serializable()]
public class Foo : IEnumerable<Foo>
{
public Foo()
{
}
IEnumerator IEnumerable.GetEnumerator()
{
throw new NotImplementedException();
}
public IEnumerator<Foo> GetEnumerator()
{
throw new NotImplementedException();
}
public void Add(Foo item)
{
throw new NotImplementedException();
}
}
默认的 XML 序列化程序首先尝试找出如何(反)序列化 Foo
的实例,然后它尝试找出如何(反)序列化 [=] 12=],并为此尝试弄清楚如何(反)序列化 Foo
——导致无限递归。通常,解决此问题的方法是使用自定义序列化程序,如 here 所述。
但是,在您的情况下,序列化程序是由第三方组件提供的。当对象从 PowerShell 会话传递到您的进程时,异常可能发生在 serialization/deserialization 期间。因此,您可以做的是更改从 PowerShell 脚本 returned 的对象。您可以 return SystemInfo
或 OtherIdentifyingInfo
.
大型递归会导致堆栈外错误。
您的问题很可能是您的程序试图消耗无限量/非常大量的堆栈。
没有看到你的堆栈跟踪,提供一个明确的答案有点困难,但我认为坚持基础知识让我相信你的 Whosebug 的来源是 PsCmd += 连续将数据添加到堆栈并导致 WhosebugException。
您可以使用以下代码增加堆栈大小:
Editbin.exe /Stack:14000000 "$(TargetDir)MyProject.exe"
您是否分析过代码以了解递归的平均深度?它总是命中 Whosebug 吗?尝试对单个实体进行硬编码并查看结果。
由于 64 位代码可以比等效的 32 位代码更多堆栈 space,大递归会导致堆栈外错误更早发生。
在那种情况下,扩大堆栈也不是一个好主意。相反,我们应该找到深度递归算法并将其变成迭代算法。
对于堆栈跟踪;
你可以阅读这个属性:Environment.StackTrace.
如果堆栈跟踪超过您预设的特定阈值,您可以 return 该函数。
注意: 从 .Net 2.0 及更高版本,您无法使用 try-catch 块获取 WhosebugException 对象。
如果对您有帮助,请告诉我。
我正在开发 asp.net mvc-5 网络应用程序,我正在使用 ap.net 4.5 版。
在我的网络应用程序中,我正在执行一些 power-shell 脚本来获取有关某些服务器和 VM 的一些硬件信息,并在我的代码中取回结果,如下所示:
var shell = PowerShell.Create();
string PsCmd =
"add-pssnapin VMware.VimAutomation.Core; $vCenterServer = '"
+ vCenterName.Trim() + "';$vCenterAdmin = '" + vCenterUsername.Trim()
+ "' ;$vCenterPassword = '" + vCenterPassword + "';"
+ System.Environment.NewLine;
PsCmd += "$VIServer = Connect-VIServer -Server $vCenterServer -User $vCenterAdmin -Password $vCenterPassword;" + System.Environment.NewLine;
PsCmd += "Get-VMHost " + System.Environment.NewLine;
shell.Commands.AddScript(PsCmd);
dynamic results = shell.Invoke();
var temp_result = results[0].BaseObject == null ? results[0] : results[0].BaseObject;
var otherIdentityInfo = temp_result.ExtensionData.Hardware.SystemInfo.OtherIdentifyingInfo;
现在,当我 运行 在我的 Visual Studio 2012 专业中使用它时,我将得到以下异常 :-
System.WhosebugException was unhandled
An unhandled exception of type 'System.WhosebugException' occurred in VimService55.XmlSerializers.dll
在
var otherIdentityInfo = temp_result.ExtensionData.Hardware.SystemInfo.OtherIdentifyingInfo;
所以有人可以就此提出建议吗?我知道通常 "WhosebugException" 异常与堆栈内存在太多数据这一事实有关,但在我的情况下,我无法控制这些数据,因为我正在扫描 VM 服务器信息。那么有人可以就此提出建议吗?
编辑
我不确定引发错误的真正原因是什么(调试器或代码)?因为当我尝试在 IIS 内(而不是 Visual Studio 内)的托管应用程序上调用此代码时,我将获得 otherIdentityInfo
变量的空值,而不是获得异常。但是,当我使用 Autos 调试 Visual Studio 内的代码时,我会得到异常,所以正如@JmaesP 提到的,调试器正在引发异常,但不确定我如何调试这个值以查看我得到的原因空??
来自 XML 序列化程序的堆栈溢出异常可能表示其中一种可序列化类型存在问题。如果类型声明本身有点递归,则默认的 XML 序列化程序将以无限递归结束。考虑这个例子:
[Serializable()]
public class Foo : IEnumerable<Foo>
{
public Foo()
{
}
IEnumerator IEnumerable.GetEnumerator()
{
throw new NotImplementedException();
}
public IEnumerator<Foo> GetEnumerator()
{
throw new NotImplementedException();
}
public void Add(Foo item)
{
throw new NotImplementedException();
}
}
默认的 XML 序列化程序首先尝试找出如何(反)序列化 Foo
的实例,然后它尝试找出如何(反)序列化 [=] 12=],并为此尝试弄清楚如何(反)序列化 Foo
——导致无限递归。通常,解决此问题的方法是使用自定义序列化程序,如 here 所述。
但是,在您的情况下,序列化程序是由第三方组件提供的。当对象从 PowerShell 会话传递到您的进程时,异常可能发生在 serialization/deserialization 期间。因此,您可以做的是更改从 PowerShell 脚本 returned 的对象。您可以 return SystemInfo
或 OtherIdentifyingInfo
.
大型递归会导致堆栈外错误。 您的问题很可能是您的程序试图消耗无限量/非常大量的堆栈。
没有看到你的堆栈跟踪,提供一个明确的答案有点困难,但我认为坚持基础知识让我相信你的 Whosebug 的来源是 PsCmd += 连续将数据添加到堆栈并导致 WhosebugException。
您可以使用以下代码增加堆栈大小:
Editbin.exe /Stack:14000000 "$(TargetDir)MyProject.exe"
您是否分析过代码以了解递归的平均深度?它总是命中 Whosebug 吗?尝试对单个实体进行硬编码并查看结果。
由于 64 位代码可以比等效的 32 位代码更多堆栈 space,大递归会导致堆栈外错误更早发生。
在那种情况下,扩大堆栈也不是一个好主意。相反,我们应该找到深度递归算法并将其变成迭代算法。
对于堆栈跟踪; 你可以阅读这个属性:Environment.StackTrace.
如果堆栈跟踪超过您预设的特定阈值,您可以 return 该函数。
注意: 从 .Net 2.0 及更高版本,您无法使用 try-catch 块获取 WhosebugException 对象。
如果对您有帮助,请告诉我。