Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

After changing namespace in UserControl files, ...g.cs files get errors

Tags:

wpf

I copied three classes in from another WPF project and then changed their namespaces.

Now when I run the project, I get errors in the ".g.cs" files which say that the namespace is incorrect. I change this namespace but when I compile and run again, the ".g.cs" files get regenerated and overwritten with the old namespace version and I get the error again.

What are the files and how can I make them be regenerate from the current files instead of some cache that its obviously holding somewhere?

I deleted the \bin and \obj directories and rebuilt but still get the errors.

like image 250
Edward Tanguay Avatar asked Jun 05 '09 12:06

Edward Tanguay


3 Answers

The .g.cs file is generated from the .xaml file. You need to change the x:class= attribute in your .xaml file to match the new namespace-qualified class name; then the .g.cs will be generated correctly on next compile. (Don't manually change the .g.cs file -- you'll only frustrate yourself.)

For example, if you previously had this in your .cs:

namespace Foo {
    class Bar { ...

and this in your .xaml:

<UserControl x:Class="Foo.Bar" ...

And then you changed your namespace:

namespace Baz {
    class Bar { ...

Then you would need to change your .xaml file to:

<UserControl x:Class="Baz.Bar" ...
like image 132
Joe White Avatar answered Oct 21 '22 01:10

Joe White


Another possible cause is if you have any xmlns:xx namespaces in your xaml which you neglected to update when changing a namespace, then this will also cause an invalid using statement in the g.cs file.

like image 10
William Avatar answered Oct 21 '22 02:10

William


I found another way to solve this by deleting your 'obj' folder and rebuilding.

like image 7
Chris Shepherd Avatar answered Oct 21 '22 02:10

Chris Shepherd