You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The ResxSourceGenerator handles all non-string resources in the resx files incorrectly. Visual Studio allows to add images, text files and any other type of file into the resources.
The file is correctly embedded by the compiler into the resources file. How ever the property generated by the source generator incorrectly exposes the resource in this example as System.String instead of System.Byte[]. The compilation of the project works without issue, the error is raised at runtime when accessing the generated resource.
Steps To Reproduce
Create any project with a non-string resource in the resx file that is handled by the source generator. The resource needs to be of any type but string. You find that the property is created with the return type string, no matter what. Running the application that is accessing the resource, will give you a runtime error.
Alternatively you can use the attached project, that has already been prepared correctly: SerializationTest.zip
You find that the resource has been generated as string instead of byte[].
Expected behavior
Ideally the generator handles the non-string resources fully correctly and creates properties that match the expected type or a related one. (byte[] could be replaced with Memory or something liket this).
If that is not an option the generated should at least fail at compile time, to let the developer know that this is not going to work.
Actual behavior
The resource generator creates a properly with the wrong return type that causes a runtime error.
The text was updated successfully, but these errors were encountered:
Analyzer
Microsoft.CodeAnalysis.ResxSourceGenerator
Analyzer source
NuGet Package: Microsoft.CodeAnalysis.ResxSourceGenerator
Version: 3.11.0-beta1.24629.2
Describe the bug
The ResxSourceGenerator handles all non-string resources in the resx files incorrectly. Visual Studio allows to add images, text files and any other type of file into the resources.
This is represented in the resx file like this:
The file is correctly embedded by the compiler into the resources file. How ever the property generated by the source generator incorrectly exposes the resource in this example as
System.String
instead ofSystem.Byte[]
. The compilation of the project works without issue, the error is raised at runtime when accessing the generated resource.Steps To Reproduce
Create any project with a non-string resource in the resx file that is handled by the source generator. The resource needs to be of any type but
string
. You find that the property is created with the return typestring
, no matter what. Running the application that is accessing the resource, will give you a runtime error.Alternatively you can use the attached project, that has already been prepared correctly: SerializationTest.zip
You find that the resource has been generated as
string
instead ofbyte[]
.Expected behavior
Ideally the generator handles the non-string resources fully correctly and creates properties that match the expected type or a related one. (
byte[]
could be replaced withMemory
or something liket this).If that is not an option the generated should at least fail at compile time, to let the developer know that this is not going to work.
Actual behavior
The resource generator creates a properly with the wrong return type that causes a runtime error.
The text was updated successfully, but these errors were encountered: