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

  • Home
  • SEARCH
  • 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 554407
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:42:23+00:00 2026-05-13T11:42:23+00:00

I have a WPF UserControl, which I use in a WinForms Control within an

  • 0

I have a WPF UserControl, which I use in a WinForms Control within an ElementHostControl. Then I start a WPF Window, while the Windows Form is still open. If I then close the WPF Window, and try to add a Child Element to my WPF UserControl, it crashes at “InitializeComponent()” (of the Child Element) with the exception:

“A first chance exception of type ‘System.Configuration.ConfigurationErrorsException’ occurred in System.Configuration.dll.
Additional information: This element is not currently associated with any context”

I found out why it happens, but I don’t know how to solve the problem. If I leave out this code:

public static void EnsureApplicationResources()
    {
        if (Application.Current == null)
        {
            // create the Application object
            new Application();
            string assemblyName = System.IO.Path.GetFileNameWithoutExtension(
                Assembly.GetExecutingAssembly().ManifestModule.Name);

            // merge in your application resources
            Application.Current.Resources.MergedDictionaries.Add(
                Application.LoadComponent(new Uri("/KolonistenClient;component/KolonistenResourceDictionary.xaml", UriKind.RelativeOrAbsolute))
                as ResourceDictionary);
        }
    }

then everything is fine. I need that though, because of the fact that my ResourceDictionary (and thus also my defined styles and templates) is otherwise not available throughout the WPF Window and Controls. This I found out about here

Is there any way to combine the best of both worlds? Keeping my ResourceDictionary, while preventing the application from crashing?

  • 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-05-13T11:42:23+00:00Added an answer on May 13, 2026 at 11:42 am

    I solved it eventually by adding the ResourceDictionary in each Window manually through xaml. This way the UserControl in my WinForms stays unaffected.

    Still don’t understand exactly why it crashed though, unfortunately.

    <Window.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/KolonistenClient;component/KolonistenResourceDictionary.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Window.Resources>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

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.