-
Notifications
You must be signed in to change notification settings - Fork 309
TestServer - Crash when calling a razor view #954
Comments
Had the same issue.. After some digging found a working solution.. The roslyn compiler used in Razor doesn't include the referenced assemblies of the main assembly.. In the test class add the following code.. Works on my machine ™️
|
@JvanderStad thank a lot, it worked but I had to add these assemblies : But I am wondering why this not already configured in the testserver plumbing. |
Sure np. But I think it's a bug 🐛, |
I have the same issue! |
I closed it too quickly because I was able to move on with the workaround. |
@Eilon can @NTaylorMullen or someone from Razor look into this? |
You need to copy your applications deps.json file into your test application. See what we do here in MVC to make this work. |
I think this is a dup of aspnet/Mvc#3410. |
@Eilon I'm not so sure this is a dupe. I'm using the right ContentPath, but my tests still fail according to the original description. When I purposefully break my ContentPath, I get a distinctly different error indicating an InvalidOperationException with a message indicating my view can't be found in the content-path-relative locations. |
Check that. Turns out it's microsoft/vstest#428 that's the core issue. #959 (comment) worked for me as a workaround in case anyone else stumbles here. |
@amattie ah ok thank you! |
The above workaround is working for me except for pages that use @ViewBag. The exception I get is "Missing compiler required member 'Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo.Create'" I tried to add "assemblies.Add(MetadataReference.CreateFromFile(Assembly.Load(new AssemblyName("Microsoft.CSharp")).Location));" to the list of RazorViewEngineOptions but that throws an error not finding the assembly. I also have the fixes in my .csproj from #959 (comment) The failing test project is .net461 calling a asp.net core 461 site |
Are there some plan to repair this problem? |
Dudes this is terrible... and closed as duplicated but no pointer to the duplicated issue so that we can track it?! |
It's right here aspnet/Mvc#3410 (comment) |
For anyone targeting .Net Framework 4.7.1 or 4.7.2 this worked for me previous?.Invoke(context); var assembly = typeof(Startup).GetTypeInfo().Assembly; string netVersion = "v4.7.2"; context.Compilation = context.Compilation.AddReferences(assemblies); |
HI
I am using thedefault AspNetCore WebApplication (netcoreapp1.1) template (no modification) and a default .NET Core Unit test project
Every package have been updated to 1.1
The unit test is as simple as :
When trying to call an the "/Home/About" (or any other action that render a view) I can stepin in the action code, but as soon as the action return anc ompile the view I get this error :
Note that the site is working if I start it normally.
The text was updated successfully, but these errors were encountered: