Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
tmeschter opened this issue Apr 26, 2017 · 1 comment
Closed

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

tmeschter opened this issue Apr 26, 2017 · 1 comment

Comments

@tmeschter
Copy link
Contributor

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()
@livarcocc
Copy link
Contributor

I believe you are missing a dotnet restore after adding the reference from the WebApp to the ClassLibrary. I tried this here now and it worked and hitting About display the appropriate message coming from the ClassLibrary.

mmitche pushed a commit to mmitche/sdk that referenced this issue Jun 5, 2020
…204.4 (dotnet#1155)

- Microsoft.DotNet.Arcade.Sdk - 5.0.0-beta.19604.4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants