Skip to content

Class library added to a web app not found at runtime #1155

Closed
@tmeschter

Description

@tmeschter

Installed VS: d15prerel 26426.1-Preview with the following workloads:

  • Universal Windows Platform development
  • .NET desktop development
  • Desktop development with C++
  • ASP.NET and web development
  • Office/SharePoint development
  • Mobile development with JavaScript
  • Visual Studio extension development
  • Linux development with C++

Note that VS isn't actually used in this repro, I just used it as a vehicle to get the tools.

Repro Steps

  1. Open a new command window (non-admin).
  2. mkdir Bug
  3. cd Bug
  4. dotnet new sln
  5. md WebApp
  6. cd WebApp
  7. dotnet new mvc --framework netcoreapp2.0
  8. cd ..
  9. md ClassLibrary
  10. cd ClassLibrary
  11. dotnet new classlib --framework netcoreapp2.0
  12. Edit Class1.cs, add the following to the class, and save:
public string GetHello()
{
    return "Hello from class library";
}
  1. cd ..\WebApp
  2. dotnet add reference ..\ClassLibrary\ClassLibrary.csproj
  3. cd ..
  4. dotnet sln add WebApp\WebApp.csproj
  5. dotnet sln add ClassLibrary\ClassLibrary.csproj
  6. cd WebApp
  7. Edit Controllers\HomeController.cs and update the About() method to the following, and save:
public IActionResult About()
{
    var c = new ClassLibrary.Class1();
    Console.WriteLine(c.GetHello());
    ViewData["Message"] = c.GetHello();

    return View();
}
  1. cd ..
  2. dotnet build
  3. cd WebApp
  4. dotnet run
  5. Open a browser and load http://localhost:5000 (or whatever port the web server is listening on).
  6. In the banner, click "About".

Expected Behavior

The "About" page includes the "Hello from class library" message.

Actual Behavior

An exception is thrown and the page does not render properly because ClassLibrary1 is not found:

fail: Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware[0]
      An unhandled exception has occurred: Could not load file or assembly 'ClassLibrary, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.
System.IO.FileNotFoundException: Could not load file or assembly 'ClassLibrary, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.
File name: 'ClassLibrary, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'
   at WebApp.Controllers.HomeController.About()
   at lambda_method(Closure , Object , Object[] )
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeActionMethodAsync>d__18.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeNextActionFilterAsync>d__16.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeInnerFilterAsync>d__21.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Mvc.Core.Internal.ResourceInvoker.<InvokeNextResourceFilter>d__18.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.AspNetCore.Mvc.Core.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context)
   at Microsoft.AspNetCore.Mvc.Core.Internal.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Core.Internal.ResourceInvoker.<InvokeFilterPipelineAsync>d__13.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Mvc.Core.Internal.ResourceInvoker.<InvokeAsync>d__11.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Builder.RouterMiddleware.<Invoke>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.<Invoke>d__6.MoveNext()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions