13

I'm getting the error:

Error 1 The type 'System.Windows.Markup.IQueryAmbient' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Xaml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.

When doing the following:

public void ExitApplication()
{
    Application.Current.Shutdown();
}

The project is targeted to .NET 4.0, my Visual Studio is 2010, I tried adding

using System.Windows.Markup; with no succes, and

using System.Xaml; where Xaml doesn't exist in namespace System.

What should I do to fix this?

Joetjah
  • 6,292
  • 8
  • 55
  • 90
  • If you comment `ExitApplication()` you don't have this issue? – DHN Mar 15 '13 at 14:15
  • See [Application](http://msdn.microsoft.com/en-us/library/ms588794.aspx). It's located in PresentationFramework (in PresentationFramework.dll) C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\PresentationFramework.dll – Dustin Kingen Mar 15 '13 at 14:16
  • @DHN true, my application works fine. But if I close the application, background threads continue to run so it's never really closed. That's why I'm trying to use this. – Joetjah Mar 15 '13 at 14:17
  • 1
    Important lesson that `using` directives and references are completely separate concepts. – Damien_The_Unbeliever Mar 15 '13 at 14:22
  • Agreed, even if they are pretty standard Windows components. – Joetjah Mar 15 '13 at 14:23
  • Background threads always die when you exit the application normally. You obviously have some foreground threads running somewhere. Find why and how to terminate them gracefully before trying anything like `Application.Shutdown` or `Environment.Exit`. – Luaan Aug 03 '15 at 11:39

3 Answers3

25

Well ok, I guess your issue is solved when you add System.Xaml.dll as reference to your project. The interface is declared there. Here is the doc.

DHN
  • 4,807
  • 3
  • 31
  • 45
  • Oh, I had to add the reference. I thought this worked before so I didn't even looked at that. Thank you! – Joetjah Mar 15 '13 at 14:21
8

Add System.Xaml.dll to project references.

Antonio Bakula
  • 20,445
  • 6
  • 75
  • 102
5

You need to add a reference to System.Xaml in your main application project. Using System.Xaml is not needed to be in your code.

TimVK
  • 1,146
  • 6
  • 16