Skip to content

Referencing 3.0 RCL project from 3.0 Web App results in 404 #4332

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

Closed
mkArtakMSFT opened this issue Nov 30, 2018 · 19 comments
Closed

Referencing 3.0 RCL project from 3.0 Web App results in 404 #4332

mkArtakMSFT opened this issue Nov 30, 2018 · 19 comments
Assignees
Labels
area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates bug This issue describes a behavior which is not expected - a bug. Done This issue has been fixed

Comments

@mkArtakMSFT
Copy link
Contributor

Describe the bug

Add a Razor Class Library(RCL) and reference from Web App 3.0, then run the project got 404 error.

To Reproduce

REPRO STEPS

  1. File > New Project > C# > ASP.NET Core Web Application > .NET Core ~ ASP.NET Core 3.0 > Web Application > NoAuth
  2. Right click the solution > Add > New project > ASP .NET Core Web Application > .NET Core ~ ASP.NET Core 3.0 > Razor Class Library
  3. Paste in Page1.cshtml file with the following code:

    Hello World

  4. Right click the Razor ClassLib project to build it
  5. Right click the Web App project and select Add > Reference. In the Reference Manager dialog, check the Razor Class Library project > OK
  6. Rebuild solution and run the Web App project, navigate to /MyFeature/Page1 in a web browser

A 404 error page shows up.
image

Expected behavior

The page loads just fine

Screenshots

image

Additional context

https://devdiv.visualstudio.com/DevDiv/_workitems/edit/738297

@mkArtakMSFT mkArtakMSFT added bug This issue describes a behavior which is not expected - a bug. 1 - Ready area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates labels Nov 30, 2018
@mkArtakMSFT mkArtakMSFT added this to the 3.0.0-preview2 milestone Nov 30, 2018
@NTaylorMullen
Copy link

NTaylorMullen commented Dec 3, 2018

So investigated this and we're missing some key features from the SDK and NuGet in regards to lifting transitive framework references from packages/projects into the deps.json. The tl;dr; of the issue is we don't end up thinking the Razor class library has a reference to MVC and therefore don't consider it as a candidate MVC assembly to translate into routes/other information.

Today we dive over the entire application graph (defined by deps.json) and look at each entries dependencies to see if it references one of MVC's many primary assemblies. If it does, we consider it for View discovery, otherwise we ignore it. This enables us to prevent loading every assembly in the world to enable a fast startup experience. Now that all of ASP.NET is a framework reference when we look at a dependent package/project that only targets a framework reference; we don't see that they're targeting MVC because the deps.json indicates they have 0 dependencies. Example:

  "Bug4332RCL/1.0.0": {
	"runtime": {
	  "Bug4332RCL.dll": {}
	},
	"compile": {
	  "Bug4332RCL.dll": {}
	}
  },

There are two issues tracking some of the efforts to manifest the understanding of a transitive project/package targeting a framework.

@dsplaisted @livarcocc Is it fair to say these two issues embody bringing FrameworkReference information into the deps.json?

@rynowak @pranavkm has this scenario been thought of in this new world of ours where everything is a framework reference? Were there other plans to fix this or was the plan to just wait for fixes from other teams?

/cc @natemcmaster

@NTaylorMullen
Copy link

Talked with @rynowak offline and his suggestion was to remove our filtering logic of "is a candidate MVC assembly". Main motivation behind this is now that ASP.NET is a framework reference we greatly limit the number of dlls we need to inspect. I'll give this a shot and work with @sebastienros to see what startup impact it has.

@dsplaisted
Copy link
Member

The NuGet issue is to reference FrameworkReferences in the assets file. I don't think we have plans to represent them in the deps file, though we could consider that if necessary.

@NTaylorMullen
Copy link

The NuGet issue is to reference FrameworkReferences in the assets file. I don't think we have plans to represent them in the deps file, though we could consider that if necessary.

Ah, ok. In regards to our requirements if i'm able to get by without needing the deps.json then we shouldn't need that. I'll keep this issue up-to-date

