-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
When using .NET Standard facades on .NET Framework, automatic binding redirects should be enabled #1405
Comments
I believe the property is Currently it is defaulted for SDK projects: sdk/src/Tasks/Microsoft.NET.Build.Tasks/build/Microsoft.NET.Sdk.BeforeCommon.targets Lines 53 to 55 in cd25d6b
I believe for non-SDK projects it is set to "true" in the template for File>New Project. I agree that we could just make it true by default (assuming project doesn't set it to false). Should it be done here or MSBuild? @rainersigwald |
Ping @livarcocc @dsplaisted please triage. |
It seems like it would be a breaking change to set a default for all projects now. |
We are not taking any new bugs for 2.0.0, unless we have strong evidence that it really breaks a scenario and we really must take it. |
I'd say this is a very severe bug we need to fix. Scenario
Expected BehaviorThe app works. Actual BehaviorThe application crashes with
Manually setting |
The symptom is severe, but:
|
Customers couldn't use .NET Standard 1.5+ assets in .NET Framework 4.6.1. IOW, the standard was created to match what was shipped in the platform. With .NET Standard 2.0 we've retroactively made .NET Framework 4.6.1 implement .NET Standard 2.0. This makes all our facades OOB on that version on the framework, thus requiring binding redirects.
Only if you're knowledgeable in MSBuild™️. Seriously though, there no easy way to add this property and it's virtually undiscoverable. |
For discoverability, doesn't the error list have https://github.com/Microsoft/msbuild/blob/4d2d2d2d51e18ad817db1c55dfa0d19473e7d1fc/src/Tasks/Resources/Strings.resx#L1527-L1530 ? Or is it something about the facade magic that circumvents that? |
@terrajobst I'm experiencing an issue very similar to what you described: #Azure/azure-functions-vs-build-sdk#115 |
Is it with Azure Functions or with your own application? |
@terrajobst That particular issue happens with Azure Functions msbuild task (part of AF SDK and of the Functions VS project template). My understanding is that it happens when some code is loaded dynamically. For example, functions build task loads all types in an assembly with functions, and if any of the types expose dependencies which in turn have dependency on 'System.Runtime, Version=4.1.0.0' (like Microsoft.Azure.DocumentDB.Core), it crashes or fails to load the type, depending on how its done. This compile-time error can be worked around by making such classes internal. However, when function runtime calls the function, the error happens at run time, which is even worse. |
Yep, in dyanamic scenarios binding redirects don't work at all, unfortunately. The good news is that at least for .NET Standard 2.0, the problem will eventually disappear (mostly in 4.7.1) as the need for binding redirects is no longer there. However, we're also thinking about how we can solve these issues without requiring binding redirects. We'll see. |
Dropping a note here on the negative impact of this bug in the Azure functions scenario. Like this issues mentions: Azure/azure-functions-vs-build-sdk#139 Even a seemingly insignificant code change in your azure functions project can introduce very hard to diagnose build errors. In my case it was only a refactor of the below code to a static function which caused the failure to be introduced. It was very surprising as 0 new unique lines of code were added to the project but due to some things outside my control with how the binding is done in azure function generator the error was introduced. Two days later I was finally able to narrow it to the simple refactor. This is a serious bug impacting current azure function developers using VS which really needs to be fixed. Code: inline in an existing method wasn't causing the issue but refactored in to a shared method caused the issue. public static void AuthenticateADLSFileSystemClient(out DataLakeStoreFileSystemManagementClient adlsFileSystemClient, out string adlsAccountName, TraceWriter log) |
Hello, I have a .NET 4.6.1 "Azure Functions" project and I experience the issue Azure/azure-functions-vs-build-sdk#139 because I have a class that inherits JsonMediaTypeFormatter.
Do you have a suggestion to fix this? |
We've designed and accepted the necessary feature work. @rainersigwald will be working on this. |
Is there a bug tracking this on the MSBuild side, where the fix will happen? Should we move this one there? |
There's dotnet/msbuild#2481 (not sure if this is the one the feature document is meant to solve, but linked to from some places already) |
Closing this issue in favor of the MSBuild one. If I got this wrong, just comment and I can re-activate. |
…0200418.1 (dotnet#1405) - Microsoft.AspNetCore.Analyzers: 5.0.0-preview.4.20216.10 -> 5.0.0-preview.4.20218.1 - Microsoft.AspNetCore.Mvc.Api.Analyzers: 5.0.0-preview.4.20216.10 -> 5.0.0-preview.4.20218.1 - Microsoft.AspNetCore.Components.Analyzers: 5.0.0-preview.4.20216.10 -> 5.0.0-preview.4.20218.1 - Microsoft.AspNetCore.Mvc.Analyzers: 5.0.0-preview.4.20216.10 -> 5.0.0-preview.4.20218.1 Co-authored-by: dotnet-maestro[bot] <dotnet-maestro[bot]@users.noreply.github.com>
We now automatically inject facades into the .NET Framework compilation when consuming a library that targets .NET Standard.
We need to make sure that when these facades are injected, that we forcefully enable automatic generation of binding redirects. That's necessary because we deploy files that might have higher versions then what the .NET Standard binary is referencing. These files aren't necessarily part of the runtime unification table or are explicitly opted-out by a minor version bump.
In non-SDK-style projects, the property
<AutoGenerateBindingRedirects>
is defaulted tofalse
and relies on project templates to be set. The latter is only the case when the project got created targeting .NET Framework 4.5.1 or later. When an existing project is upgraded to 4.5.1 or later, the property is stillfalse
. I suggest we set it totrue
when we detect .NET Standard facades are needed.My understanding is that in SDK-style projects the
<AutoGenerateBindingRedirects>
is alreadytrue
if the project is targeting .NET Framework and producing an application.The text was updated successfully, but these errors were encountered: