Если я открою новое окно из класса MainWindow, я получил исключение InvalidOperationException. Исключение вызывается вызовом метода InitializeComponent().InvalidOperationException by InitializeComponent
Я не знаю, что делать.
ItemWindow itemWindow = new ItemWindow()
{
WindowStartupLocation = WindowStartupLocation.CenterScreen,
Topmost = true
};
itemWindow.ShowDialog();
Ошибка возникает при вызове метода во второй раз.
Послание:
Объект Application в настоящее время закрыты.
Источник: PresentationFramework
StackTrace:
на System.Windows.Application.GetResourcePackage (Uri packageUri)
на System.Windows.Application.LoadComponent (компонент Object, Uri resourceLocator)
в Project.View.ItemWindow.InitializeComponent() в d: \ Documents \ Visual Studio 2012 \ Projects \ Project \ View \ ItemWindow.xaml: строка 1.
в Project.View.ItemWindow .. ctor() в d: \ Documents \ Visual Studio 2012 \ Projects \ Project \ View \ ItemWindow.xaml.cs: строка 45.
в Project.View.EditButton_OnClick (отправитель объекта, RoutedEventArgs e) in d: \ Documents \ Visual Studio 2012 \ Projects \ Project \ View \ MainWindow.xaml.cs: линия 479.
Edit: проблема occours только в режиме отладки.
Редакция 2: Проблема возникает не только в режиме отладки, но и в режиме разблокировки.
Трассировка стека, нажав первый раз:
PresentationFramework.dll System.Windows.Application.CriticalShutdown (интермедиат ExitCode) Строка 340
PresentationFramework.dll System.Windows.Window.UpdateWindowListsOnClose()! линия 4621
PresentationFramework.dll! System.Windows.Window.InternalDispose() линия 2380
PresentationFramework.dll! System.Windows.Window.WmDestroy() линия 4660
PresentationFramework.dll! System.Windows.Window.WindowFilterMessage (System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam, ref bool обрабатывается) Строка 4349 + 0x7 Байт
PresentationCore.dll! System.Windows.Interop.HwndSource.PublicHooksFilterMessage (System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam, ref bool обрабатывается) Строка 1811 + 0x16 байтов
WindowsBase.dll! MS.Win32.HwndWrapper.WndProc (System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam, ref bool обрабатывается) Строка 345 + 0x16 Bytes
WindowsBase.dll! MS.Win32.HwndSubclass.DispatcherCallbackOperation (объект о) линия 494 + 0x18 Bytes
WindowsBase.dll! System.Windows.Threading.ExceptionWrapper.InternalRealCall (System.Делегирование callback, object args, int numArgs) Строка 111 + 0xa Байт
WindowsBase.dll! MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen (источник объекта, метод System.Delegate, object args, int numArgs, System.Delegate catchHandler) Строка 41 + 0x17 Байт
WindowsBase.dll! System.Windows.Threading.Dispatcher.LegacyInvokeImpl (System.Windows.Threading.DispatcherPriority priority, System.TimeSpan timeout, метод System.Delegate, object args, int numArgs) Строка 1447 + 0x2d Bytes
WindowsBase.dll! MS.Win32.HwndSubclass.SubclassWndProc (System.IntPtr HWND, внутр тзд, System.IntPtr WPARAM, System.IntPtr LPARAM) линия 398
[Род Managed Перехода]
[Успела Native Перехода]
WindowsBase.dll! MS.Win32.HwndSubclass.DefWndProcWrapper (System.IntPtr HWND, внутр тзд, System.IntPtr WPARAM, System.IntPtr LPARAM) Строка 672 + 0x29 Bytes
[Родом Managed Перехода]
[Успели Native Transition]
WindowsBase.dll! MS.Win32.HwndSubclass.SubclassWndProc (System.IntPtr HWND, внутр тзд, System.IntPtr WPARAM, System.IntPtr LPARAM) Строка 424 + 0x1a Bytes
[Род Managed перехода]
[Управляется нативный переход]
WindowsBase.dll! MS.Win32.HwndSubclass.DefWndProcWrapper (System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam) Линия 672 + 0x29 байт
[Род Managed Перехода]
[Успел Native Перехода]
WindowsBase.dll! MS.Win32.HwndSubclass.SubclassWndProc (System.IntPtr HWND, внутр тзд, System.IntPtr WPARAM, System.IntPtr LPARAM) Линия 424 + 0x1a Bytes
[Род Managed Перехода]
[Успел Native Перехода]
WindowsBase.dll! MS.Win32.HwndSubclass.DefWndProcWrapper (System.IntPtr HWND, внутр тзд, System.IntPtr WPARAM, System.IntPtr LPARAM) Линия 672 + 0x29 Байт
[От управляемого к управляемому переходу]
[Управляемый к естественному переходу]
WindowsBase.dll! MS.Win32.HwndSubclass.SubclassWndProc (System.IntPtr HWND, внутр тзд, System.IntPtr WPARAM, System.IntPtr LPARAM) Строка 424 + 0x1a Bytes
[Род Managed Перехода]
[Успела Native Переход]
WindowsBase.dll! System.Windows.Threading.Dispatcher.PushFrameImpl (System.Windows.Threading.DispatcherFrame рамка) линия 2281 + 0x38 Bytes
WindowsBase.dll! System.Windows.Threading.Dispatcher.PushFrame (System. Windows.Threading.DispatcherFrame) Строка 368 + 0x9 байт
PresentationFramework.dll! System.Windows.Window.ShowHelper (объект booleanBox) Строка 5745 + 0xb Байт
PresentationFramework.dll! System.Window s.Window.Show() строки 211 + 0x1D Bytes
PresentationFramework.dll! System.Windows.Window.ShowDialog() Строка 456 + 0x7 Bytes
Test.exe! Test.FormMain.tab_Click (объект отправителя, System.EventArgs e) Строка 405 + 0xd Байты
System.Windows.Forms.dll! System.Windows.Forms.Control.OnClick (System.EventArgs e) Строка 8504 + 0xf Байт
System.Windows.Forms.dll! System.Windows .Forms.Button.OnClick (System.EventArgs е) линия 278 + 0x9 байт
System.Windows.Forms.dll! System.Windows.Forms.Button.OnMouseUp (System.Windows.Forms.MouseEventArgs mevent) линия 308
System.Windows.Forms.dll! System.Windows.Forms.Control.WmMouseUp (ref System.Windows.Forms.Message m, System.Windows.Forms.MouseButtons, int clicks) Строка 13171 + 0x274 Байт
System.Windows.Forms.dll! System.Windows.Forms.Control.WndProc (ref System.Windows.Forms.Message m) Строка 13920
System.Windows.Forms.dll! System.Windows.Forms.ButtonBase.WndProc (ref System.Windows.Forms.Message m) Строка 1308 + 0xa Байт
System.Windows.Forms.dll! System.Windows .Forms.Button.WndProc (ref System.Windows.Forms.Message m) Линия 397 + 0x7 Байты
System.Windows.Forms.dll! System.Windows.Forms.Control.ControlNativeWindow.OnMessage (ref System.Windows.Forms .Message m) Строка 14207 + 0xe Байт
System.Windows.Forms.dll! System.Windows.Forms.Control.ControlNativeWindow.WndProc (ref System.Windows.Forms.Messa ge m) Строка 14262 + 0xb Байты
System.Windows.Forms.dll! System.Windows.Forms.NativeWindow.DebuggableCallback (System.IntPtr hWnd, int msg, System.IntPtr wparam, System.IntPtr lparam) Строка 779 + 0xe Б
[Род Managed Перехода]
[Успел Native Transition]
System.Windows.Forms.dll! System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop (System .IntPtr dwComponentID, int reason, int pvLoopData) Строка 2082
System.Windows.Forms.dll! System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner (int reason, System.Windows.Forms.ApplicationContext context) Строка 3422 + 0x1b Байт
System.Windows.Forms.dll! System.Windows.Forms.Application.ThreadContext.RunMessageLoop (int reason, System.Windows.Forms.ApplicationContext context) Строка 3306 + 0xc Байты
System.Windows.Forms.dll! System. Windows.Forms.Application.Run (System.Windows.Forms.Form MainForm) линия 1495 + 0x31 Bytes
Test.exe! Test.Program.Main() Строка 38 + 0x1D Bytes
[Род Managed Перехода]
[Успели Native Перехода]
mscorlib.dll! System.AppDomain.ExecuteAssembly (строка assemblyFile, System.Security.Policy.Evidence assemblySecurity, строка [] арг) линия 2031 + 0x18 Bytes
Microsoft.VisualStudio.HostingProcess.Utilities. дл л! Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() + 0x27 байт
mscorlib.dll! System.Threading.ThreadHelper.ThreadStart_Context (объект состояние) Строка 68 + 0x27 байт
mscorlib.dll! System.Threading.ExecutionContext. RunInternal (System.Threading.ExecutionContext executeContext, System.Threading.ContextCallback callback, состояние объекта, bool preserveSyncCtx) Строка 581 + 0xd Байт
mscorlib.dll! System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executeContext, System. Threading.ContextCallback callback, состояние объекта, bool preserveSyncCtx) Строка 530 + 0xd Байт
mscorlib.dll! System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executeContext, System.Threading.ContextCallback callback, состояние объекта) Lin е 519 + 0xE Bytes
mscorlib.dll System.Threading.ThreadHelper.ThreadStart() линия 105 + 0x20 Bytes
[Родом Managed Перехода]
трассировки стека, нажав второй раз:
PresentationFramework.dll! System.Windows.Application.GetResourcePackage (System.Uri packageUri) линия 2278
PresentationFramework.dll! System.Windows.Application.GetResourceOrContentPart (System.Uri Uri) Линия 2256 + 0x14 Bytes
PresentationFramework.dll! System.Windows.Application.LoadComponent (компонентных объектов, System.Uri resourceLocator) Строка 486 + 0x16 Bytes
Test.exe! Test.Testversandt.InitializeComponent() Строка 1 + 0xb Байты
Test.exe! Test.Testversandt.Testversandt (строка html, строка subject) Строка 27 + 0x8 Байт
Test.exe! Test.FormMain.tab_Click (отправитель объекта, System.EventArgs e) Строка 404 + 0x21 Байты
System.Windows.Forms.dll! System.Windows.Forms.Control.OnClick (System.EventArgs e) Строка 8504 + 0xf Байты
System.Windows.Forms.dll! System.Windows.Forms.Button.OnClick (System.EventArgs e) Строка 278 + 0x9 байт
System.Windows.Forms.dll! System.Windows.Forms.Button.OnMouseUp (System.Windows.Forms.MouseEventArgs mevent) Строка 308
System.Windows.Forms.dll! System.Windows.Forms.Control.WmMouseUp (ref System.Windows.Forms.Message m, System.Windows.Forms.MouseButtons button, int clicks) Строка 13171 + 0x274 Байт
System.Windows.Forms.dll! System.Windows.Forms.Control.WndProc (ref System .Windows.Forms.Message m) Строка 13920
System.Windows.Forms.dll! System.Windows.Forms.ButtonBase.WndProc (ref System.Windows.Forms.Message m) Строка 1308 + 0xa Байт
System.Windows .Forms.dll! System.Windows.Forms.Button.WndProc (ref System.Windows.Forms.Message m) Линия 397 + 0x7 Байт
Sys tem.Windows.Forms.dll! System.Windows.Forms.Control.ControlNativeWindow.OnMessage (ref System.Windows.Forms.Message m) Строка 14207 + 0xe Байт
System.Windows.Forms.dll! System.Windows.Forms .Control.ControlNativeWindow.WndProc (ref System.Windows.Forms.Message m) Строка 14262 + 0xb Байты
System.Windows.Forms.dll! System.Windows.Forms.NativeWindow.DebuggableCallback (System.IntPtr hWnd, int msg, System.IntPtr WPARAM, System.IntPtr LPARAM) линия 779 + 0xE Bytes
[Родом Managed Перехода]
[Успели Native Перехода]
System.Windows.Forms.dll! System.Windows.Forms.Application.ComponentManager .System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop (System.IntPtr dwComponentI D, int reason, int pvLoopData) Строка 2082
System.Windows.Forms.dll! System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner (int reason, System.Windows.Forms.ApplicationContext context) Строка 3422 + 0x1b Байт
System.Windows.Forms.dll! System.Windows.Forms.Application.ThreadContext.RunMessageLoop (int reason, System.Windows.Forms.ApplicationContext context) Строка 3306 + 0xc Байты
System.Windows.Forms.dll! System. Windows.Forms.Application.Run (System.Windows.Forms.Form MainForm) линия 1495 + 0x31 Bytes
Test.exe! Test.Program.Main() Строка 38 + 0x1D Bytes
[Род Managed Перехода]
[Управляется естественным переходом]
mscorlib.dll! System.AppDomain.ExecuteAssembly (строка assemblyFile, System.Security.Policy.Evidence assemblySecurity, строка [] арг) Линия 2031 + 0x18 Bytes
Microsoft.VisualStudio.HostingProcess.Utilities.dll! Microsoft.VisualStudio. HostingProcess.HostProc.RunUsersAssembly() + 0x27 Bytes
mscorlib.dll! System.Threading.ThreadHelper.ThreadStart_Context (состояние объекта) линии 68 + 0x27 Bytes
mscorlib.dll! System.Threading.ExecutionContext.RunInternal (System.Threading. ExecutionContext executeContext, System.Threading.ContextCallback callback, состояние объекта, bool preserveSyncCtx) Строка 581 + 0xd Байт
mscorlib.dll! System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executeContext, System.Threading.ContextCallback callback, состояние объекта, bool preserveSyncCtx) Строка 530 + 0xd Байт
10 mscorlib.dll! System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executeContext, System.Threading.ContextCallback callback, состояние объекта) Строка 519 + 0xE Bytes
mscorlib.dll! System.Threading.ThreadHelper.ThreadStart() Строка 105 + 0x20 Bytes
[Род Managed Перехода]
Редактировать 3
Я нашел причину ,
Главное приложение написано в виде окон. На вкладке приложение выполняет элементhost с WPF-UserControl. Этот UserControl открывает WPF-окно. Закрыв это WPF-окно, WPF-UserControl также закрыт. (Критическое завершение)
Вставьте полное сообщение об ошибке. –
Вы пробовали открыть окно без предопределенных начальных и верхних свойств? – horHAY
вам нужно добавить дополнительные сведения к вашему вопросу – Muds