9

The line using System.Windows.Documents; produces the following compile error:

The type or namespace name 'Documents' does not exist in the namespace 'System.Windows' (are you missing an assembly reference?)

I tried finding the assembly in the "add references..." dialog, but System.Windows.Documents was not listed, as it usually is when this error occurs.

Which assembly do I need to add for this using clause?

BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
Matthew Sainsbury
  • 1,470
  • 3
  • 18
  • 42
  • 12
    Do we want a question like this for every namespace in .NET? The question _"How to find in which assembly a type resides"_ is _"Check MSDN"_. For example the type [`System.Windows.Documents.DocumentPage` is, according to MSDN](https://msdn.microsoft.com/en-us/library/system.windows.documents.documentpage(v=vs.110).aspx), in "Assembly: PresentationCore (in PresentationCore.dll)". – CodeCaster Jan 28 '15 at 11:54
  • Ah, I looked at https://msdn.microsoft.com/en-us/library/System.Windows.Documents%28v=vs.110%29.aspx trying to find it, but I see you have to go deeper into the single class you want. Thanks for pointing that out – Matthew Sainsbury Jan 28 '15 at 11:59
  • Actually I just properly understood the differences between namespaces and assemblies now, thanks to your comment. I updated my answer to be more helpful – Matthew Sainsbury Jan 28 '15 at 12:05

1 Answers1

13

Classes in this namespace are contained in the Presentation Framework assembly, and this is the reference you need to add.

This assembly also provides classes for these namespaces:

  • System.Windows.Documents
  • System.Windows.Media
  • System.Windows.Media.Animation
  • System.Windows.Shell

Note that assemblies (physical collections of classes) do not provide namespaces (logically organization of classes) per se, they contain classes which have their own classification in namespaces. So it is possible for an assembly to "contain" many namespaces, and it is possible for a namespace to appear in many assemblies. This explains why it is not listed on the MSDN page for System.Windows.Documents (Thanks CodeCaster and Damien_The_Unbeliever)

Patrick Hofman
  • 153,850
  • 22
  • 249
  • 325
Matthew Sainsbury
  • 1,470
  • 3
  • 18
  • 42
  • 30
    This post seems to suggest that it is encouraged: http://blog.stackoverflow.com/2011/07/its-ok-to-ask-and-answer-your-own-questions/ – Matthew Sainsbury Jan 28 '15 at 09:59
  • 22
    Also, stack overflow itself lets you answer your own question while posting it: https://imgur.com/mSVBDte – Matthew Sainsbury Jan 28 '15 at 10:04
  • 2
    There's no 1-N mapping between assemblies and namespaces. A single assembly can contribute types to multiple namespaces (as you seem to understand here), but *multiple* assemblies can contribute types to the *same* namespace. Therefore, it's generally *not* sound to say that a namespace is contained within a particular assembly. – Damien_The_Unbeliever Jan 28 '15 at 10:07
  • @Damien_The_Unbeliever thanks for the comment - would it be more accurate to say that the assembly *provides* the namespace? Not sure what I should have said – Matthew Sainsbury Jan 28 '15 at 10:15
  • 5
    @AndyKorneyev Answering one's own question is allowed and encouraged, as long as both are up to SO quality standards. The Ask a Question page even has a special feature for this. http://stackoverflow.com/help/self-answer – JLRishe Jan 28 '15 at 15:42
  • @Matt You can @ tag a user so that they know you've directed a message at them. – JLRishe Jan 28 '15 at 15:43