locked
Certification failure: out of memory exception on call to InitializeComponent()

    Question

  • My Windows Store App (XAML & C#) failed the crash and hang certification test, exiting with code C000027C.  I deployed it and ran it under the Application Verifier using the low resource simulation.  I put a breakpoint on the first line of the MainPage constructor (this.InitializeComponent();) and got there.  I then put a breakpoint on the next line (this.navigationHelper = new NavigationHelper(this);) and encountered an out of memory exception before I got there.  I assume this has to be a problem with the XAML code, but would like some advice on how to track it down. 

    The Debug output has multiple lines of symbol loading, ending with this:

    'BridgeTutor.exe' (CLR v4.0.30319: Immersive Application Domain): Loaded 'C:\WINDOWS\system32\WinMetadata\Windows.Foundation.winmd'. Cannot find or open the PDB file.
    A first chance exception of type 'System.OutOfMemoryException' occurred in BridgeTutor.exe
    A first chance exception of type 'System.OutOfMemoryException' occurred in mscorlib.dll
    A first chance exception of type 'System.OutOfMemoryException' occurred in mscorlib.dll
    A first chance exception of type 'System.Exception' occurred in BridgeTutor.exe
    A first chance exception of type 'System.OutOfMemoryException' occurred in mscorlib.dll
    A first chance exception of type 'System.OutOfMemoryException' occurred in mscorlib.dll
    A first chance exception of type 'System.OutOfMemoryException' occurred in mscorlib.dll
    A first chance exception of type 'System.OutOfMemoryException' occurred in mscorlib.dll
    A first chance exception of type 'System.OutOfMemoryException' occurred in mscorlib.dll
    Activation of the Windows Store app '50258W.PrestonGranbery.BridgeCoach_r7ftj9jccpfq8!App' failed with error 'Windows was unable to communicate with the target application.  This usually indicates that the target application's process aborted. More information may be available in the Debug pane of the Output window (Debug->Windows->Output)'.
    The program '[6436] BridgeTutor.exe' has exited with code 255 (0xff).

    I did not find that helpful.

    Friday, March 28, 2014 1:48 AM

Answers

  • Matt:

    The level of my ignorance must astound you.  I never did figure out how to 'log it somewhere' but I won't bore you with my missteps there.  Worse, I had forgotten about the "Suspend", "Resume" and "Suspend and Shutdown" functions of the VS debugger until reminded of it reading another post on another issue.  (For those reading this who are as ignorant as I, go to View -> Toolbar -> Debug Location to display the drop down buttons.)

    I fired up the program in debug mode, hit the "Suspend" button and bingo: exception in the Suspension Manager with the inner exception message: "Multi-dimensional arrays are not supported."  Sure enough, some of those variables I am storing in pageState are multi-dimensional.  Eliminating them fixed the problem.

    I do not believe the multi-dimensional array limitation is well publicized.  At least it surprised me.

    • Marked as answer by P Granbery Friday, April 11, 2014 2:00 PM
    Friday, April 11, 2014 2:00 PM

All replies

  • I am not confident that this is a valid course of action. The failure in the crash/hang certification test may not have anything to do with low memory condition.  Additionally, running the app in AppVerifier simulating a low memory condition means that your app will likely encounter an OOM.

    Do you have any crash dumps from the app when it fails certification?  I think those are more likely to be helpful than the simulated low memory condition.

    If you have any information which shows that there actually is a memory leak in your app, please let me know.


    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Friday, March 28, 2014 12:33 PM
    Moderator
  • I have crash dumps.  I will play with them some more this weekend (programming is my hobby, not my day job) but my recollection is that, when I loaded them into VS 2013 Express, did the set symbol path, and then, I believe, selected debug with mixed, I got the exception code 27C and everything in the stack was a dll with no source available.  I didn't know where to go from there, so I followed the suggestion to try the AppVerifier.

    If you have suggestions on what I should read to learn more about using crash dumps, that could be helpful.

    Friday, March 28, 2014 4:37 PM
  • Also, I have been reading up on memory leaks (long lunch hour) and I've got some.  For example, it never crossed my mind to unsubsribe from the SizeChanged event handlers when a page goes out of view.  I have some work to do on memory management, which sounds like the first step.
    Friday, March 28, 2014 5:58 PM
  • Matt:

    I am now quite sure I do not have any memory leaks.  After revising the code, I used the task manager to look at memory usage, and although every time I opened a new page in the program, the memory usage jumped, after I had opened every page and done all the operations at least once, the size pretty well stabilized.  I played with the program for a couple of hours, and it didn't grow any further, and when I ran other programs, the memory usage dropped back down to about where it started.  

    Nevertheless, it fails the certification test as before.  As before, the dump files show error code C000027B, no heap, and when I do the debug with mixed, the stack is full of dlls with no source code available.

    Where do I go to learn how to figure out what might be going on here?  I notice the debug output, after doing much symbol loading, has this as the last two lines:

    'BridgeTutor.exe.1964.dmp' (CLR v4.0.30319: Immersive Application Domain): Loaded '*C:\Program Files\WindowsApps\50258W.PrestonGranbery.BridgeCoach_1.1.0.4_x86__r7ftj9jccpfq8\BridgeTutor.exe'. No matching binary found.
    Unhandled exception at 0x7776A8E7 (combase.dll) in BridgeTutor.exe.1964.dmp: 0xC000027B: An application-internal exception has occurred (parameters: 0x0475F764, 0x00000001).

    Would the dump have been more informative if the matching binary had been found? Or is that usual?


    Sunday, March 30, 2014 10:33 PM
  • Can you display the callstacks of the threads in your app when it crashes?

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Monday, March 31, 2014 1:31 PM
    Moderator
  • Here are the callstacks of the threads with enable just my code checked

    Tuesday, April 1, 2014 1:21 AM
  • Here are the callstacks with enable just my code unchecked, left half and right half.

    I am afraid these do not mean much to me.

    Tuesday, April 1, 2014 1:25 AM
  • It looks to me that you're crashing on Suspend.  Are you handling the Suspend methods?


    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Tuesday, April 1, 2014 1:21 PM
    Moderator
  • Yes.  Is there a way that I can recreate what the certification kit is doing while running under the debugger so I can step through and see what the suspend code is doing?

    I am trying to recall now  .   .   .   .  I started porting this program from Windows 7 to Windows 8.  When I was about half done, Windows 8.1 came out and, as I recall, there was an upgrade from VS2012 to VS2013 at the same time.  When I opened the project in VS2013, there was some step to follow to port from 8 to 8.1.  I did that, but when I compiled the code, I got warnings about code that was deprecated, or something like that.  What I ultimately did was take each page that had been created under VS2012, copy the c# and XAML code I had written to a text file, delete the xaml and cs files, recreate the page with VS2013 and then paste the saved XAML and C# code into the new xaml and cs files.  That got rid of the warnings.

    The reason I am running on at the mouth about this is that I seem to recall at least some of the warnings had to do with code used in suspension, and maybe my cut and paste was too simplistic.  Just a thought.

    Tuesday, April 1, 2014 2:45 PM
  • Can you paste your suspend code here?

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Tuesday, April 1, 2014 5:21 PM
    Moderator
  • There is code generated by VS which I didn't touch except for adding the line to the OnNavigatedFrom routine to decouple the SizeChanged event handler like this:

            protected override void OnNavigatedFrom(NavigationEventArgs e)
            {
                this.SizeChanged -= SizeChange_Handler; //decouple event handler to enable garbage collection
                navigationHelper.OnNavigatedFrom(e);
            }
    


    This is the code for the navigationHelper.SaveState event

            private void navigationHelper_SaveState(object sender, SaveStateEventArgs e)
            {
                e.PageState["dealPreference"] = dealPreference;
                e.PageState["dealNumber"] = dealNumber;
                e.PageState["vulnerabilityCode"] = vulnerabilityCode;
                e.PageState["biddingComplete"] = biddingComplete;
                e.PageState["playComplete"] = playComplete;
                e.PageState["playing"] = playing;
                e.PageState["showHandsPostBid"] = showHandsPostBid;
                e.PageState["playAll"] = playAll;
                e.PageState["trumps"] = trumps;
                e.PageState["level"] = level;
                e.PageState["manualDeal"] = manualDeal;
                e.PageState["dealComplete"] = dealcomplete;
                e.PageState["defending"] = defending;
                e.PageState["dummyDisplayed"] = dummyDisplayed;
                e.PageState["doubleDummy"] = doubleDummy;
                e.PageState["rubberPending"] = rubberPending;
                e.PageState["Dummy"] = Dummy;
                e.PageState["currentPlayer"] = currentPlayer;
                e.PageState["cardnums"] = cardnums;
                e.PageState["mpBaseScore"] = mpBaseScore;
                e.PageState["scoringEnabled"] = scoringEnabled;
                e.PageState["gameScores"] = gameScores;
                e.PageState["aboveIndex"] = aboveIndex;
                e.PageState["belowIndex"] = belowIndex;
                e.PageState["gameNumber"] = gameNumber;
                e.PageState["gamesWon"] = gamesWon;
                e.PageState["cumulativeRubbers"] = cumulativeRubbers;
                e.PageState["cumulativePoints"] = cumulativePoints;
                e.PageState["chicagoPoints"] = chicagoPoints;
                e.PageState["matchPoints"] = matchPoints;
                e.PageState["numberOfGames"] = numberOfGames;
                e.PageState["baseScore"] = baseScore;
                e.PageState["deviation"] = deviation;
                e.PageState["pickedLevel"] = pickedLevel;
                e.PageState["pickedSuit"] = pickedSuit;
                e.PageState["simpleClub"] = simpleClub;
                e.PageState["traceTricks"] = traceTricks;
                e.PageState["traceLeaders"] = traceLeaders;
                e.PageState["suggestedBid"] = suggestedBid;
                e.PageState["theHint"] = theHint;
                e.PageState["allBidsExpected"] = allBidsExpected;
                e.PageState["delimeter"] = delimiter;
                e.PageState["duplicateScoring"] = duplicateScoring;
                e.PageState["autobidding"] = autoBidding;
                e.PageState["rubberGame"] = rubberGame;
                e.PageState["currentMatchPoints"] = currentMatchPoints;
    
                for (int i = 0; i < 4; i++)
                {
                    e.PageState["BidText" + i] = bidAreas[i].Text;
                    e.PageState["bidVisibility" + i] = bidAreas[i].Visibility;
                }
                e.PageState["westAreaVisibility"] = westBiddingArea.Visibility;
                e.PageState["eastAreaVisibility"] = eastBiddingArea.Visibility;
                e.PageState["northAreaVisibility"] = northBiddingArea.Visibility;
                e.PageState["southAreaVisibility"] = southBiddingArea.Visibility;
                e.PageState["playButton"] = playButton.IsEnabled;
                e.PageState["rebidButton"] = rebibButton.IsEnabled;
                e.PageState["southHandText"] = southHand.Text;
                e.PageState["westHandText"] = westHand.Text;
                e.PageState["northHandText"] = northHand.Text;
                e.PageState["eastHandText"] = eastHand.Text;
                e.PageState["southHandStatus"] = southHand.Visibility;
                e.PageState["westHandStatus"] = westHand.Visibility;
                e.PageState["northHandStatus"] = northHand.Visibility;
                e.PageState["eastHandStatus"] = eastHand.Visibility;
                e.PageState["getBidStatus"] = getBid.Visibility;
                e.PageState["bidLevelIndex"] = bidLevel.SelectedIndex;
                e.PageState["bidSuitIndex"] = bidSuit.SelectedIndex;
                e.PageState["twoOverOneMain"] = twoOverOne;
                e.PageState["staymanAsking"] = staymanInvitational;
                e.PageState["fourDiamonds"] = fourDiamonds;
                e.PageState["splinterBids"] = splinterBids;
                e.PageState["michaels"] = michaels;
                e.PageState["jacobyNT"] = jacobyNT;
                e.PageState["jacobyXfers"] = jacobyXfers;
                e.PageState["lebensohl2NT"] = lebensohl2NT;
                e.PageState["helpSuitGameTry"] = helpSuitGameTry;
                e.PageState["blackwoodCode"] = blackwoodCode;
                e.PageState["Bergan"] = Bergan;
                e.PageState["fourthSuitForcing"] = fourthSuitForcing;
                e.PageState["forceManipulationsToEnd"] = forceManipulationsToEnd;
                e.PageState["manipulatedCard"] = manipulatedCard;
                e.PageState["manipulatedHand"] = manipulatedHand;
                e.PageState["manipulationEnabled"] = manipulationEnabled;
                e.PageState["selectionEnabled"] = selectionEnabled;
                e.PageState["msg"] = msg;
                e.PageState["t"] = t;
                e.PageState["p"] = p;
                e.PageState["madeBid"] = madeBid;
                e.PageState["northBitMapImage"] = northBitmapImage;
                e.PageState["southBitMapImage"] = southBitmapImage;
                e.PageState["wesstBitMapImage"] = westBitmapImage;
                e.PageState["eastBitMapImage"] = eastBitmapImage;
                for (int i = 0; i < 13; i++)
                {
                    e.PageState["northCardsVisibility" + i] = northCards[i].Visibility;
                    e.PageState["southCardsVisibility" + i] = southCards[i].Visibility;
                    e.PageState["westCardsVisibility" + i] = westCards[i].Visibility;
                    e.PageState["eastCardsVisibility" + i] = eastCards[i].Visibility;
                }
                e.PageState["eastCanvasVisibility"] = eastHandCanvas.Visibility;
                e.PageState["westCanvasVisibility"] = westHandCanvas.Visibility;
                e.PageState["northCanvasVisibility"] = northHandCanvas.Visibility;
                e.PageState["southCanvasVisability"] = southHandCanvas.Visibility;
                e.PageState["tableBitMapImage"] = tableBitmapImage;
                for (int i = 0; i < 4; i++)
                {
                    e.PageState["tabledCardsVisability" + i] = tabledCards[i].Visibility;
                }
                e.PageState["vulnerabilityText"]=vulnerability.Text ;
                e.PageState["dealNumberText"]=dealNumMsg.Text ;
                e.PageState["trickDone"] = trickDone.IsOpen;
                e.PageState["dealDone"] = dealDone.IsOpen;
                e.PageState["statMsg"] = statMsg.Text;
                e.PageState["gameResults"] = gameResults.IsOpen;
                e.PageState["ressultsHeader"] = resultsHeader.Text;
                e.PageState["resultsMsg"] = resultsMsg.Text;
                e.PageState["scoreCard"] = scoreCard.IsOpen;
                e.PageState["weAbove"] = weAbove.Text;
                e.PageState["weBelow"] = weBelow.Text;
                e.PageState["theyAbove"] = theyAbove.Text;
                e.PageState["theyBelow"] = theyBelow.Text;
                e.PageState["endOfTrickDisplayed"] = endOfTrickDisplayed;
                e.PageState["endOfHandDisplayed"] = endOfHandDisplayed;
                e.PageState["gamesInMatch"] = gamesInMatch;
                e.PageState["handStore"] = handStore;
                e.PageState["numberOfHandsStored"] = numberOfHandsStored;
                e.PageState["aveScore"] = aveScore;
                e.PageState["hintButtonVisibility"] = hintButton.Visibility;
    #if trialVersion
                 e.PageState["licenseInformation"] = licenseInformation;
                 e.PageState["trialLicence"] = trialLicense;
                 e.PageState["validLicense"] = validLicense;
                 e.PageState["currentDaysRemaining"] = currentDaysRemaining;
    #endif
                deck.SaveState(e.PageState);
                PlayingHand.SaveState(e.PageState);
            }
    

    The deck SaveState method is this:

            public void SaveState(Dictionary<string, Object> pageState)
            {
                pageState["southHand"] = theBoard[0].Cards;
                pageState["westHand"] = theBoard[1].Cards;
                pageState["northHand"] = theBoard[2].Cards;
                pageState["eastHand"] = theBoard[3].Cards;
                pageState["round"] = round;
                pageState["dealer"] = dealer;
                pageState["theBidding"] = theBidding;
                pageState["bi"] = bi;
                pageState["staymanInvitational"] = StaymanInvitational;
                pageState["fourDiamondsAsking"] = fourDiamondsAsking;
                pageState["splinterBids"] = splinterBids;
                pageState["michaels"] = michaels;
                pageState["fourthSuitForcing"] = fourthSuitForcing;
                pageState["jacobyNT"] = jacobyNT;
                pageState["jacobyXfer"] = jacobyXfer;
                pageState["lebensohl2NT"] = lebensohl2NT;
                pageState["bigClub"] = bigClub;
                pageState["helpSuitGameTry"] = helpSuitGameTry;
                pageState["helpSuitGameTryOn"] = helpSuitGameTryOn;
                pageState["dealPreferenceInt"] = dealPreference;
                pageState["FirstBid"] = FirstBid;
                pageState["allPasses"] = allPasses;
                pageState["pMinPoints"] = pMinPoints;
                pageState["pmaxpoints"] = pMaxPoints;
                pageState["pMinCards"] = pMinCards;
                pageState["myMinCards"] = myMinCards;
                pageState["myMinPoints"] = myMinPoints;
                pageState["myMaxPoints"] = myMaxPoints;
                pageState["partScore"] = partScore;
                pageState["fourDiamondStatus"] = fourDiamondsStatus;
                pageState["firstBidder"] = firstBidder;
                pageState["controls"] = controls;
                pageState["demoBidding"] = demoBidding;
                pageState["lastPartnerBid"] = lastPartnerBid;
                pageState["active"] = active;
                pageState["bidding"] = bidding;
                pageState["passcount"] = passCount;
                pageState["bidExplanation"] = bidExplanation;
                pageState["thisBidExplanation"] = thisBidExplanation;
                pageState["lastBid"] = lastBid;
                pageState["doubleStatus"] = doubleStatus;
                pageState["lastBidder"] = lastBidder;
                pageState["twoOverOne"] = twoOverOne;
                pageState["lastBidBeforePartnerBid"] = lastBidBeforePartnerBid;
                pageState["rkBlackwood"] = rkBlackwood;
                pageState["myKeyCards"] = myKeyCards;
                pageState["knownKeyCards"] = knownKeyCards;
                pageState["Stage"] = Stage;
                pageState["fitSuit"] = fitSuit;
                pageState["noForce"] = noForce;
                pageState["rkbAvailable"] = rkbAvailable;
                pageState["grandSlam"] = grandSlam;
                pageState["twoOvrOne"] = twoOvrOne;
                pageState["bergan"] = bergan;
            }
    

    And the PlayingHand SaveState method is this:

                public void SaveState(Dictionary<string, Object> pageState)
                {
                    pageState["cardsPlayed"] = cardsPlayed;
                    pageState["leader"]=leader;
                    pageState["declarer"]=declarer;
                    pageState["dummy"] = dummy;
                    for (int i=0;i<4;i++)
                    {
                        pageState["unplayedCards" + i] = unplayedCards[i].Cards;
                        pageState["playedCards" + i] = playedCards[i].Cards;
                        pageState["theBoard" + i] = theBoard[i].Cards;
                    }
                    pageState["suitsPlayed"] = suitsPlayed.Cards;
                    pageState["suitsLeft"] = suitsLeft.Cards;
                    pageState["numberOfSuitTricks"] = numberOfSuitTricks;
                    pageState["trick"] = trick;
                    pageState["trickSuit"] = trickSuit;
                    pageState["trumpSuit"] = trumpSuit;
                    pageState["northSouthTricks"] = northSouthTricks;
                    pageState["eastWestTricks"] = eastWestTricks;
                    pageState["shortestDefensiveWinner"] = shortestDefensiveWinner;
                    pageState["suitPreferences"] = suitPreferences;
                    pageState["pickedSuit"] = pickedSuit;
                    pageState["pickedRank"] = pickedRank;
                    pageState["trumped"] = trumped;
                    pageState["highestRank"] = highestRank;
                    pageState["highestPlayer"] = highestPlayer;
                    pageState["voids"] = voids;
                    pageState["highLows"] = highlows;
                    pageState["lastFreeCard"] = lastFreeCard;
                    pageState["firstLead"] = firstLead;
                    pageState["doubletonSuit"] = doubletonSuit;
                    pageState["sequenceSuit"] = sequenceSuit;
                    pageState["trumpStat"] = trumpStat;
                    pageState["goodFinesse"] = goodFinesse;
                    pageState["thirdHandCode"] = thirdHandCode;
                    pageState["suitToRun"] = suitToRun;
                    pageState["cardCount"] = cardCount;
                    pageState["requireTricks"] = requiredTrincks;
                    pageState["desiredWinners"] = desiredWinners;
                    pageState["allowedLosers"] = allowedLosers;
                }

    I hope this is useful.

    Wednesday, April 2, 2014 1:40 AM
  • I don't see anything offhand that would cause a crash. Perhaps you can put try/catch blocks around the code to see if you can isolate it. Also, are you handling ApplicationUnHandledException?

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Wednesday, April 2, 2014 1:59 PM
    Moderator
  • I haven't tried try/catch blocks or an Application.UnHandledException handler when the program was running under the certification kit.  I will do that tonight.

    If I catch an exception, what do I do with it?  What is the recommended way to get the exception info to the user (me)?

    Wednesday, April 2, 2014 5:35 PM
  • Log it somewhere so you can figure out how to handle it when it occurs.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Thursday, April 3, 2014 2:03 PM
    Moderator
  • Matt:

    The level of my ignorance must astound you.  I never did figure out how to 'log it somewhere' but I won't bore you with my missteps there.  Worse, I had forgotten about the "Suspend", "Resume" and "Suspend and Shutdown" functions of the VS debugger until reminded of it reading another post on another issue.  (For those reading this who are as ignorant as I, go to View -> Toolbar -> Debug Location to display the drop down buttons.)

    I fired up the program in debug mode, hit the "Suspend" button and bingo: exception in the Suspension Manager with the inner exception message: "Multi-dimensional arrays are not supported."  Sure enough, some of those variables I am storing in pageState are multi-dimensional.  Eliminating them fixed the problem.

    I do not believe the multi-dimensional array limitation is well publicized.  At least it surprised me.

    • Marked as answer by P Granbery Friday, April 11, 2014 2:00 PM
    Friday, April 11, 2014 2:00 PM
  • I'm really pleased that it's working now. :-)

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Friday, April 11, 2014 4:13 PM
    Moderator