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

[BinFmt] Identify usages of GenerateResource task #8827

Closed
Tracked by #6215
JanKrivanek opened this issue Jun 1, 2023 · 5 comments
Closed
Tracked by #6215

[BinFmt] Identify usages of GenerateResource task #8827

JanKrivanek opened this issue Jun 1, 2023 · 5 comments

Comments

@JanKrivanek
Copy link
Member

JanKrivanek commented Jun 1, 2023

Background

#6215
This subitem is focused on GenerateResource task
Here we dont need to know exact usages - just gain some idea about magnitude and patterns of usage
GenerateResouce Task uses BinaryFormatter for application/x-microsoft.net.object.binary.base64 mime type - so we are mainly interested in that one

Expected output

  • List of internal repos that use GenerateResource task + some sample usages
  • Examples of external GH repos (with recent activity) using GenerateResource task
  • Count of external repos using GenerateResource task, idealy categorized by recent usage and # of commits, or some relativelu useful metric giving idea of how much/few it's being used (especialy for Core).

TODO

what about resgen.exe?

@JanKrivanek
Copy link
Member Author

FYI @Forgind - the search might be simplified via simply adding an implicit GenerateResourceWarnOnBinaryFormatterUse parameter with true value (somewhere into common targets? the FullFW version of MSBuild should be likely skipped)

@KalleOlaviNiemitalo
Copy link

KalleOlaviNiemitalo commented Jun 2, 2023

I'm using the GenerateResource task in a few projects, via the StronglyTypedClassName etc. metadata on EmbeddedResource items. These EmbeddedResource items are defined in shared projects (*.shproj, *.projitems), and C# source is generated in each consuming project. I don't remember exactly why I did it this way -- perhaps there was some problem with Visual Studio not updating *.projitems correctly if the C# file was generated at design time.

In these *.resx files, all resources are strings only, but some of them read files at build time via System.Resources.ResXFileRef.

@rainersigwald
Copy link
Member

To a first approximation, the set of "repos that use GenerateResource" is the same as the set of "repos that use .NET". Search for .resx files or EmbeddedResource items to find most uses.

Few call GenerateResource directly; generally it's used through common.targets

<Target
Name="CoreResGen"
DependsOnTargets="$(CoreResGenDependsOn)">

@JanKrivanek
Copy link
Member Author

Based on offlien discussion with @rainersigwald - GenerateResource task targetting NET actually currently doesn't use BinaryFormatter at all (it just transfers the base64 encoded data, with de-/en-coding just the binary format, but performs no de/serialization of the actual data in the blobs - this happens only during generating .resx files and then during runtime when reading embedded resources - both outside of the scope of msbuild)

@ladipro
Copy link
Member

ladipro commented Jun 6, 2023

Confirming the findings above. The one direct use of BinaryFormatter is basically an optimization to see if input resources should be read in another AppDomain. Then the task indirectly uses BinaryFormatter when it deserializes input resources and re-serializes them to its output. All of this is ifdefed out in .NET (Core) MSBuild so we're safe for now.

The resource story end-to-end is out of scope, the task is just a conversion tool.

@ladipro ladipro closed this as completed Jun 6, 2023
JaynieBai pushed a commit that referenced this issue Jun 12, 2023
Related to #8827

Context
Some of the comments mentioning BinaryFormatter are misleading. Most of the classes don't need to be serializable. The only exception is PortableLibraryFile which is serialized cross-domain on .NET Framework.

Changes Made
Removed [Serializable] and the comment about BinaryFormatter-based calls from several classes. Left it on PortableLibraryFile, ifdef'ed to .NET Framework builds only.

Testing
Experimental insertion confirmed that PortableLibraryFile is indeed marshaled cross-domain in some scenarios. Confirmed that it is the only such type by code inspection.
@AR-May AR-May added the triaged label Feb 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants