Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

[release/3.1] Handle binary formatted payloads with ResX mangled generic type names #42209

Merged

Conversation

ericstj
Copy link
Member

@ericstj ericstj commented Oct 29, 2019

Release/3.1 port of #42102.

Description

When a resource contains a serialized type with generic parameters the resource cannot be deserialized on .NETCore. This is caused by a bug in .NETFramework's ResXReader/Writer that we can't fix (nor would that be feasible since we want to deal with old/bad resx files). To handle this we will detect these malformed type names and correct them in with a custom SerializationBinder at runtime.

Customer Impact

Customer cannot deserialize resource. This may prevent the use of some 3rd party controls, or block porting Windows Forms applications from .NETFramework to .NETCore.

Regression?

.NET Framework: Yes. Previous version of .NETCore: No

Risk

Low: This PR could impact performance, but we've minimized this by only using the custom binder to load types when we detect that a type name is bad. We've profiled the type-name checking step to ensure that it is minimal.

…dotnet#42102)

* Handle binary formatted payloads with ResX mangled generic type names

ResXSerializationBinder on desktop corrupted type names for generic parameters
in the binary formatted payload.  It would also undo this in the reader,
but we don't benefit from that in .NETCore since we don't deserialize
during build: we just copy the preserialized payload into the resources.

To handle this, we use a serialization binder to un-mangle the type names
in a way similar to ResXSerializationBinder.  We do it slightly differently
so that we only do it when needed, since relying on the binder to resolve
the type bypasses the type cache in BinaryFormatter.

* Respond to feedback.

release/3.1 - regenerate TestData.resources
@ericstj ericstj added the Servicing-consider Issue for next servicing release review label Oct 30, 2019
@ericstj ericstj added this to the 3.1 milestone Oct 30, 2019
@danmoseley danmoseley added Servicing-approved Approved for servicing release and removed Servicing-consider Issue for next servicing release review labels Oct 30, 2019
@ericstj ericstj merged commit 11b1ec3 into dotnet:release/3.1 Oct 30, 2019
@owlyowl
Copy link

owlyowl commented Dec 4, 2019

Hi team thanks for releasing 3.1 having not specified a global.json file my 3.0.100 project got rolled forward to 3.1.100

I've now got my resource manager call failing with:
"Could not find the resource "PregnancyStudy.Web.Resources.SharedResource.resources" among the resources "" embedded in the assembly "PregnancyStudy.Web", nor among the resources in any satellite assemblies for the specified culture. Perhaps the resources were embedded with an incorrect name."

image

The .resources.dll files still show up in the directories on disk etc I was wondering if there was something in the path that doesn't agree with 3.1.100?
image

This is the offending code in the call to ExtractResources:

                var resourceManager = new ResourceManager("PregnancyStudy.Web.Resources.SharedResource", this.GetType().Assembly);
                
                // Insert all resources, to then be overwritten
                if (cultureInfo.TwoLetterISOLanguageName != "en")
                {
                    ExtractResources(translations, resourceManager.GetResourceSet(CultureInfo.GetCultureInfo("en-US"), true, true));
                }

I was hoping you could shed some light on any breaking changes I couldn't seem to find anything in the release notes.

@ericstj
Copy link
Member Author

ericstj commented Dec 4, 2019

That error looks like your neutral assembly is missing embedded resources. This could be an issue with MSBuild or SDK. It shouldn't be related to this PR, since this PR is impacting the formatting of the content inside the resources not the embedding of the resources itself. Let me see if I can find a candidate change that would have caused the error you're seeing.

@ericstj
Copy link
Member Author

ericstj commented Dec 4, 2019

@owlyowl it could be dotnet/msbuild#4597 or dotnet/msbuild#4740. Can you open a new issue in https://github.com/microsoft/msbuild and share either a repro project or more information about the DLLs you've built (eg: open them up in ILSpy or ILDasm and examine the embedded resources and their names).

@owlyowl
Copy link

owlyowl commented Dec 5, 2019

@owlyowl it could be microsoft/msbuild#4597 or microsoft/msbuild#4740. Can you open a new issue in https://github.com/microsoft/msbuild and share either a repro project or more information about the DLLs you've built (eg: open them up in ILSpy or ILDasm and examine the embedded resources and their names).

Hi Eric just wondering your best contact email for sharing the repo with you?
Please ignore the disasterous nature of the react front-end it has been a quick and dirty form filling app for a family friend

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Resources Servicing-approved Approved for servicing release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants