dotnet / dotnet/project-system

Retrieving file from new resource file format throws System.MissingMethodException: 'Constructor on type 'System.Byte[]' not found.'

Open
#9,526 15 comments 2 reactions 1 assignee Claimed by @melytc View on GitHub
Feature-Resource-Explorer Regression Triage-Approved
Dominant language
C#
Stars
1k
Forks
415
PR merge metrics
No merged PRs in 30d

Description

### 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

1. Create a .net8 console project
3. Add a Resources (.resx) file
4. Double click on the .resx file to open the new Resource Explorer
5. Click the + button to create a resource
6. Change the type to "File"
7. Click "Add existing file..." and select a file
8. Close the Resource Explorer.
9. 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.
10. Reference the resource file in code i.e. `var fileBytes = ResourceFileName.ObjectName`
11. 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_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.