user310291
user310291

Reputation: 38220

Old namespace still in .g.cs file when changing namespace of a referenced class

I have renamed the namespace of a referenced class and WPF compiler doesn't want to take it into account: it keeps prefixing MyOldNameSpace in .g.cs file:

[System.CodeDom.Compiler.GeneratedCodeAttribute
     ("PresentationBuildTasks", "4.0.0.0")]
public partial class MyClass: 
    MyOldNameSpace.MyReferencedClass, 
    System.Windows.Markup.IComponentConnector {

Why ? How to fix this ? What's this obscure .g.cs file ?

Upvotes: 13

Views: 9922

Answers (6)

Skippy VonDrake
Skippy VonDrake

Reputation: 846

Also check xmlns:local in Application.xaml. This had me going for a while...

Upvotes: 2

Artiom
Artiom

Reputation: 7837

In my case removing obj folder fixed the error.

Upvotes: 2

Guillermo Hernandez
Guillermo Hernandez

Reputation: 1184

Don't forget to change your Generic.xaml file too,

<ResourceDictionary 
                   xmlns:local="clr-namespace:MyOldNameSpace">
</ResourceDictionary>

Upvotes: 2

Howard
Howard

Reputation: 3848

Maybe another case is that the build action of your xaml is not "Page" but the other options.

Upvotes: 1

alpha-mouse
alpha-mouse

Reputation: 5003

Looks like you didn't change your MyClass.xaml file. There should be something like this on top of it

<MyClass x:Class="MyOldNameSpace.MyReferencedClass"

but should be "MyNewNameSpace.MyReferencedClass"

Upvotes: 22

Emond
Emond

Reputation: 50682

Close the .g.cs file. You can even delete it.

The g stands for generated, VS generates the wireing up between the code and the Xaml in this partial class.

Clean the solution and rebuild. That should fix it.

Upvotes: 7

Related Questions