31

I have a very simple C# problem that loads a Windows WPF window from a library. Here's the code:

public partial class App : Application
{
    public App()
    {
        MainWindow mainWindow = new MainWindow();
        mainWindow.Show();
    }
}

But when I run it breaks on the mainWindow.Show(); line with the following error:

Managed Debugging Assistant 'LoadFromContext' has detected a problem in 'C:\Users.....\bin\Debug\Test.vshost.exe'.

Additional information: The assembly named 'WpfXamlDiagnosticsTap' was loaded from 'file:///C:/PROGRAM FILES (X86)/MICROSOFT VISUAL STUDIO 14.0/COMMON7/IDE/COMMONEXTENSIONS/MICROSOFT/CLIENTDIAGNOSTICS/XAMLDIAGNOSTICS/x64/WpfXamlDiagnosticsTap.dll' using the LoadFrom context.

The use of this context can result in unexpected behavior for serialization, casting and dependency resolution. In almost all cases, it is recommended that the LoadFrom context be avoided. This can be done by installing assemblies in the Global Assembly Cache or in the ApplicationBase directory and using Assembly.Load when explicitly loading assemblies.

The MainWindow class just extends from System.Windows.Window; I'm not exactly sure what this means and how to solve. Just upgraded to Visual Studio 2015.

enter image description here

enter image description here

If I ignore the exception and continue I get this when I close the last window:

enter image description here

Cœur
  • 37,241
  • 25
  • 195
  • 267
Jason
  • 13,563
  • 15
  • 74
  • 125
  • Since 2015 has not in been released yet...does this happen in 2013? – ΩmegaMan Jul 12 '15 at 01:13
  • @OmegaMan, it didn't, but not sure if a) I ignored the exception in 2013, b) created this with the upgrade, c) there's a bug in 2015, or d) everything is the same as before, but 2015 has a new exception. No matter what, I still don't understand what it means and/or how to fix it. – Jason Jul 12 '15 at 01:22
  • When you say it *breaks*, do you mean it breaks in the debugger or when running outside the debugger, *it throws* this exception? Also can you create a small test app and publish the code here so we can attempt to recreate it? – ΩmegaMan Jul 12 '15 at 01:32
  • when I start debugging, it throws an exception on that line and the debugger halts the program. If I continue, it still runs fine, util the program stops, and then it throws the same exception. I'll update the description with screenshots and see if I can create a small project to recreate – Jason Jul 12 '15 at 01:45

4 Answers4

44

I'm running into the same issue after switching from Visual Studio 2013 to 2015. Some old projects (WPF, .NET 4.5, MVVM Light) produce this error - other not. In visual Studio i can skip the exception but newly created releases stop while loading and try to open the JIT Debugger.

Until now the only solution seems to be a rollback to Visual Studio 2013.

** UPDATE **

Finally I solved it in VS 2015 by unchecking the following option:

Tools –> Options –> Debugging –> General –> Enable UI Debugging Tools for XAML

M. Altmann
  • 726
  • 5
  • 20
  • 7
    Isn't this just suppressing the error message though? Something is still generating these exceptions. – hughes Jan 29 '17 at 17:59
22

I all of a sudden started seeing this error in VS2015 and fixed it by opening the "Exception Settings" Window (CTRL + ALT + E) and press the "Restore Settings" Button :

enter image description here

Andy Braham
  • 9,594
  • 4
  • 48
  • 56
  • This resets ALL exceptions settings, answer https://stackoverflow.com/questions/31362077/loadfromcontext-occurred#answer-32789494 is much more precise. – Jack Miller Jun 20 '18 at 13:16
  • Thank you for the solution. I forgot I open all exception and while I do so whenever I try to use FolderBrowserDialog Class I got error – Shino Lex May 02 '19 at 12:48
3

In VS2015 I am getting two exceptions from WpfXamlDiagnosticsTap.dll

  1. The first one is "LoadFromContext" and it occurs when activating the first window.
  2. The second one is "NotMarshalable" and it occurs when closing that window.

Simply ignoring those two Exception types allows me to run the application, and use the UI Debugging tools. I haven't observed any adverse effects.

Denis P
  • 585
  • 2
  • 6
  • 17
1

Visual Studio creates a number of hidden files and folders within your solution that can stagnate over time and cause issues including the LoadFromContext error. Try closing Visual Studio, deleting the following files and folders, and reloading the solution:

  • .vs (folder)
  • *.suo
  • *.user

You may wish to back up anything you delete, but Visual Studio will regenerate these items automatically as needed.

Tawab Wakil
  • 1,737
  • 18
  • 33