NTaylorMullen pushed a commit that referenced this issue Dec 5, 2018
…ared framework.

- This is required due to how AspNet Core is included via a framework reference now. In order to properly evaluate transitive projects that target AspNet Core 3.0 we'd need some level of information that they targeted a framework reference. This happens to be a missing feature in the sdk/nuget. Also, given that all of ASP.NET is now included via a framework reference the act of finding candidate assemblies to reduce the amount of assembly loads doesn't matter as much since we went from 100s of potential assemblies to only what the application currently targets.
- Fixed a test issue where calling into BasicApi tests resulted in the attempted loading of EFCore.Design. Problem is EFCore.Design wasn't a dependency of our functional test project because of PrivateAssets="true" and therefore, when we tried to find candidate assemblies we read in the BasicApiTest.deps.json but operated on the functional tests.deps.json. I could have added the EFCore.Design package to the functional test project to fix this but given that the package wasn't being used choose to remove it instead.
- Removed Mvc.Analyzers from AspNetCore.Mvc because it's no longer brought in via the shared framework. This was needed because with the new approach with always loading all dll's in an applications graph we'd attempt to load Mvc.Analyzers at which point we'd explode saying we couldn't load Roslyn (it's not available at runtime anymore).
- Updated tests to reflect new expectations in regards to application part type loading.

Addresses #4332
@NTaylorMullen
Copy link

Alright, so we tried to scan the whole world and ran into a ton of issues. Most importantly our perf got destroyed:

Description RPS CPU (%) Memory (MB) Avg. Latency (ms) Startup (ms) First Request (ms) Latency (ms)
baseline 14,207 86 365 20.8 849 172.9 1.3
After Change 14,774 88 441 19 1056 (+24%) 608.7 (+352%) 1.4

Sooo, that being said @dsplaisted / @livarcocc we'll need a transitive package/project framework reference to exist in the deps.json. I'll send an email out so we can talk more.

@NTaylorMullen
Copy link

Marking as blocked until dotnet/sdk#2729 is completed.

@mkArtakMSFT
Copy link
Contributor Author

Moving out to preview4 as the dependent work hasn't yet completed.

@mkArtakMSFT
Copy link
Contributor Author

mkArtakMSFT commented Mar 6, 2019

Talked to @nguerrera and @livarcocc regarding this. The dependent work will be available in 3.0.0-preview5 and this work will be unblock then.

@NTaylorMullen
Copy link

@mkArtakMSFT
Copy link
Contributor Author

#8428

@pranavkm pranavkm added 2 - Working and removed 1 - Ready blocked The work on this issue is blocked due to some dependency labels May 17, 2019
@pranavkm pranavkm added Done This issue has been fixed and removed 2 - Working labels May 20, 2019
@ghstahl
Copy link

ghstahl commented May 20, 2019

Lots of 3.0 talk going on here. Is this also going to get fixed in 2.2 or is that a dead branch? My problem #10331 happened on 2.2.

@pranavkm
Copy link
Contributor

Is this also going to get fixed in 2.2 or is that a dead branch?

@ghstahl we will usually consider targeted fixes for 2.1 \ 2.2. Unfortunately the approach we took to fix this issue incurred a fairly substantial change so porting it the change as-is wouldn't be an option.

@ebekker
Copy link
Contributor

ebekker commented Jul 3, 2019

Please note, in my experience using 3.0.0-Preview6, I'm still experiencing this issue.

The workaround described here to use the sample Add30AssemblyWorkaround does fix the issue for me.

@mkArtakMSFT
Copy link
Contributor Author

Hi @ebekker. The was fixed in a way, which doesn't require the parts discovery workaround any more. There were some follow-up issues we had to address during Preview 7 release, specific to the new model. Can you please be more specific what is the exact problem you're having?

@ebekker
Copy link
Contributor

ebekker commented Jul 5, 2019

