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

Force EnableUnsafeBinaryFormatterSerialization using SetSwitch - BinaryFormatter Issue #1349

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from

Conversation

ricaun
Copy link

@ricaun ricaun commented Mar 14, 2024

Hello everyone,

This PR forces to EnableUnsafeBinaryFormatterSerialization in runtime instead of adding the configuration in the csproj.

This is done by using the code below before using the BinaryFormatter. (Reference: pythonnet/pythonnet#2282)

AppContext.SetSwitch("System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization", true);

I add a simple test in the Nuke.Tooling.Tests and changes to NET 8.0 to make sure the BinaryFormatter gonna work without any EnableUnsafeBinaryFormatterSerialization in the csproj.

This gonna make sure the BinaryFormatter gonna works regardless if has or hasn't the configuration in the csproj.

And just to remind that theBinaryFormatter gonna be removed in the next .NET Core (.NET 9.0 - dotnet/announcements#293)


I confirm that the pull-request:

  • Follows the contribution guidelines
  • Is based on my own work
  • Is in compliance with my employer

@matkoch
Copy link
Member

matkoch commented Mar 16, 2024

What exactly is the benefit compared to the auto-loaded .props file?

@ricaun
Copy link
Author

ricaun commented Mar 16, 2024

The .props is goes only to the main csproj that referencing the Nuke.Commum.

This mean if I create a package with the dependencies Nuke.Commum or Nuke.Tooling, the .props does not progate to the main csproj that use the package.

Here is my package the uses that. https://www.nuget.org/packages/ricaun.Nuke#dependencies-body-tab

Now I could add the .props in my ricaun.Nuke package, or try to fix in the Nuke.Tooling to force enable the switch on runtime fixing the issue with net8.0.

The benefits would be using the Nuke.Tooling without any extra confuguratuon in the csproj or .props.

@ITaluone
Copy link
Contributor

This looks like the proper solution (especially for projects which using/extending Nuke.*)

@matkoch matkoch force-pushed the develop branch 4 times, most recently from 0719711 to 6fe1e3b Compare March 20, 2024 01:24
@ricaun
Copy link
Author

ricaun commented Mar 28, 2024

At the moment I gonna use this in my package.

By default when the DLL is load the module switch the EnableUnsafeBinaryFormatterSerialization to true.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants