Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8360715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:32:01+00:00 2026-06-09T11:32:01+00:00

I developed a WPF Application where I have problems when closing the application. Only

  • 0

I developed a WPF Application where I have problems when closing the application.

Only on Windows 2003 PCs, the application throws the following exception on closing. But it does not seem to be thrown from my code, because I can’t get a callstack.

That’s why I can’t post any further details.

Do you have a clue where I can start digging into it?

System.InvalidOperationException was unhandled
  Message=Handle is not initialized.
  Source=mscorlib
  StackTrace:
       at System.WeakReference.set_Target(Object value)
       at System.Windows.Threading.Dispatcher.FromThread(Thread thread)
       at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
       at MS.Win32.UnsafeNativeMethods.IntDestroyWindow(HandleRef hWnd)
       at MS.Win32.HwndWrapper.DestroyWindow(Object args)
       at MS.Win32.HwndWrapper.Dispose(Boolean disposing, Boolean isHwndBeingDestroyed)
       at MS.Win32.HwndWrapper.Finalize()
  InnerException: 

Thanks for your ideas.

EDIT
I found out which lines of code produces the failure. But how can I fix it?

It’s the following line of code:

        try
        {
            return DesignerProperties.GetIsInDesignMode(new DependencyObject());
        }
        catch (Exception)
        {
            return true;
        }

I’m using this to check if the code runs in the designer. But on closing this code fails, although I catched the exception.

Any other ideas to check the designmode?
Thanks for your help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T11:32:03+00:00Added an answer on June 9, 2026 at 11:32 am

    To answer my own question …

    I could solve the issue by implementing a backing field for the IsInDesignMode Property. The backing field is now going to bet set within the constructor of the ViewModel, instead of my prior solution which checked the DesignMode on every method call.

    That means, that even within the Dispose Method it can be checked if the application is/was running in DesignMode.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hie Everyone I have 1st time developed SSRS in my WPF application.. but there
I have windows application developed based on WPF,i am going thur weird issue here.
I have problems with my current application which is developed in C# with WPF.
I have developed wpf application which calls a lot of processes and windows services
I have a WPF Keyboard Application, it is developed in such a way that
I'm experienced developing Windows client desktop apps with WPF, but I've never developed apps
For my WPF application I have developed a virtual keyboard. It runs fine on
I have developed WPF application which contains the menuitem. I set background color to
I have developed a WPF application in C# 4.0. This application is installing some
The application is developed with C# and WPF. I have a data binding to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.