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

BinaryFormatter Deprecation #6215

Closed
26 of 27 tasks
Forgind opened this issue Mar 3, 2021 · 17 comments · Fixed by #6324 or #6350
Closed
26 of 27 tasks

BinaryFormatter Deprecation #6215

Forgind opened this issue Mar 3, 2021 · 17 comments · Fixed by #6324 or #6350
Assignees
Labels

Comments

@Forgind
Copy link
Member

Forgind commented Mar 3, 2021

Motivativation

Moving away from BinaryFormatter is a long running coordinated dotnet effort, all first party code should be migrated away during .NET 8 timeframe

Context

MSBuild is using BinaryFormatter in couple places as a fallback mechanism for de/serialization of more complex types (AppDomainSetup, Exceptions, ValueTypes etc.) as well as for de/serialization of custom, pluggable data (BuildEventArgs, Embedded resources)

Scope

NET 8 - need to remove or developer-condition MSBuild usages of BinaryFormatter

post NET 8 #

@Forgind Forgind self-assigned this Mar 3, 2021
@KirillOsenkov
Copy link
Member

I'm working on getting rid of BinaryTranslator.TranslateDotNet. I'm writing custom manual serialization for various args which will be more efficient.

@Forgind
Copy link
Member Author

Forgind commented Mar 16, 2021

@rokonec 👆

@rokonec
Copy link
Member

rokonec commented Mar 16, 2021

@KirillOsenkov are those new 'custom manual serialization' be still supported by ITranslator? Also, how are you planning to deal with serialization of Exceptions?

@KirillOsenkov
Copy link
Member

I’ll send a PR in the next day or two, for now I started with ProjectEvaluationStarted and ProjectEvaluationFinished, which currently go through TranslateDotNet. I haven’t looked at the other cases yet.

@Forgind
Copy link
Member Author

Forgind commented May 27, 2021

Should not have closed this because of BinaryTranslator.TranslateDotNet

@KirillOsenkov
Copy link
Member

KirillOsenkov commented May 27, 2021

I think I've at least moved all *BuildEventArgs classes off of using TranslateDotNet. So if you place a breakpoint and run a build, it shouldn't be hit for BuildEventArgs serialization. If I missed a kind, let me know. I think TelemetryEventArgs potentially, but I don't know what that's for so I might have left it out.

But yes, there could be other types other than BuildEventArgs, so I didn't look into those.

@rolfbjarne
Copy link
Member

