-
Notifications
You must be signed in to change notification settings - Fork 323
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
Binding Redirects necessary to run Unit Tests on .NET Framework are not preserved when running in testhost
#428
Comments
@anurse and I played around with this more. We think this may be solved by forcing MSBuild to generate binding redirects. This does not normally happen for .NET Framework and OutputType=Library projects. <PropertyGroup>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
</PropertyGroup> |
@Eilon could you add this to your tracking list for VS2017 RTM? |
So I guess we'd need to add those MSBuild properties to test projects somehow, preferably through the Test SDK MSBuild package. |
This is going to block many people running tests in .NET Framework. As soon as you start adding NuGet packages, you begin to need binding redirects and if this isn't fixed, those redirects will fail and you'll get Assembly Load errors and Missing Method exceptions with no idea how to resolve them. I think this is a pretty important fix. |
- use specific workaround for microsoft/vstest#428 - generating an executable for a test project is a bit too weird - also work around dotnet/sdk#926 - generating an executable covered this as well nit: add and update comments about other workarounds in the functional tests project
- use specific workaround for microsoft/vstest#428 - generating an executable for a test project is a bit too weird - also work around dotnet/sdk#926 - generating an executable covered this as well nit: add and update comments about other workarounds in the functional tests project
…ests for aspnet core.
We're seeing customers hitting this now (aspnet/Hosting#959) |
* Nolocking extensions implemented for aspnetboilerplate#1637 * Add EfCoreTransactionStrategy * Implement EfCoreTransactionStrategy * Abp.Dapper package implemented for aspnetboilerplate#1661 * Dapper packoptions added on project.json * Abp.Dapper tests added * refactor for aspnetboilerplate#1661 * resolved aspnetboilerplate#1907 * Resolved aspnetboilerplate#1847: Trigger AbpHandledExceptionData for hangfire jobs too. * Fixed aspnetboilerplate#1875: Tenant Resolve Contributer renamed to Contributor (typo fix) * Resolved aspnetboilerplate#1886: Make TestAbpSession methods and properties virtual to allow overriding. * Use existing connection in the demo if available for EF Core. * aspnetboilerplate#1909: Refactor EF Core transaction strategy. Pass conn string to options builder. * aspnetboilerplate#1909 refactored DbContextEfCoreTransactionStrategy * aspnetboilerplate#1854 Correct version in project.json for dapper package. * Add Abp.Dapper to pack.ps1. * Resolved aspnetboilerplate#1827: Depend on JetBrains.Annotations instead of including annotations in Abp package. * Resolved aspnetboilerplate#1864: Set Http Status to 400 for validation exceptions. * Add WithNoLockInterceptor in AbpEntityFrameworkModule aspnetboilerplate#1823. * Resolved aspnetboilerplate#1892: Load plugin dependencies from plugin folder. * Incremented version to 1.5.0.0. * Resolved aspnetboilerplate#1915: Upgrade to AspNet Core v1.1.1. * Open solution on VS 2017, make it building (but not passing all unit tests yet). * Upgraded xunt and other nuget packages. * Create nuget packages after build. * Create Abp-fa.xml * Added bindings based on microsoft/vstest#428 to be able to run unit tests for aspnet core. * Passed all unit tests by applying microsoft/vstest#428 * Remove solution folder. * Change pack.ps1 for msbuild * Revised nuget packaging. * Fix appveyor.xml. * Move common project properties to a single file. Revise pack.ps1. * Change sln format. * update appveyor file * added RuntimeIdentifier. * Fix test dll paths in appveyor.xml * Temporarily remove NH tests for appveyor. * Check matched count on DomainTenantResolveContributor * Fixed aspnetboilerplate#1928: Fix Dapper namespaces. * Fix default namespaces for projects. * Resolved aspnetboilerplate#1934: Upgrade nuget package dependencies. * Fixed aspnetboilerplate#1923: Web API [DontWrapResult] Not Working with [AbpApiAuthorize] * Fixed aspnetboilerplate#1918: Can not handle model binding validation errors for dynamic web API actions. * aspnetboilerplate#1936 Remove Abp dependency from Abp.Web.Resources package. * Fixed aspnetboilerplate#1936: Abp.Web.Resources contents become flat with 1.5.1 release.
I just want to add myself as a customer being hit by this - it took me almost 2 days to figure it out, and making another developer scratch his head as I thought it was caused by his library. For now I added the 2 lines to my .csproj and it works fine - but I really would appreciate a quick fix. Thanks & best regards, |
1) microsoft#613 2) microsoft#428 3) microsoft#391 4) microsoft#595 Fix: Generate config file for test project targeting .NET Framework. This config file has have binding redirect which is needed at time of running tests.
* `dotnet migrate` all the projects, moving from project.json to .csproj * Created a solution file (dotnet new sln and dotnet sln add ...) capturing all of the projects to replace the equivalent global.json * Adjusted *some* of the test run batch files to account for new CLI format for invoking unit tests * Had to make some adjustments to TestServer integration tests to handling binding redirects properly as described by aspnet/Hosting#959 and microsoft/vstest#428
Why did this get closed? |
This is fixed in version 15.3.0 of the Microsoft.NET.Test.Sdk package. |
I could be off here, but it looks like i'm running into this issue. I'm using the full .net framework 4.6.1 and MS Test: System.IO.FileNotFoundException: 'Could not load file or assembly 'System.Net.Http, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.' Let me know if this belongs somewhere else. |
Using latest VS 2019 and Nunit, I still had to add the GenerateBindingRedirectsOutputType to my Tests csproj file to make VS generate Tests.dll.config file to allow the tests to run correctly in Nunit runner from within VS and standalone. Is there a better solution for auto-generating binding redirects for DLLs that need to run as part of Unit testing? |
Like sergeibobyr I still have to add GenerateBindingRedirectsOutputType to my Tests csproj file manually using VS 2019 and MSTest to get the binding redirects added to the app.config file. |
Description
Binding Redirects necessary to run Unit Tests on .NET Framework are not preserved when running in
testhost
. When MSBuild compiles the test Console Exe project, it generates an app.config with a binding redirect for System.Net.Http. However, that binding redirect is not present when running insidetesthost
and thus the tests fail with a MissingMethodException because the binding was never redirected.Steps to reproduce
App
is set as the start-up project and run itdotnet test
in the folder containing theTest
projectExpected behavior
Steps 5, 7 and 9 all complete successfully without errors
Actual behavior
During step 7 (running tests from VS), there is an exception while discovering tests (this particular issue may be xunit related and may not be related to the specific problem):
During step 9, the test will fail:
Environment
OS: Windows 10 x64
VS: 2017 build 26126 d15prerel
dotnet --info:
App.config file
Below is the
app.config
file generated when compiling the App project (which works):Test Host Verbose log (
dotnet test --diag
)Related issue: aspnet/Hosting#926
/cc @Tratcher @muratg
The text was updated successfully, but these errors were encountered: