Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are namespaces acting up in Visual Studio 2010?

I've just converted a project to VS 2010 and something really weird is going on with namespaces. Let me give an example, the following code used to work in VS2008:

namespace MySystem.Core.Object
{
    using MySystem.Core.OtherObject;
    ...
}

But now it doesn't, it either wants the whole thing to be put outside of the namespace like this:

using MySystem.Core.OtherObject;

namespace MySystem.Core.Object
{
    ...
}

or be rewritten it like:

namespace MySystem.Core.Object
{
    using OtherObject;
    ...
}

I understand why this works and maybe is the correct way of handling this, but now we'd have to change thousands of lines of code! Which is not cool.

Any idea to circumvent this requirement?

like image 931
Doguhan Uluca Avatar asked Apr 23 '10 23:04

Doguhan Uluca


People also ask

How do you fix the type or namespace name could not be found?

Solution 1If it has an "include" option, click that, and it should fix it. If it doesn't, you need to find out where that class is, and add a reference to uit, either via the project in the same solution, or via the DLL, and then add the appropriate using line to the top of all files that reference it.

How do I automatically add a namespace in Visual Studio?

To do it, you may either manually type the Using Namespace or you just right click on the class name and select Resolve > Namespace. But using “Ctrl+.” you can automatically add the namespace in your code.

What is a namespace in Visual Basic?

Namespaces organize the objects defined in an assembly. Assemblies can contain multiple namespaces, which can in turn contain other namespaces. Namespaces prevent ambiguity and simplify references when using large groups of objects such as class libraries.


1 Answers

It may be because you converted to C# from VB.NET. "Usings" in VB.NET are the same thing as "Imports" in C#. So when the conversion/upgrade took place, it figured you meant to use a using(){} statement and placed that inside the namespace. Rewrite your includes as "imports" and it should work.

like image 172
sohtimsso1970 Avatar answered Sep 28 '22 03:09

sohtimsso1970