I'm getting this when building a project with errors from the command line when using a recent version of .NET 8 (8.0.100-preview.5.23266.8):

 MSBUILD : error MSB4166: UNHANDLED EXCEPTIONS FROM PROCESS 90123:
 MSBUILD : error MSB4166: =====================
 MSBUILD : error MSB4166: 5/18/2023 4:56:48 PM
 MSBUILD : error MSB4166: System.NotSupportedException: BinaryFormatter serialization and deserialization are disabled within this application. See https://aka.ms/binaryformatter for more information.
 MSBUILD : error MSB4166:    at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph)
 MSBUILD : error MSB4166:    at Microsoft.Build.Execution.BuildResult.Microsoft.Build.BackEnd.ITranslatable.Translate(ITranslator translator)
 MSBUILD : error MSB4166:    at Microsoft.Build.BackEnd.NodeEndpointOutOfProcBase.RunReadLoop(Stream localReadPipe, Stream localWritePipe, ConcurrentQueue`1 localPacketQueue, AutoResetEvent localPacketAvailable, AutoResetEvent localTerminatePacketPump)
 MSBUILD : error MSB4166: ===================

@rainersigwald
Copy link
Member

@rolfbjarne very interesting! Can you share a repro? We didn't expect any .NET Core codepaths to hit this but we were clearly wrong.

@rolfbjarne
Copy link
Member

rolfbjarne commented May 18, 2023

<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
	<PropertyGroup>
		<TargetFramework>net8.0</TargetFramework>
	</PropertyGroup>
	<PropertyGroup Condition="''">
	</PropertyGroup>
</Project>
$ dotnet --version
8.0.100-preview.5.23266.8

$ MSBUILDNOINPROCNODE=1 dotnet build MySimpleApp.csproj
MSBuild version 17.7.0-preview-23260-01+7f4bef8b4 for .NET
/Users/rolf/work/maccore/mono-master/xamarin-macios/tests/dotnet/MySimpleApp/macOS/MySimpleApp.csproj(6,17): error MSB4113: Specified condition "''" evaluates to "" instead of a boolean.
MSBUILD : error MSB4166: Child node "2" exited prematurely. Shutting down. Diagnostic information may be found in files in "/var/folders/43/h027tm1n101cdrq2_b6n9n2m0000gn/T/MSBuildTemprolf/" and will be named MSBuild_*.failure.txt. This location can be changed by setting the MSBUILDDEBUGPATH environment variable to a different directory.
MSBUILD : error MSB4166: /var/folders/43/h027tm1n101cdrq2_b6n9n2m0000gn/T/MSBuildTemprolf/MSBuild_pid-5527_75432f69f6fa4357a1cb60532f101677.failure.txt:
MSBUILD : error MSB4166: UNHANDLED EXCEPTIONS FROM PROCESS 5527:
MSBUILD : error MSB4166: =====================
MSBUILD : error MSB4166: 5/18/2023 6:00:21 PM
MSBUILD : error MSB4166: System.NotSupportedException: BinaryFormatter serialization and deserialization are disabled within this application. See https://aka.ms/binaryformatter for more information.
MSBUILD : error MSB4166:    at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph)
MSBUILD : error MSB4166:    at Microsoft.Build.Execution.BuildResult.Microsoft.Build.BackEnd.ITranslatable.Translate(ITranslator translator)
MSBUILD : error MSB4166:    at Microsoft.Build.BackEnd.NodeEndpointOutOfProcBase.RunReadLoop(Stream localReadPipe, Stream localWritePipe, ConcurrentQueue`1 localPacketQueue, AutoResetEvent localPacketAvailable, AutoResetEvent localTerminatePacketPump)
MSBUILD : error MSB4166: ===================
MSBUILD : error MSB4166:
MSBUILD : error MSB4166:

Build FAILED.

Note that when I ran into this originally, I didn't have MSBUILDNOINPROCNODE set, so that's not necessary for the issue to trigger (although I'm not sure how to force it without the env variable)

@rainersigwald
Copy link
Member

Oh wow, that is DEFINITELY not a case I expected to fail here. Yikes. Thanks!

Note that when I ran into this originally, I didn't have MSBUILDNOINPROCNODE set, so that's not necessary for the issue to trigger (although I'm not sure how to force it without the env variable)

I bet it's "multiproc build where the error originated in one of the worker processes".

@JanKrivanek JanKrivanek self-assigned this May 19, 2023
@JanKrivanek
Copy link
Member

related: dotnet/runtime#43482

@Forgind
Copy link
Member Author

Forgind commented Jun 2, 2023

Turn on warning in GenerateResource when building from the SDK:
dotnet/sdk#32981

@rmarinho
Copy link
Member

rmarinho commented Jun 13, 2023

Hi, we (MAUI team) are getting our build failing when bumping to 8.0.100-preview.6.23310.1

Here's the PR : https://github.com/dotnet/maui/pull/15504/files

build: https://devdiv.visualstudio.com/DevDiv/_build/results?buildId=7910174&view=results

@Forgind
Copy link
Member Author

Forgind commented Jun 13, 2023

Hi, we (MAUI team) are getting our build failing when bumping to 8.0.100-preview.6.23310.1

Here's the PR : https://github.com/dotnet/maui/pull/15504/files

build: https://devdiv.visualstudio.com/DevDiv/_build/results?buildId=7910174&view=results

JanKrivanek has a PR open here that should resolve this issue when it goes in.

@BrennanConroy
Copy link
Member

What's the timeline to fix this? ~50% of our builds are now failing due to this.

@JanKrivanek
Copy link
Member

FYI: dotnet/sdk#33227 (once merged, this should provide a workaround for the meantime)

@JanKrivanek
Copy link
Member

Removing the BinFmt opt-in in sdk: dotnet/sdk#34402

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment