The type or namespace name 'Window' does not exist in the namespace 'System.Windows'

13,536

Add PresentationFramework.dll reference to your project it contains the System.Windows namespace.

http://msdn.microsoft.com/es-es/library/system.windows.window(v=vs.110).aspx

Share:
13,536
JoeMjr2
Author by

JoeMjr2

Updated on June 13, 2022

Comments

  • JoeMjr2
    JoeMjr2 almost 2 years

    I am trying to write an extension method for the WPF Window class. I am doing it in a class library project in my solution, so that I can use it in all my projects in the solution.

    Here is my code:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows;
    
    namespace ExtensionMethods
    {
        public static class MyExtensions
        {
            public static void ResizeToPrimaryScreenWorkingArea(this System.Windows.Window w)
            { 
            }
        }
    }
    

    When I try to compile this, I get the following error:

    The type or namespace name 'Window' does not exist in the namespace 'System.Windows'

    Yes, I DID add references to System.Windows and System.Windows.Forms in my class library project, and they are showing under References in the project in Solution Explorer.

    What am I doing wrong?

  • Tom Blodget
    Tom Blodget about 10 years
    @JoeMjr2 You need to understand that there is no required relationship between the name of an assembly and the namespaces of any types it defines. Nor any requirement that all types in a namespace be defined in a single assembly. The documentation link in the answer specifies the assembly for the class you are trying to use.
  • JoeMjr2
    JoeMjr2 about 10 years
    Tom, excellent point! I'd never thought about it that way. In most cases the assembly names and namespaces jive, but I guess not always. I'll be sure to check that line in the docs from now on!