Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't change a project's Default Namespace in Visual Studio 2013

I have a solution that includes various C# projects, and I just now noticed that I can't change the default namespace on any of them.

When I go to Properties --> Application on any of the project and change the "Default Namespace" field, a fatal error dialog pops up that says:

exception of type 'system.runtime.interopservices.externalexception' was thrown

At this point Visual Studio becomes unusable, as I can't close it or leave the screen, every click or button combination I press makes the same dialog pop up. The only thing I can do is terminate VS with the task manager.

like image 441
Master_T Avatar asked Jan 25 '14 10:01

Master_T


People also ask

How do I change the default namespace in Visual Studio?

Just right click on the name you want to change (this could be namespace or whatever else) and select Refactor->Rename... Enter new name, leave location as [Global Namespace], check preview if you want and you're done!

How do I change the default namespace in C#?

You could put the caret on a namespace declaration in your C# code and press F2 on the keyboard. This should let you change the name of the namespace across the entire project, including the XAML files.

How do I change the project name in Visual Studio 2013?

Right-click on the project name & click reload the project. Then rename the project name as highlighted below & save. It will automatically rename the .


2 Answers

I got around it by just renaming the <RootNamespace> node in the .csproj file

like image 100
MichelZ Avatar answered Nov 03 '22 00:11

MichelZ


Maybe you should try to do this in another way:

Ctrl-H - Find: PreviousNameSpaceName Replace: NewNamespaceName

You can also right click the namespace in code and Refactor->Rename.

What is more: you can change the names of your projects, solutions, directories - etc. Namespaces, when adding new files, are generated using these names in fact.

like image 40
Paweł Bejger Avatar answered Nov 02 '22 23:11

Paweł Bejger