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

Remove BinaryFormatter usage from ResourceReader #39290

Closed
GrabYourPitchforks opened this issue Jul 14, 2020 · 4 comments
Closed

Remove BinaryFormatter usage from ResourceReader #39290

GrabYourPitchforks opened this issue Jul 14, 2020 · 4 comments
Labels
area-System.Resources enhancement Product code improvement that does NOT require public API changes/additions
Milestone

Comments

@GrabYourPitchforks
Copy link
Member

Ref:

private void InitializeBinaryFormatter()
{
LazyInitializer.EnsureInitialized(ref s_binaryFormatterType, () =>
Type.GetType("System.Runtime.Serialization.Formatters.Binary.BinaryFormatter, System.Runtime.Serialization.Formatters, Version=0.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a",
throwOnError: true)!);
LazyInitializer.EnsureInitialized(ref s_deserializeMethod, () =>
{
MethodInfo binaryFormatterDeserialize = s_binaryFormatterType!.GetMethod("Deserialize", new Type[] { typeof(Stream) })!;
// create an unbound delegate that can accept a BinaryFormatter instance as object
return (Func<object?, Stream, object>)typeof(ResourceReader)
.GetMethod(nameof(CreateUntypedDelegate), BindingFlags.NonPublic | BindingFlags.Static)!
.MakeGenericMethod(s_binaryFormatterType)
.Invoke(null, new object[] { binaryFormatterDeserialize })!;
});
_binaryFormatter = Activator.CreateInstance(s_binaryFormatterType!)!;
}

This issue tracks the removal and replacement of this code per the BinaryFormatter obsoletion plan.

@ghost
Copy link

ghost commented Jul 14, 2020

Tagging subscribers to this area: @tarekgh, @buyaa-n, @krwq
Notify danmosemsft if you want to be subscribed.

@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added the untriaged New issue has not been triaged by the area owner label Jul 14, 2020
@tarekgh tarekgh added enhancement Product code improvement that does NOT require public API changes/additions and removed untriaged New issue has not been triaged by the area owner labels Jul 14, 2020
@pgovind
Copy link
Contributor

pgovind commented Apr 8, 2021

Alright, so I spent some time looking at the BinaryFormatter usage here. It is very simple to hide the BinaryFormatter usage in ResourceReader.Core.cs behind an AppContextSwitch, however, I think this is premature at this point. First, some context: Our own tools (ResGen, WinForms) create resx files at the moment that may contain binary formatted data. Assuming we have a serialized resx file, there are 2 ways to deserialize at the moment: Using ResourceReader from S.P.CoreLib or using ResourceReader from S.Resources.Extensions (SRE). BF usage in SRE is tracked by #39292. So, this means that currently both these code paths are being used to deserialize their resx files. So, our options here seem to be:

  1. Follow the deprecation steps outlined by @ericstj in Remove BinaryFormatter usage from System.Resources.Extensions #39292. This would mean this issue will remain blocked until Remove BinaryFormatter usage from System.Resources.Extensions #39292 is fixed.
  2. Deprecate BF usage in S.P.CoreLib's ResourceReader alone by hiding it behind an AppContext switch. This will likely "break" anyone not using SRE currently (possibly everyone generating resx files in NET Framework and reading them in .NET Core) but these folks can always turn the AppContext switch on to preserve current behavior. If we decide to go down this road, we need to determine when we want to do the deprecation. We can do it right now for Preview 4 or we can do it in P1 of the next release.

Curious to hear more opinions here.

cc @GrabYourPitchforks @ericstj @jeffhandley @jkotas

@ghost ghost added the needs-further-triage Issue has been initially triaged, but needs deeper consideration or reconsideration label Apr 8, 2021
@jkotas
Copy link
Member

jkotas commented Apr 11, 2021

It is very simple to hide the BinaryFormatter usage in ResourceReader.Core.cs behind an AppContextSwitch

The binary formatter usage is behind System.Resources.ResourceManager.AllowCustomResourceTypes switch in this file already.

This would mean this issue will remain blocked until #39292 is fixed.

Right, the real for this issue is WinForms (#39292 (comment)). I think it should be fine to resolve this issue as as dup of #39292.

@joperezr joperezr removed the needs-further-triage Issue has been initially triaged, but needs deeper consideration or reconsideration label Apr 13, 2021
@danmoseley
Copy link
Member

dupe of #39292

@ghost ghost locked as resolved and limited conversation to collaborators Jun 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Resources enhancement Product code improvement that does NOT require public API changes/additions
Projects
No open projects
Development

No branches or pull requests

7 participants