Click here to Skip to main content
15,891,749 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
down vote
favorite
using System.Data.Common.CommandTrees; 
It is showing an error as below :

"Error 3 The type or namespace name 'CommandTrees' does not exist in the namespace 'System.Data.Common' (are you missing an assembly reference?) "
in visual studio 2013.
Posted
Comments
Sergey Alexandrovich Kryukov 21-Dec-15 9:22am    
Are you missing an assembly reference? :-)
—SA

Add a reference to System.Data.Entity.dll in the Framework references
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 21-Dec-15 9:23am    
5.—SA
CHill60 21-Dec-15 9:42am    
Thank you. It was actually more work than such a short answer would indicate! Fortunately this reference was only the 3rd one I tried.
Sergey Alexandrovich Kryukov 21-Dec-15 10:23am    
I appreciate your effort, but I don't see where any trial is needed at all. Perhaps you are missing something.
This causes me to write detailed, universal, but very trivial answer as Solution 2.
The delicate thing is: this type of question does not guarantee compilation of the code using some namespace.

Please see.

—SA
In addition to Solution 1:

But here is a subtle point here, totally trivial at the same time. Such questions and answers don't resolve the reference problem in all cases. This is because reported compilation error is based on using directive (not to be confused with using statement), and, importantly, not the alias form of this directive. At the moment of generation of this error, the compiler does not yet "know" what type of the namespace causes the issue.

First of all, let me explain why answering of this question does not need any trial. On the example of this particular case, we search Google for the namespace "System.Data.Common.CommandTrees". It gives us no assembly name or main module name: https://msdn.microsoft.com/en-us/library/system.data.common.commandtrees%28v=vs.110%29.aspx[^].

Why not? Because two or more different assembly can declare different types in the same namespace. To answer the question, it's enough to point out just one assembly, then referencing this assembly will make the line in question compile. So, it's enough to click on any assembly-level type in the namespace, any at all; it will give the assembly, in this case, "System.Data.Entity.dll":
https://msdn.microsoft.com/en-us/library/system.data.common.commandtrees.dbaggregate(v=vs.110).aspx[^].

In most cases, all the types declared in assembly will be referenced by adding just one assembly to references. But it cannot be guaranteed. No matter, the question is answered, the "using" line is compiled. But further code many not compile, because it may need some other assembly reference, despite the same namespace. Anyone can define identical namespaces in different; and I cannot even call it unreasonable. Here is the simplest example from BCL:

Let's say, we reference only System assembly, and write
C#
using System; // will compile

// ...

Action myMethod = new Action(() => { Console.WriteLine("do something"); });


The code won't compile despite the fact that Console is just System.Console and Action is System.Action. Why? This is because System.Action is defined in "System.Core" which needs to be referenced, too.

By the way, I explained the rationale behind using Action, especially generic Action types, in my past article Hide Ad-hoc Methods Inside the Calling Method’s Body[^].

For a kind of conclusion, I want to emphasize the robustness of the alias form of using directive: https://msdn.microsoft.com/en-us/library/sf0df423.aspx[^].

Not only understanding of this matter can help asking more correct question of this forum, but it can be used as a complete instruction for answering all the questions of this kind.

—SA
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900