Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove an old namespace from a g.cs File?

I previously had a subfolder in my WPF application project called "Controls". It contained a WPF user control. I decided to move that user control to my "Views" folder. Since the original folder was empty, I decided to delete it from the project.

Because the user control and folder is removed I receive a compilation error because the user control used the ProjectName.Folder namespace and now nothing references it. MainWindow.g.cs is what references ProjectName.Controls in a using statement.

I know that *.g.cs are generated by VS and can't be edited because it will be overwritten. What do I do to not allow that namespace to be written to the g.cs file? I tried cleaning my solution/project and rebuilding but nothing has worked.

like image 272
Jeff LaFay Avatar asked Nov 17 '10 15:11

Jeff LaFay


4 Answers

I had a local reference to the Controls namespace in my Xaml code (MainWindow.xaml). I removed the reference, cleaned the project and produced a successful build.

like image 116
Jeff LaFay Avatar answered Oct 23 '22 23:10

Jeff LaFay


In your user control file,

In your ClassName.xaml, you must change the namespace as shown below

<UserControl
    x:Class="YourOldNamespace.ClassName"
    ...
    ...
/>

And in your ClassName.xaml.cs, you must change the namespace as shown below

using System;
using System.Windows;

namespace YourOldNamespace{

   public class ClassName{ ....

}

In both the files, you must replace YourOldNamespace to some new namespace as needed.

like image 22
Akash Kava Avatar answered Oct 23 '22 23:10

Akash Kava


I have had problems with g.cs files in my projects before too. Since they are auto generated, I tend to just delete the file manually and rebuild.

like image 25
Jason Avatar answered Oct 23 '22 22:10

Jason


Dont forget too, that you must check to see if the Build Action property when you click on the affected XAML file is set to PAGE (instead of resource). This is useful to know when you copy a XAML from another project using copy-paste to save time.

like image 26
dazonkah Avatar answered Oct 23 '22 23:10

dazonkah