Skip to content
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

Allow MSBuild to use BinaryFormatter #33227

Merged
merged 1 commit into from
Jun 14, 2023

Conversation

rainersigwald
Copy link
Member

With EnableUnsafeBinaryFormatterSerialization=false, MSBuild can crash
instead of passing along an error, dotnet/msbuild#8786. Temporarily
opt back into the old behavior while fixing this in MSBuild.

With EnableUnsafeBinaryFormatterSerialization=false, MSBuild can crash
instead of passing along an error, dotnet/msbuild#8786. Temporarily
opt back into the old behavior while fixing this in MSBuild.
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Infrastructure untriaged Request triage from a team member labels Jun 14, 2023
@rainersigwald rainersigwald marked this pull request as ready for review June 14, 2023 02:05
@rainersigwald
Copy link
Member Author

Crashes caused by the BinaryFormatter changes have been problematic for ASP.NET, so let's get an SDK out that fixes them since dotnet/msbuild#8779 has been a bit more difficult than we expected.

Copy link
Member

@JanKrivanek JanKrivanek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's ship this!

As soon as my questions are irrelevant - I have no objections

<ReplaceFileContents
InputFiles="@(ToolRuntimeConfigPath)"
DestinationFiles="@(ToolRuntimeConfigPath)"
ReplacementPatterns="$(DisabledBinaryFormatterPattern)"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm failing to find where this is being populated by the original value that we are replacing - is the key allways expected to be present?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah the process in this repo for things is pretty convoluted! The gist is that there's a redist.csproj that is basically an empty project targeted at the latest runtime, and its output config files get used as the prototype for the tool executables like MSBuild.

I don't know for sure that the setting is guaranteed to be there and explicitly set to false forever, but it is right now, which seems good enough to me since we hopefully fix the underlying reason with your MSBuild PR soon and then revert this tweak.

@@ -438,6 +438,9 @@
<PropertyGroup>
<ReplacementPattern>"version": ".*"</ReplacementPattern>
<ReplacementString>"version": "$(MicrosoftNETCoreAppRuntimePackageVersion)"</ReplacementString>

<DisabledBinaryFormatterPattern>"System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false</DisabledBinaryFormatterPattern>
<EnableBinaryFormatterString>"System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": true</EnableBinaryFormatterString>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do true and false need to be quoted?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are not in the current JSON.

Copy link
Member

@baronfel baronfel Jun 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct - true/false are literals in JSON and don't need quote-wrapping

@GrabYourPitchforks
Copy link
Member

I'm not quite sure if there's something special about the runtimeconfig.json logic here, but in theory all you need to do is put <EnableUnsafeBinaryFormatterSerialization>true</EnableUnsafeBinaryFormatterSerialization> in your .csproj and it will emit the correct runtimeconfig.json on your behalf. Is that not a viable workaround here?

@rainersigwald
Copy link
Member Author

@GrabYourPitchforks this is the moral equivalent of that. Things that ship as tools in the SDK are more convoluted because they're retargeted to the runtime that the SDK will ship with, and one side effect of that was inheriting the latest/greatest .NET 8 rules.

@GrabYourPitchforks
Copy link
Member

I should also point out that the SDK's runtimeconfig.json including an explicit false value by default is an error. See also: #32969

Hopefully that will also make life a little less painful for you once that is addressed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Infrastructure untriaged Request triage from a team member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants