13
votes

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?

3
If you comment ExitApplication() you don't have this issue? - DHN
See Application. It's located in PresentationFramework (in PresentationFramework.dll) C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\PresentationFramework.dll - Dustin Kingen
@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
Important lesson that using directives and references are completely separate concepts. - Damien_The_Unbeliever
Agreed, even if they are pretty standard Windows components. - Joetjah

3 Answers

25
votes

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.

8
votes

Add System.Xaml.dll to project references.

5
votes

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.