I'm writing a C# WPF app with a tab control within a tab control. On the main tab control (tcMain) there are four tab items: tiOne, tiTwo, tiThree and tiFour. On tiOne there is another tab control (tcAnswers) that must be transferred to the selected tab when the user clicks on another of the four tabs on tcMain.
Problem: the app throws an error... Managed Debugging Assistant 'FatalExecutionEngineError' has detected a problem in 'QuestionaireApp.exe'.
Additional Information: The runtime has encountered a fatal error. The address of the error was at 0x6dfda7d0, on thread 0x20d8. The error code is 0x80131623. This error may be a bug in the CLR or in the unsafe or non-verifiable portions of user code. Common sources of this bug include user marshaling errors for COM-interop or PInvoke, which may corrupt the stack.
I checked the box at Tools >Options > Debugging > General >Use Managed Compatibility Mode Here's my code. The line where the error occurs has a comment.
private void tcMain_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
// First, let's get the old and new tab items...
TabItem tiOld = tcMain.Items[currentTab] as TabItem;
TabItem tiNew = tcMain.SelectedItem as TabItem;
// Good job! Now let's see which one is the selected tab item and remove the controls...
if (tiOld.Name != "tiMatchUp" && tiNew.Name != "tiMatchUp")
{
if (tiOld.Name == "tiOne")
{
RemoveStuff(grdOne);
}
else if (tiOld.Name == "tiTwo")
{
RemoveStuff(grdTwo);
}
else if (tiOld.Name == "tiThree")
{
RemoveStuff(grdThree);
}
else if (tiOld.Name == "tiFour")
{
RemoveStuff(grdFour);
}
// Now we add the controls to the newly selected tab item...
if (tiNew.Name == "tiOne")
{
grdOne = AddStuff(grdOne);
}
else if (tiNew.Name == "tiTwo")
{
grdTwo = AddStuff(grdTwo);
}
else if (tiNew.Name == "tiThree")
{
grdThree = AddStuff(grdThree);
}
else if (tiNew.Name == "tiFour")
{
grdFour = AddStuff(grdFour);
}
// Finally, we update the currentTab to the selected index...
CurrentTab = tcMain.SelectedIndex;
blProjectIsSaved = false;
}
private void RemoveStuff(Grid sentGrid)
{
sentGrid.Children.Remove(tcAnswers); //ERROR OCCURS HERE.
}
private Grid AddStuff(Grid sentGrid)
{
sentGrid.Children.Add(tcAnswers);
return sentGrid;
}
User contributions licensed under CC BY-SA 3.0