-
Notifications
You must be signed in to change notification settings - Fork 312
MissingMethodException when referencing Microsoft.AspNetCore.TestHost in a .NET Core project that targets net461 #926
Comments
Possibly related to aspnet/Security#1046. @anurse Or some of the ongoing issues with the System.Net.Http packages... |
I'm seeing that this only repros when in a unit test project, not within a standalone console app. @dfaivre are you able to confirm that? It could be something related to the Test SDK in that case... |
It looks like the unit test runner is causing the binding redirects to be lost (because the actual executable is |
Thanks for looking into it @anurse. I can confirm it doesn't throw in the stand alone app. Updated the repro project with a console example. |
If anyone stumbles on this and wants a work around, I just copied all the code files from https://github.com/aspnet/Hosting/tree/dev/src/Microsoft.AspNetCore.TestHost into my unit test project. |
@dfaivre Can you try the following workaround?
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> Then try running tests again. That got it working for me when running |
@anurse Yep, that works for me too when running Updated the repro project. |
External: microsoft/vstest#428 |
- With kind help of giorgiog in slack. Solution: aspnet/Hosting#926
Same problem happened with xUnit. Adding |
Working workaround for NUnit OutOfMemory and this issue: http://bit.ly/2q8jbch . |
I've added the elements in the
After a long investigation I found out that it makes a difference whether the (custom) Is this related, any thoughts on how to fix this? |
This is just until the version issue with the asp.net core testing assembly is addressed: aspnet/Hosting#926
@KPStolk THANK YOU! That was immensely helpful to me! |
I am getting the same error in VS2017 15.3.5 with ASPNETCore MVC project (4.6.2) and a unit test project that has the following packages installed: Microsoft.AspNetCore.TestHost -Version 2.0.0 I already added the property groups to the unit test project and I now get this: Message: System.MissingMethodException : Method not found: 'Microsoft.Net.Http.Headers.MediaTypeHeaderValue Microsoft.Net.Http.Headers.MediaTypeHeaderValue.Parse(System.String)'. when it runs the following line of code:
|
@pamanes make sure all of your dependencies are updated to 2.0. Fee free to share your project file. |
This is what my web project looks like:
@Tratcher Just to be clear on what I am doing: I have a solution that contains an ASP.NET Core Web Application where I chose .NET Framework (4.6.1) on web template and then .NET Framework and ASP.NET Core 2.0 on the next wizard. Then a full .net framework 4.6.1 unit test project. with the packages I mentioned before. and I now get the following when running
|
I have a .NET standard 2.0 library that I was trying to test with an xUnit .Net Framework 4.7 project. I was getting a MissingMethodException error when using |
For those receiving the error System.AggregateException : One or more errors occurred. (Method not found: 'Microsoft.Net.Http.Headers.MediaTypeHeaderValue Microsoft.Net.Http.Headers.MediaTypeHeaderValue.Parse(System.String)' when running Test project please add explicitly reference to Microsoft.AspNetCore.Mvc and Microsoft.AspNetCore.StaticFiles to your dependencies:
Do it in your csproj file of your Test project. |
@seccijr your solution worked for me. Thanks! |
Cross posting the issue from here: dotnet/msbuild#1649
Reproduction code here: https://github.com/dfaivre/bugrepro_dotnetcore_missingmethod
It is only my best guess that this is an issue with the package. Maybe it's a NuGet issue? Or possibly an issue with the new MSBuild csproj format? Sorry if I'm wasting your time.
Summary
Using VS2016 RC, when referencing
Microsoft.AspNetCore.TestHost
(https://www.nuget.org/packages/Microsoft.AspNetCore.TestHost/) nuget package in a .NET Core project that targetsnet461
, aMissingMethodException
is thrown when trying to create an HttpClient:
It is also thrown when creating a "classic" .NET Framework class library and using
PackageReferences
for NuGet.The exception is not thrown when targeting
netcoreapp1.0
, or when creating a "classic" .NET Framework class library usingpackages.config
for NuGet.System Info
The text was updated successfully, but these errors were encountered: