views:

172

answers:

2

My project went through a name change, which led to using ReSharper to change the name of namespaces throughout the solution. Everything compiles just fine, but my ASP.NET MVC views are no longer seeing any inherited classes. I've changed the namespace imports in web.config and everything, and I'm certain that the classes exist. They work if I refer to the fully-qualified class name (Name.Space.ClassName).

Why is this happening and how can I fix it?

EDIT: More detail:

Before refactoring, I had custom view page, master page, and user control classes:

SalesWeb.Mvc.Views.SalesWebViewPage
SalesWeb.Mvc.Views.SalesWebMasterPage
SalesWeb.Mvc.Views.SalesWebUserControl

After refactoring:

Wasabi.SalesPortal.Mvc.Views.SalesPortalViewPage
Wasabi.SalesPortal.Mvc.Views.SalesPortalMasterPage
Wasabi.SalesPortal.Mvc.Views.SalesPortalUserControl

In web.config, before refactoring:

<configuration>
    <system.web>
        ...
        <pages ...>
            ...
            <namespaces>
                ...
                <add namespace="SalesWeb.Mvc.Views" />
            </namespaces>
        </pages>
    </system.web>
</configuration>

After:

<configuration>
    <system.web>
        ...
        <pages ...>
            ...
            <namespaces>
                ...
                <add namespace="Wasabi.SalesPortal.Mvc.Views" />
            </namespaces>
        </pages>
    </system.web>
</configuration>

I've also changed the Inherits attribute on each of my views, master pages, and user controls. However, when attempting to visit the MVC application, it complains that SalesPortalMasterPage cannot be found, although I'm absolutely certain that it exists because I don't have any problems when referring to it as Wasabi.SalesPortal.Mvc.Views.SalesPortalMasterPage.

A: 

I have similar problems when the namespace is different than the namespace that holds the view. My issue is that when I use a strongly-typed view that references a class not in the web site's namespace, it doesn't recognize it if defined in the view itself. My solution is to create a codebehind file for each view and define the class there (so that it is in the same namespace) and have the view inherit from the codebehind class. I realize this is the old way to do it (and not recommended), but it's the only thing I've found that works. I stumbled on it because views that I had created with versions before the codebehind stopped being created by default still worked while views that were created without the codebehind failed to compile. You might want to try this to see if it resolves your problem.

I have reported this issue on Codeplex, btw.

EDIT: Based on your comment, you may not be seeing the same problem as me. You might want to check to see if the assembly name (and default namespace) have been updated in your project. Perhaps the issue is that the assembly name doesn't match your namespace.

tvanfosson
It's worked fine before. The only part that's changed is the first level of the namespace (SalesWeb -> Wasabi.SalesPortal).
David Brown
I updated my answer with another possibility.
tvanfosson
+1  A: 

Try cleaning your bin directory and do a rebuild. Sometimes an older dll lingers in the bin folder and mess up your references/namespacing.

Johannes Setiabudi