If my ASP.NET Core web project just references an RCL library that contains a Razor Page, if I try to reference the page using the path that is either "implied" by the Page's directory path (e.g. /MyFeature/Page1 in the default project created by dotnet new razorclasslib) or explicitly specified in the @page directive (e.g. `@page "/testpage"), I get a 404 error.

If however, I also add the Add30AssemblyWorkaround call in my Startup.ConfigureServices, then both scenarios work as expected.

If you would like, I can provide a reference to a sample project. Or perhaps I should wait till preview 7 to retry my scenario.

@pranavkm
Copy link
Contributor

pranavkm commented Jul 5, 2019

If you would like, I can provide a reference to a sample project. Or perhaps I should wait till preview 7 to retry my scenario.

@ebekker could you please file a new issue and share a repro app?

@rodrmoya
Copy link

rodrmoya commented Nov 11, 2019

This seems to be happening still, at least on Mac, easy repro:

rodrigo@Rodrigos-MacBook-Pro:/tmp/test $ dotnet new sln
The template "Solution File" was created successfully.
rodrigo@Rodrigos-MacBook-Pro:/tmp/test $ dotnet new razorclasslib -s -o RazorUIClassLib
The template "Razor Class Library" was created successfully.

Processing post-creation actions...
Running 'dotnet restore' on RazorUIClassLib/RazorUIClassLib.csproj...
  Restore completed in 97.32 ms for /private/tmp/test/RazorUIClassLib/RazorUIClassLib.csproj.

Restore succeeded.

rodrigo@Rodrigos-MacBook-Pro:/tmp/test $ dotnet sln add RazorUIClassLib/RazorUIClassLib.csproj 
Project `RazorUIClassLib/RazorUIClassLib.csproj` added to the solution.
rodrigo@Rodrigos-MacBook-Pro:/tmp/test $ dotnet new mvc -o MvcApp
The template "ASP.NET Core Web App (Model-View-Controller)" was created successfully.
This template contains technologies from parties other than Microsoft, see https://aka.ms/aspnetcore/3.1-third-party-notices for details.

Processing post-creation actions...
Running 'dotnet restore' on MvcApp/MvcApp.csproj...
  Restore completed in 96.6 ms for /private/tmp/test/MvcApp/MvcApp.csproj.

Restore succeeded.
         
rodrigo@Rodrigos-MacBook-Pro:/tmp/test $ dotnet add MvcApp/MvcApp.csproj reference RazorUIClassLib/RazorUIClassLib.csproj 
Reference `..\RazorUIClassLib\RazorUIClassLib.csproj` added to the project.
rodrigo@Rodrigos-MacBook-Pro:/tmp/test $ cd MvcApp/
rodrigo@Rodrigos-MacBook-Pro:/tmp/test/MvcApp $ dotnet run
info: Microsoft.Hosting.Lifetime[0]
      Now listening on: https://localhost:5001
info: Microsoft.Hosting.Lifetime[0]
      Now listening on: http://localhost:5000
info: Microsoft.Hosting.Lifetime[0]
      Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]

@rodrmoya
Copy link

Forget it, this is due to the MVC project not having the correct AddMvc/MapRazorPages

@bhagyashree19sb
Copy link

bhagyashree19sb commented Nov 24, 2019

If my ASP.NET Core web project just references an RCL library that contains a Razor Page, if I try to reference the page using the path that is either "implied" by the Page's directory path (e.g. /MyFeature/Page1 in the default project created by dotnet new razorclasslib) or explicitly specified in the @page directive (e.g. `@page "/testpage"), I get a 404 error.

If however, I also add the Add30AssemblyWorkaround call in my Startup.ConfigureServices, then both scenarios work as expected.

If you would like, I can provide a reference to a sample project. Or perhaps I should wait till preview 7 to retry my scenario.

@ebekker Add30AssemblyWorkaround didn't work for me. Could you please share a reference to the sample project? Thanks in advance.

@ghost ghost locked as resolved and limited conversation to collaborators Dec 24, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates bug This issue describes a behavior which is not expected - a bug. Done This issue has been fixed
Projects
None yet
Development

No branches or pull requests

9 participants