Search code examples
c#windows-embedded

Event Viewer reporting my C# application crashed through 'System.Environment.FailFast()'


My application is running on Windows Embedded Standard 7 and launches when the OS boots up.

Sometimes on the first load, I will get an Unknown Hard Error, and after checking the Event Viewer, I see a message of

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

Needless to say, I of course have no calls to this function. I only seem to see this happen on Windows Embedded, and haven't seen this reproduced on a standard install of Windows.

I'm unsure of how to diagnose this or what 'fix' would be appropriate as I don't really know why it happens.

Edit:

The entire log in Event Viewer:

    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()

Solution

  • If you look at the code with a decompiler you will find

        // 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"));
        }
    }
    

    The code fails at the assert because that is the only method which calls FailFast

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

    Now the question remains why you package could not be found in the PartList array. WPF fills some things out for you. Could it be that you reference from your XAML some resource via an internet addresses or a network share which could fail if the network subsystem of your Windows embedded is not yet ready?