tags:

views:

177

answers:

3

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.

+1  A: 

Did you update the namespace of the class in the x:Class attribute on UserControl in the XAML too?

Failing that, have you tried rebuilding the project?

Drew Noakes
+4  A: 

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" ...
Joe White
that was it: just needed to chnage the the x:class= entries and all was fine again, thanks!
Edward Tanguay
A: 

This usually is the result of other errors, that need fixing first.. Check all errors in your error log, and fix the first.. then try again...

Hope this helps..

Arcturus