locked
ASP.NET MVC 5 - Server Error in '/' Application RRS feed

  • Question

  • User1583361731 posted

    Code to db workflow. Trying to query my db. When I use the below code I get the errors mentioned below? 

    Both Reference -> EntityFramework and Manager NuGet Packages for solution... show version 6.0.0

    public class CustomersController : Controller
        {
            private ApplicationDbContext _context;
    
            public CustomersController()
            {
                _context = new ApplicationDbContext();
            }
        
            protected override void Dispose(bool disposing)
            {
                _context.Dispose();
            }
        }


    Server Error in '/' Application.


    Could not load file or assembly 'EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

    Exception Details: System.IO.FileLoadException: Could not load file or assembly 'EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

    Source Error: 
    Line 14:         {
    Line 15:             _context = new ApplicationDbContext();
    Line 16:         }
    Line 17:     
    Line 18:         protected override void Dispose(bool disposing)

    Source File: C:\Users\cdpai\Documents\SourceCodeWC\trunk\ASP.NET\03 Working with Data\EntityFramework\EntityFramework\Controllers\CustomersController.cs    Line: 16 

    Assembly Load Trace: The following information can be helpful to determine why the assembly 'EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' could not be loaded.
    === Pre-bind state information ===
    LOG: DisplayName = EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
     (Fully-specified)
    LOG: Appbase = file:///C:/Users/cdpai/Documents/SourceCodeWC/trunk/ASP.NET/03 Working with Data/EntityFramework/EntityFramework/
    LOG: Initial PrivatePath = C:\Users\cdpai\Documents\SourceCodeWC\trunk\ASP.NET\03 Working with Data\EntityFramework\EntityFramework\bin
    Calling assembly : Microsoft.AspNet.Identity.EntityFramework, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.
    ===
    LOG: This bind starts in default load context.
    LOG: Using application configuration file: C:\Users\cdpai\Documents\SourceCodeWC\trunk\ASP.NET\03 Working with Data\EntityFramework\EntityFramework\web.config
    LOG: Using host configuration file: C:\Users\cdpai\Documents\IISExpress\config\aspnet.config
    LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
    LOG: Post-policy reference: EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
    LOG: Attempting download of new URL file:///C:/Users/cdpai/AppData/Local/Temp/Temporary ASP.NET Files/vs/7461f73a/4dfb86b1/EntityFramework.DLL.
    LOG: Attempting download of new URL file:///C:/Users/cdpai/AppData/Local/Temp/Temporary ASP.NET Files/vs/7461f73a/4dfb86b1/EntityFramework/EntityFramework.DLL.
    LOG: Attempting download of new URL file:///C:/Users/cdpai/Documents/SourceCodeWC/trunk/ASP.NET/03 Working with Data/EntityFramework/EntityFramework/bin/EntityFramework.DLL.
    WRN: Comparing the assembly name resulted in the mismatch: Major Version
    ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.
    

    Stack Trace: 
    [FileLoadException: Could not load file or assembly 'EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)]
       EntityFramework.Controllers.CustomersController..ctor() in C:\Users\cdpai\Documents\SourceCodeWC\trunk\ASP.NET\03 Working with Data\EntityFramework\EntityFramework\Controllers\CustomersController.cs:16
    
    [TargetInvocationException: Exception has been thrown by the target of an invocation.]
       System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) +0
       System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) +119
       System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) +232
       System.Activator.CreateInstance(Type type, Boolean nonPublic) +83
       System.Activator.CreateInstance(Type type) +11
       System.Web.Mvc.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType) +55
    
    [InvalidOperationException: An error occurred when trying to create a controller of type 'EntityFramework.Controllers.CustomersController'. Make sure that the controller has a parameterless public constructor.]
       System.Web.Mvc.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType) +178
       System.Web.Mvc.DefaultControllerFactory.GetControllerInstance(RequestContext requestContext, Type controllerType) +80
       System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext, String controllerName) +102
       System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory) +187
       System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state) +50
       System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContext httpContext, AsyncCallback callback, Object state) +48
       System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData) +16
       System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +103
       System.Web.<>c__DisplayClass285_0.<ExecuteStepImpl>b__0() +26
       System.Web.StepInvoker.Invoke(Action executionStep) +101
       System.Web.<>c__DisplayClass4_0.<Invoke>b__0() +22
       Microsoft.AspNet.TelemetryCorrelation.TelemetryCorrelationHttpModule.OnExecuteRequestStep(HttpContextBase context, Action step) +64
       System.Web.<>c__DisplayClass284_0.<OnExecuteRequestStep>b__0(Action nextStepAction) +54
       System.Web.StepInvoker.Invoke(Action executionStep) +85
       System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) +9980113
       System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +159
    Tuesday, February 26, 2019 12:33 PM

All replies

  • User197322208 posted

    uninstall the EF nuget

    re-install the EG nuget

    Also, do you have just the MVC project in the solution or you have MVC and another project that references EF?

    Tuesday, February 26, 2019 2:51 PM
  • User1583361731 posted

    One Solution...

    Still same exception after uninstall of EF and reinstall...

    Thank in advance.

    Tuesday, February 26, 2019 3:28 PM
  • User1120430333 posted

    One Solution...

    Still same exception after uninstall of EF and reinstall...

    Thank in advance.

    Did you deploy the solution? 

    I mean it's telling you what is wrong. It the program's manifest wants the EF DLL for EF6,  version such and such with the public key-token, which is what you picked up in development of the program. Either the DLL is not in the Bin folder, the wrong version of the DLL is there in the Bin folder  or a dependency DLL the main DLL needs is not there in the Bin folder.

    Tuesday, February 26, 2019 9:05 PM
  • User1583361731 posted

    I figured out the issue. Big bang migration. Started over with smaller migrations with not a problem...

    Thank you for your help.

    Wednesday, February 27, 2019 6:29 PM