project-system: Retrieving file from new resource file format throws System.MissingMethodException: 'Constructor on type 'System.Byte[]' not found.'
Description
When adding a resource file after upgrading Visual Studio to 17.11.0 and adding a file resource, the new Resource Explorer is used.
Then when trying to retrieve the resource using the ResourceFileName.ObjectName syntax, a MissingMethodException is thrown Constructor on type 'System.Byte[]' not found.
Reproduction Steps
- Create a .net8 console project
- Add a Resources (.resx) file
- Double click on the .resx file to open the new Resource Explorer
- Click the + button to create a resource
- Change the type to “File”
- Click “Add existing file…” and select a file
- Close the Resource Explorer.
- The project will now fail to build with an error
MSB3822 Non-string resources require the System.Resources.Extensions assembly at runtime, but it was not found in this project's references.Add the NuGet package “System.Resources.Extensions” Version=“8.0.0” to resolve the error. - Reference the resource file in code i.e.
var fileBytes = ResourceFileName.ObjectName - Run the program, an exception will be thrown:
System.MissingMethodException: 'Constructor on type 'System.Byte[]' not found.'
Expected behavior
When accessing the resource file it should be returned as a byte[].
Actual behavior
An exception is thrown: System.MissingMethodException: 'Constructor on type 'System.Byte[]' not found.'
Regression?
This worked before the latest resource file / explorer changes
Known Workarounds
No response
Configuration
No response
Other information
No response
About this issue
- Original URL
- State: open
- Created 2 years ago
- Reactions: 2
- Comments: 15 (7 by maintainers)
Callstack:
So it’s being treated as a Activator type resource.
Here’s the relevant code in MSBuild: https://github.com/dotnet/msbuild/blob/1a51dd82a24e26b6aac68e29414182fa56fbb573/src/Tasks/ResourceHandling/MSBuildResXReader.cs#L222-L280
MSbuild is registering as activator resource: https://github.com/dotnet/msbuild/blob/1a51dd82a24e26b6aac68e29414182fa56fbb573/src/Tasks/ResourceHandling/MSBuildResXReader.cs#L279C31-L279C49 https://github.com/dotnet/msbuild/blob/1a51dd82a24e26b6aac68e29414182fa56fbb573/src/Tasks/ResourceHandling/FileStreamResource.cs#L47
That’s wrong, it should be treating as byte[], but MSBuild is only treating this as a byte array if it has both
System.Byte[]andmscorlibhttps://github.com/dotnet/msbuild/blob/1a51dd82a24e26b6aac68e29414182fa56fbb573/src/Tasks/ResourceHandling/MSBuildResXReader.cs#L293Here’s what I see in the latest resx:
Repro: conRes.zip
So I can workaround this by adding
,mscorlibto the resx.Maybe MSBuild could broaden that check to consider this specific case of no core assembly name. @rainersigwald
Did the designer change here? @drewnoakes Here are some previous values written – all seem to include the assembly name: https://github.com/search?q=org%3Adotnet+ResxFileRef+%2F%3BSystem.Byte\[\]%2F+path%3A*.resx&type=code
Has the fix to this issue been released yet? Now it seems with the current version of VS community (17.11.5) I cannot even attach .exe files in the new resource manager. Funny thing, it works perfectly to import them using the legacy solution (and then I can actually read the file). This seems a bit embarrassing at this point… 😅
A fix for this issue has been internally implemented and is being prepared for release, where we treat text files as
System.Stringand other files, like .cs and .exe, asSystem.Byte[]. Thanks again for bringing this up! We’ll update you once it becomes available for download.Thanks for the clarification, @maot01. I can see the error now; I’ll investigate this further and keep this thread updated.
@cmierowsky, @maot01, the fix is available in Visual Studio 17.11.1.
When can we expect this fix to be in a release?