Skip to content

ResXFileRef special cases - #4607

Merged
rainersigwald merged 3 commits into
dotnet:masterfrom
rainersigwald:fileref-special-cases
Aug 20, 2019
Merged

rainersigwald merged 3 commits into
dotnet:masterfrom
rainersigwald:fileref-special-cases

Conversation

@rainersigwald

@rainersigwald rainersigwald commented Aug 12, 2019 •

Copy link
Copy Markdown
Member

Description

Add special cases in build-time resource embedding for the resource types byte[] and MemoryStream. Fixes #4581.

Enable StronglyTypedResourceBuilder when running on .NET Core and ensure that projects built using the .NET Core codepath get code generated using the expected types for resources. Fixes #4588, fixes #2272.

Customer Impact

Accessing some resources would throw an exception at runtime instead of returning a resource of type byte[] or MemoryStream.

Projects affected by either problem would have to workaround by:

  1. Build using desktop MSBuild.exe, not dotnet build
  2. Explicitly disable the new .NET Core resource-handling codepath in the projects.

Regression

Regression from .NET Framework functionality; bugs in features new to crossplatform .NET Core MSBuild.

Risk

Low--impacts only the new resource codepaths.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ericstj Do I need to check both of these, or would just the desktop-framework flavor be sufficient? I wrote a resx using the Core ResXResourceWriter and it did embed

  <data name="ref" type="System.Resources.ResXFileRef, System.Windows.Forms">
    <value>whatever.txt;System.IO.MemoryStream, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e</value>
  </data>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

System.Private.CoreLib should not persist to source files. I think there would need to be some affordance for that when writing a resx, even if it were a resx that only needed to work with core.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should be using TypeForwardedFromAttribute to write out the original identity. That leads me to believe we do not need to support the core identity. Since nothing is writing core-specfic resx files yet in VS, I think we should wait and see how this shakes out. I would not bake System.Private.CoreLib into our code base unless we are told to do so by corefx.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, removed System.Private.CoreLib from here and #4638.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, we had requested this ResX designer use TypeForwardedFrom.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: Should you have variables for these strings, like you have on IsMemoryStream?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this, I'm preserving the code as it was in the original ResXReader code in the comment above. Would you prefer static strings? I'm not opposed.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not super worried about it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Realize this is preserved, but sure is hacky that this is just a couple of indexofs that would have all sorts of false matches in theory.)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, its primary purpose these days is to make everyone who looks at it sad :(

@livarcocc

Copy link
Copy Markdown
Contributor

No tests?

@rainersigwald

Copy link
Copy Markdown
Member Author

Testing the types of failures this fixes is difficult at the moment. I filed dotnet/sdk#3549 to create some end-to-end tests in a repo that already has good infrastructure to support building and running test projects.

@rainersigwald
rainersigwald force-pushed the fileref-special-cases branch from 505cf9b to 589ef2b Compare August 19, 2019 22:39
These were handled specially in the WinForms reader, to read in the byte
array and wrap a stream around it, then use the primitive-type
serialization to deal with that.
@rainersigwald
rainersigwald force-pushed the fileref-special-cases branch from 589ef2b to c3717ae Compare August 20, 2019 01:56
@rainersigwald
rainersigwald merged commit edb3be3 into dotnet:master Aug 20, 2019
@rainersigwald rainersigwald added the Approved to merge Approved by .NET Tactics for servicing or QB mode checkins label Aug 20, 2019
@rainersigwald
rainersigwald deleted the fileref-special-cases branch October 1, 2019 19:19
@ManoharRT

ManoharRT commented Jun 3, 2020 •

Copy link
Copy Markdown

@rainersigwald - I have same issue with byte[] on .NetCore3.0. Could you please help me to fix this?

System.MissingMethodException: Constructor on type 'System.Byte[]' not found. at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture) at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes) at System.Activator.CreateInstance(Type type, Object[] args) at System.Resources.Extensions.DeserializingResourceReader.DeserializeObject(Int32 typeIndex) at System.Resources.Extensions.DeserializingResourceReader._LoadObjectV2(Int32 pos, ResourceTypeCode& typeCode) at System.Resources.Extensions.DeserializingResourceReader.LoadObjectV2(Int32 pos, ResourceTypeCode& typeCode) at System.Resources.Extensions.DeserializingResourceReader.LoadObject(Int32 pos, ResourceTypeCode& typeCode) at System.Resources.Extensions.RuntimeResourceSet.GetObject(String key, Boolean ignoreCase, Boolean isString) at System.Resources.Extensions.RuntimeResourceSet.GetObject(String key, Boolean ignoreCase) at System.Resources.ResourceManager.GetObject(String name, CultureInfo culture, Boolean wrapUnmanagedMemStream) at System.Resources.ResourceManager.GetObject(String name, CultureInfo culture)

@ericstj

ericstj commented Jun 3, 2020

Copy link
Copy Markdown
Member

@ManoharRT please open a new issue with complete repro details. https://github.com/microsoft/msbuild/issues/new/choose

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

Labels

Approved to merge Approved by .NET Tactics for servicing or QB mode checkins Area: Task: GenerateResource Problems with the task itself, resgen.exe, and resx resources in general. .NET Core

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GenerateResource has incomplete handling for ResXFileRef Generating strongly typed resource files not currently supported on .NET Core MSBuild

5 participants