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.
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" ...
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.
I found another way to solve this by deleting your 'obj' folder and rebuilding.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With