Search code examples
c#using

'Using' not detecting namespace-checked client profiling already


I have a C# solution composed of three projects in Visual Sudio 2010. One is X.Domain (class library) the second, X.UnitTest and the third X.WebUI (MVC3). I was having problems with the using statement to reference the X.Domain namespace from withing the X.WebUI namespace. I thought it was a client profiling issue and verifired that all of the projects where using ".Net Framework 4" as the target framework. I checked to make sure the project dependencies for X.WebUI included the namesapce X.Domain. The exact errors I'm getting are: The type or namespace name 'Domain' does not exist in the namespace'X' (are you missing an assembly reference). The error for the interface I'm trying to use from within X.Domain.Abstract: The type or namespace name 'IPersonRepository' could not be found (are you missing a using directive or an assembly reference)

In the X.Domain namespace/project, there are public methods, so I'm not sure why it's not exposed. I looked into these links here on stackoverflow, but they did not resolve the issue. Visual Studio 2010 suddenly can't see namespace?, The type or namespace name could not be found , The type or namespace 'MyNamespace' does not exist etc

It's worth mentioning that someone posted that it could have something to do with a missed configured global.asax file, here Type or namespace name does not exist in that link, but I'm not sure about it. Could be the case, so I am posting my Global.asax file as well. I noticed the problem when I'm trying to create my 'PersonController' with ninject MVC3, I used Remo.gloo's blog to help me create the Global.asax file as posted here http://www.planetgeek.ch/2010/11/13/official-ninject-mvc-extension-gets-support-for-mvc3/ and am following along with some additional code on p.164 of the the Pro ASP.NET MVC3 Framework book to create the controller.

PersonController.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using KLTMCInsight.Domain.Abstract;


namespace KLTMCInsight.WebUI.Controllers
{
    public class PersonController : Controller
    {
        private readonly IPersonRepository repository;

        public PersonController(IPersonRepository personRepository)
        {
            repository = personRepository;
        }
    }
}

Global.asax

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using System.Reflection;
using Ninject;
using Ninject.Modules;
using Ninject.Web.Mvc;

namespace KLTMCInsight.WebUI
{

    public class MvcApplication : NinjectHttpApplication
    {
        public static void RegisterGlobalFilters(GlobalFilterCollection filters)
        {
            filters.Add(new HandleErrorAttribute());
        }

        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                "Default", // Route name
                "{controller}/{action}/{id}", // URL with parameters
                    new { controller = "Home", action = "Index", id = UrlParameter.Optional    }
            );

        }

        protected override IKernel CreateKernel()
        {
            var kernel = new StandardKernel();
            kernel.Load(Assembly.GetExecutingAssembly());
            return kernel;
        }


        protected override void OnApplicationStarted()
        {
            base.OnApplicationStarted();

            AreaRegistration.RegisterAllAreas();
            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);
        }
    }
}

If I missed something you need, I'll be more than glad to post it up. Again, Thank you for your help- Very appreciated.


Solution

  • Here is the solution:

    I had used the 'Project Dependencies' box listed under the 'Project' file menu to select the dependencies of the X.WebUI project. Even though on in it I had checked the box for the X.WebUI project to depend on the X.Domain project... the reference was never created by VS2010.

    To solve the issue it was a simple fix by manually right-clicking the References folder under X.WebUI, and adding the reference to X.Domain through that window. Reference was added problem solved.

    Not sure why the reference was not made from the 'Project Dependencies' box in the first place, but if anyone comes across this same problem- this should remind you to check if the reference was actually made.