-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ResourceManager not threadsafe when case insensitive keys are used #80790
Comments
Tagging subscribers to this area: @dotnet/area-system-resources Issue DetailsDescriptionUsing resource manager in a high load environment we see errors occurring and strings being read incorrectly. This only happens when the Error message: Stack: Reproduction StepsThis test fails intermittently but more frequently after a clean rebuild [TestFixture]
public class ResourceManagerTest
{
[Test]
public void GivenCaseInvariantResources_ThenNoErrors()
{
Parallel.For(0, 1000, (i) =>
{
var resourceMan = new System.Resources.ResourceManager("MyBaseName", typeof(MyAssembly).Assembly);
resourceMan.IgnoreCase = true;
Parallel.For(0, 1000, (i) =>
{
var key = "key_that_exists_but_not_in_same_case_as_resources";
resourceMan.GetString(key);
});
});
}
}`
### Expected behavior
The resource should be read without an error as the class is marked as thread safe.
### Actual behavior
Error message: `Corrupt .resources file. Invalid offset '503403335' into data section.`
Stack:
`
at System.Resources.ResourceReader.AllocateStringForNameIndex(Int32 index, Int32& dataOffset)
at System.Resources.RuntimeResourceSet.GetObject(String key, Boolean ignoreCase, Boolean isString)
at System.Resources.RuntimeResourceSet.GetString(String key, Boolean ignoreCase)
at System.Resources.ResourceManager.GetString(String name, CultureInfo culture)
`
After the error occurs once **resource strings are read incorrectly without and further errors** until the application is restarted
### Regression?
_No response_
### Known Workarounds
Don't use the IgnoreCase flag
### Configuration
.NET 6.0
Errors occurs on:
- Windows 10 Pro x64
- Ubuntu 18.4 x64
### Other information
_No response_
<table>
<tr>
<th align="left">Author:</th>
<td>tl-laurence</td>
</tr>
<tr>
<th align="left">Assignees:</th>
<td>-</td>
</tr>
<tr>
<th align="left">Labels:</th>
<td>
`area-System.Resources`, `untriaged`
</td>
</tr>
<tr>
<th align="left">Milestone:</th>
<td>-</td>
</tr>
</table>
</details> |
Appears to be a bug however we need to verify locally. That method is doc'd as being "thread safe" Thread Safety |
@tl-laurence is the resource file special in any way (lots of items?) or is it changed at runtime? Basically wondering how to best repro this. |
Is this different than #74052? |
This issue has been marked |
Looks quite similar thanks @tarekgh, @tl-laurence could you try with recent .NET 8 bits where #74052 fixed? |
Yes it looks like it could be the same issue as #74052. I will have a go at testing with the suggested version. @steveharter there is nothing special about the resource files. We have multiple languages configured but can reproduce with a single culture. It is the IgnoreCase flag and the use of a key that is not in the correct case that causes it from what I have found. We removed the ignorecase and looked up the keys in a concurrent dictionary instead as a workaround which has stopped the errors. |
@tl-laurence did you verify it's fixed? |
Yes this is fixed in .Net 8 |
Description
Using resource manager in a high load environment we see errors occurring and strings being read incorrectly. This only happens when the
IgnoreCase
property istrue
.Error message:
Corrupt .resources file. Invalid offset '503403335' into data section.
Stack:
at System.Resources.ResourceReader.AllocateStringForNameIndex(Int32 index, Int32& dataOffset) at System.Resources.RuntimeResourceSet.GetObject(String key, Boolean ignoreCase, Boolean isString) at System.Resources.RuntimeResourceSet.GetString(String key, Boolean ignoreCase) at System.Resources.ResourceManager.GetString(String name, CultureInfo culture)
Reproduction Steps
This test fails intermittently but more frequently after a clean rebuild
Expected behavior
The resource should be read without an error as the class is marked as thread safe.
Actual behavior
Error message:
Corrupt .resources file. Invalid offset '503403335' into data section.
Stack:
at System.Resources.ResourceReader.AllocateStringForNameIndex(Int32 index, Int32& dataOffset) at System.Resources.RuntimeResourceSet.GetObject(String key, Boolean ignoreCase, Boolean isString) at System.Resources.RuntimeResourceSet.GetString(String key, Boolean ignoreCase) at System.Resources.ResourceManager.GetString(String name, CultureInfo culture)
After the error occurs once resource strings are read incorrectly without and further errors until the application is restarted
Regression?
No response
Known Workarounds
Don't use the IgnoreCase flag
Configuration
.NET 6.0
Errors occurs on:
Other information
No response
The text was updated successfully, but these errors were encountered: