Can't find System.Windows.Vector in C#

20,886

Solution 1

Add a reference to WindowsBase.
The Vector class is defined in the WindowsBase.dll assembly within the System.Windows namespace.

Solution 2

System.Windows.Vector is a part of WPF, not Windows Forms, hence the difficulty you've having when trying to use it. You could add a reference to WindowsBase.dll, but given that it's intended for use in WPF applications, rather than Windows Forms applications, it's likely that you'd derive little benefit from doing so.

Microsofts decision to put WPF components in System.Windows and WinForms in System.Windows.Forms is a source of endless confusion on the internet, quite what was wrong with System.Windows.Presentation or similar for WPF, I'll never know!

Solution 3

To find out which assembly you have to add to your references, it can be very helpful to use a tool like ILSpy (OpenSource). There you can search for the type you need, and find out in which assembly it is implemented and which namespace you have to use.

Finding out the implementing assembly can be quite difficult, and i have to do it often. I found it to be a fast method and thought it can help you in the future.

Share:
20,886
Carl Walsh
Author by

Carl Walsh

Engineering software at Autodesk. Worked on Google BigQuery, Visual Studio CMake, and Powery Query.

Updated on November 11, 2020

Comments

  • Carl Walsh
    Carl Walsh over 3 years

    I'm making a Windows Forms application in Visual Studio 2010 Ultimate, but can't get the built-in Vector to work.

    Microsoft says that there is a System.Windows.Vector in the .NET Framework 4:

    Maybe I'm making some large mistake, but Visual Studio complains about trying to use Vector in any way, and it doesn't come up in the IntelliSense autocomplete:

    The line Vector v = new Vector(20, 30); gives

    Compile error Error 1 The type or namespace name 'Vector' could not be found (are you missing a using directive or an assembly reference?)"

    I tried including a using System.Windows at the top but that didn't solve the problem.

    I went to References -> Add Reference to try to find something to add, but nothing was obvious.

    The problem may be: Also listed with Vector in the System.Windows namespace, there are other classes like Rect or Application. I could use these as System.Drawing.Rectangle or System.Windows.Forms.Application, but none of these show up as part of some System.Windows namespace

    I've tried different things for about 2 hours, and found this related post (but Vector is part of .NET 4, so their fix doesn't seem worthwhile?) and this possibly related post but I do have .NET Framework 4 installed.

    Does anyone have an example of Vector? I know I could get a third party class, but I feel I'm missing something, and want to learn/have the solution posted for other people googling the same problem.

  • Rob
    Rob almost 13 years
    System.Windows.Vector is a class, not a namespace. There's nothing even remotely namespace related.
  • martinstoeckli
    martinstoeckli almost 13 years
    @Rob - Sorry, you are absolutely right and i will edit my answer. Nevertheless, it can be a real help to find the assembly and the namespace of a type.
  • Carl Walsh
    Carl Walsh almost 13 years
    Works great! I can't use the System.Windows namespace without creating ambiguity, but that's not a huge problem. Thanks again :)
  • krs013
    krs013 over 9 years
    I had a hard time finding WindowsBase until I realized that my target environment was .NET 2.0, so just as a heads up, make sure that you are using .NET 4.0 or newer to be able to add that reference.