事件查看器报告我的C#应用程序通过';System.Environment.FailFast()';

本文关键字:System Environment FailFast 报告 我的 应用程序 事件 | 更新日期: 2024-09-22 20:59:25

我的应用程序在Windows Embedded Standard 7上运行,并在操作系统启动时启动。

有时在第一次加载时,我会得到一个Unknown Hard Error,在检查事件查看器后,我会看到的消息

The application requested process termination through System.Environment.FailFast(string message).
Message: Unrecoverable system error.

不用说,我当然没有调用这个函数。我似乎只在Windows Embedded上看到过这种情况,而没有在标准安装的Windows上看到这种情况。

我不确定如何诊断这种情况,也不确定什么"修复"是合适的,因为我真的不知道为什么会发生这种情况。

编辑:

事件查看器中的整个日志:

    Application: WinForm.exe
    Framework Version: v4.0.30319
    Description: The application requested process termination through System.Environment.FailFast(string message).
    Message: Unrecoverable system error.
    Stack:
       at System.Environment.FailFast(System.String)
       at MS.Internal.Invariant.FailFast(System.String, System.String)
       at System.IO.Packaging.Package.AddIfNoPrefixCollisionDetected(ValidatedPartUri,     
System.IO.Packaging.PackagePart) at System.IO.Packaging.Package.GetPartHelper(System.Uri)
   at System.IO.Packaging.Package.GetPart(System.Uri)
   at System.Windows.Application.GetResourceOrContentPart(System.Uri)
   at System.Windows.Application.LoadComponent(System.Object, System.Uri)
   at Pms.PmControl.InitializeComponent()
   at Pms.PmControl..ctor(Boolean)
   at Pms.PmAppControl.StartWpfThread()
   at System.Threading.ThreadHelper.ThreadStart_Context(System.Object)
   at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
   at System.Threading.ThreadHelper.ThreadStart()

事件查看器报告我的C#应用程序通过';System.Environment.FailFast()';

如果你用反编译器查看代码,你会发现

    // System.IO.Packaging.Package
private void AddIfNoPrefixCollisionDetected(PackUriHelper.ValidatedPartUri partUri, PackagePart part)
{
    this._partList.Add(partUri, part);
    int num = this._partList.IndexOfKey(partUri);
    Invariant.Assert(num >= 0, "Given uri must be present in the dictionary");**
    string normalizedPartUriString = partUri.NormalizedPartUriString;
    string text = null;
    string text2 = null;
    if (num > 0)
    {
        text = this._partList.Keys[num - 1].NormalizedPartUriString;
    }
    if (num < this._partList.Count - 1)
    {
        text2 = this._partList.Keys[num + 1].NormalizedPartUriString;
    }
    if ((text != null && normalizedPartUriString.StartsWith(text, StringComparison.Ordinal) && normalizedPartUriString.Length > text.Length && normalizedPartUriString[text.Length] == PackUriHelper.ForwardSlashChar) || (text2 != null && text2.StartsWith(normalizedPartUriString, StringComparison.Ordinal) && text2.Length > normalizedPartUriString.Length && text2[normalizedPartUriString.Length] == PackUriHelper.ForwardSlashChar))
    {
        this._partList.Remove(partUri);
        throw new InvalidOperationException(SR.Get("PartNamePrefixExists"));
    }
}

代码在断言时失败,因为这是调用FailFast 的唯一方法

internal static void Assert(bool condition, string invariantMessage)
{
    if (!condition)
    {
        Invariant.FailFast(invariantMessage, null);
    }
}

现在的问题仍然是为什么在PartList数组中找不到包。WPF为您填充了一些内容。可能是你通过互联网地址或网络共享从XAML引用了一些资源,如果嵌入式Windows的网络子系统还没有准备好,这些资源可能会失败吗?