In PresentationFramework from .NET 4.5 there is a namespace called Standard. Look here for more info: What is the namespace 'Standard'?
The problem is that in my C++/CLI project I am using an unmanaged library, which also defines a class called Standard. So I get the following compiler error:
error C2869: 'Standard' : has already been defined to be a namespace
I cannot remove the reference to PresentationFramework, and I cannot stop using the said library. Is there anything I can do? Like un-importing the namespace?
P.S. I am using VisualStudio 2012. I think that an upgrade to 2013 might help, but that will require the whole team to move to it.
That namespace was added to PresentationFramework by .NET 4.5, I believe, and I don't think changing to Visual Studio 2013 will help you. Everything in that namespace is defined as internal, and it mostly consists of Enums and Structs used with Windows SDK functions called by PresentationFramework.
Unfortunately, I have no idea what to do about your problem. Perhaps you can convince whoever supplies the third-party library to change their namespace. The fact that Microsoft is now using it would be a good reason for them to do so. Whoever these people are that are creating namespaces with a simple, generic name such as "Standard" need to have their heads examined.
Related
The AutoComplete Function in VS2017 suggests me fully qualified using statements.
I have two projects with following (simplified) structure:
Company.Contracts
IMyExample.cs
Company.Core
MyExample.cs
Now when I use IMyExample in Class MyExample, VS2017 suggests me a using statement like
using Company.Contracts
But I think that there was a time when VS2017 suggested me:
using Contracts
which is sufficient as the projects share the same main namespace.
How can I configure VS2017 so that it prefers simplified instead of fully qualified namespaces? In fact this is the opposite of StyleCop Rule SA1135.
Hint: I was using VS2019 before but switchted back to VS2017 because the test licence ended and I'm pretty sure, that I didn't have to correct my using statements. Maybe in VS2019 this is possible?
Maybe in VS2019 this is possible?
Sorry but the answer could be negative, I test it in VS2019 release 16.3.4 and confirm this behavior is not supported for now.
In your situation, instead of using full qualified names, you can also use the format like Contracts.ClassName.
And for the reason why full qualified namespace is more preferred in this situation, assuming your current project Company.Core references one assembly whose root namespace is also named Contracts, now if VS do what you suggested, add the using Contracts when you use functions from Company.Contracts project, the intellisense would be confused about this. See:
In that situation you suggested, VS intellisense may get confused about what the using Contracts really mean, another assembly whose root namespace is Contracts or Company.Contracts project? So I think this could be one possible reason why it suggests full qualified namespace.
And if you do need one option which supports this behavior, I suggest you can send a feature request here.The team would consider about it if this request gets enough votes.
Hope my answer makes some help:)
I've ran into this issue a couple times and I'm wondering if anyone has a better solution than trial and error or searching stack overflow.
Lets say we are using some .net class Foo
Foo resides in the Bar.Baz namespace
The following statement
using Bar.Baz;
is not sufficient to compile the program, we are missing an assembly reference. So add a reference to System.Bar.Baz It still doesn't work so after searching the internet I find that I actually have to add a reference to Some.Other.dll and now it compiles.
My question is how do I know what namespace maps to what reference when the usual one doesn't work?
Most recent problem was
The type or namespace name 'DbContext' could not be found Instead of adding a reference to System.Data.Entity I had to install through Nuget.
If it is a .NET framework function, you can just search it on MSDN, and it will tell you in which assembly the class/function exists.
You can also use ReSharper which is a very nice plugin to Visual Studio, and it can help you add assemblies automatically.
If you're using Visual Studio 2013 or higher, one easy way to discover which namespace a class belongs to is using the Peek definition feature. You can easily find it in the right-click context menu.
In the screen below, I used it with KeyValuePair:
Also, take a look at the documentation.
I'm unable to use Validator class belongs to System.ComponentModel.DataAnnotations namespace in WPF. Don't know whether Validator class is shipped with that DLL or not. I'm using .NET 4.5 Framework. As per Microsoft release notes Validator class can be used from .NET 4.0 version and I'm using higher version that that.
I know something silly is getting missed. Any help would be highly appreciated.
The simplest answer to this question is to add System.ComponentModel.DataAnnotations DLL as a reference to your project.
Now that's surprise me. The using statement (using System.ComponentModel.DataAnnotations;) didn't throw any error even there is no reference of System.ComponentModel.DataAnnotations DLL added in the project. But the only problem was that Validator class was not available.
The moment I added DLL, I'm able to use Validator class. Shouldn't it be an error before only when I used Using statement without adding DLL? Or, is it a known bug? Or, am I missing something again?
I am brand new to Visual Studio. I have been coding in Java for many years but have taken on a project which requires me to use c# and visual studio 2012.
What I need to know is how to utilize a different SDK. I want to use something called Honeywell SDK instead of Visual Studios inherent SDK but I cannot find out where to change this setting. If anyone has an answer that would be greatly appreciated!
as a Java developer you are probably used to imports and presumably understand how to use the import statement to import the classes in a namespace.
In C#, the first thing you must do is add a reference to the library containing the methods you require - this is normally done by right clicking your project in Solution Explorer, clicking add reference, and then selecting browse to browse to the location what is normally a DLL containing the library methods in question.
Once you have added a reference to your project, you can access the classes in the library either using a fully qualified name, e.g. to access the Thread class in .NET's System.Threading namespace for example, fully qualified use would be as follows:
System.Threading.Thread thread = new Thread();
Alternatively, you can put a using directive at the top of each file where you intend to use the client to avoid the need for the fully qualified name. For example:
using System.Threading;
Then in code, you can simply use the shortened version of the class name by itself:
Thread thread = new Thread();
As you can see, the using directive is effectively C#'s equivalent of Java's import directive. Note that to import all classes in a namespace you do not need the .* wild card at the end of the using directive as you do an equivalent Java import statement.
In practice, you may need to refer to the documentation you have to confirm what namespaces they use, and what files you need to add references to to use their libraries as this detail will be vendor specific. For more detail and a more thorough explanation of the using directive then the MSDN documentation is likely to be the most helpful source:
http://msdn.microsoft.com/en-gb/library/sf0df423%28v=vs.80%29.aspx
and:
http://msdn.microsoft.com/en-gb/library/z2kcy19k%28v=vs.80%29.aspx
There is no inherent SDK per-se in a .NET project, though normally references to the .NET framework and default using directives will be added. You will probably find these useful as they contain core functionality and the references normally added by default in a new project will provide you access to things such as collections and so forth.
One final note is that C# has a using statement, as well as the using directive, so if searching for additional information on the directive, be careful not to confuse it for the using statement.
I'm having the following problem using the Visual Studio 2010 Team System Beta 1:
While working on some printing code, I tried to declare a variable of type System.Printing.PrintTicket, but Visual Studio doesn't seem to recognize that the class exists. It appears in the MSDN documentation, and other classes like System.Printing.PrintQueue have variables of type PrintTicket, but even in those cases VS doesn't recognize it as a valid type.
Does anyone knows if that is a bug, or am I missing something??
Thanks...
PD: I have the required reference to the System.Printing.dll file in my project and the required 'using' directive in the class file. As a matter of fact, every class of the System.Printing namespace that I've used works, except for that one.
Ok, I'm definitely an idiot. The problem was that the PrintTicket object is defined in a different assembly than the rest of the System.Printing namespace. I believe that MS should change that but...
Thats it...
Edit: In response to Ivix question, the Assembly where the PrintTicket is defined is ReachFramework (the filename is ReachFramework.dll)
PrintTicket is a .NET 4.5 function, but the Visual Studio 2010 just support up to .NET 4.0.
If you are using Windows XP, .NET version can only up to be 4.0