Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have three asp.net mvc 5 projects in one solution. The solution is called "Bank24" so the assembly too. Project "Application_layer" is main project. Also there is 2 more projects. There are "BusinessLogic_layer" where I'm working with database and "Data layer" where I'm creating database.

When I attempting to use class from "BusinessLogic_layer" in "Application_layer" I'm getting runtime server error - "Could not load type "BusinessLogic_layer.Services.DataService" from assembly "Bank24, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"."

Project "Application_layer" already has reference to "BusinessLogic_layer". Directory that contains needed class already linked with "Using" directive. So I don't know why it doesen't loading.

Here is code of Controller "MainController". I need to use desired class in method "Register". It is linked with "using BusinessLogic_layer.Services;"

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Microsoft.AspNet.Identity;
using Application_layer.Models;
using BusinessLogic_layer.Services;

namespace Application_layer.Controllers
{
[Authorize]
public class MainController : Controller
{

    ...

    public UserManager<ApplicationUser> UserManager { get; private set; }

    [HttpGet]
    [AllowAnonymous]
    //[ValidateAntiForgeryToken]
    public void Register()
    {
            var user = new ApplicationUser() { UserName = "Admin" };
            var result = UserManager.Create(user, "q1w2e3");
            if (result.Succeeded)
            {
                DataService dataWorker = new DataService();
                dataWorker.CreateUser("Admin", "Суренко Иван Васильевич", 0);
                RedirectToAction("Login", "Authorization");
            }
    }
}
}

Here is code of "DataService" class which is in "Services" folder of another project

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using BusinessLogic_layer.Models;
using Data_layer.DataAccess;
using Data_layer.Models;

namespace BusinessLogic_layer.Services
{
public class DataService
{
    ...

    public void CreateUser(string login, string name, byte role)
    {
        bool isEmployee = false;
        if (role == 0)
            isEmployee = true;
        BankContext db = new BankContext();
        db.Users.Add(new User() { Login = login, Name = name, Role = role, IsEmployee = isEmployee });
        db.SaveChanges();
    }

    ...

}
}

P.S. I have Visual Studio 2013

share|improve this question
1  
Check the target .NET Framework for each project. If, for example, your Application_Layer targets 4.0 and your Business_Layer targets 4.5, you would receive an error similar to this, even though the reference is set correctly and the namespaces are also used correctly. –  Alex Barac 1 hour ago
    
@AlexBarac The target .NET Framework for all projects is 4.5. I've ckecked it before asking. –  Alex Pritchin 1 hour ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.