简体   繁体   中英

Class in namespace can't find a sibling class in the same namespace that it inherits

My exact code looks like this:

// ContractsUserControl
namespace AC.WebGUI.UserControls
{
    public partial class ContractUserControl : BaseUserControlObject
    {
        // Obviously stuff goes here.
    }
}

// BaseUserControlObject
namespace AC.WebGUI.UserControls
{
    public class BaseUserControlObject : System.Web.UI.UserControl
    {
        // A single property is declared here.
    }
}

When I debug with Visual Studio this works 100% perfectly fine, but when run on the live server, I get a compilation error:

CS0246: The type or namespace name 'BaseUserControlObject' could not be found (are you missing a using directive or an assembly reference?)

I don't understand how this can happen given that both classes exist in the same namespace and given that both classes are public so no using reference should be necessary.

Everything I know about ASPX says this should work so I don't even know where to begin finding the cause of the problem.

Assemblies and namespaces are two different things. Even if the classes are in the same namespace, they can be in different assemblies and if for some reason an older version of the assembly containing the base class is loaded that actually does not contain the base class BaseUserControlObject , then you'd get exactly this error message.

Upon debug, Visual Studio usually compiles everything, so this is why you would not see the exception in debug, but maybe your deployment tool for the server did not recognize that the assembly containing BaseUserControlObject had an outdated version.

Edit: One thing that I could imagine why the server deployment failed is that an older version of the library was added to the GAC, but the version number has not been increased. In that case, the server would load the assembly from the GAC instead the local one. However, this is only a wild guess.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM