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
{{ message }}
Repository navigation
[Win11] [Bug] [ConcurrentBag regression in .Net 9] System.AccessViolationException: 'Attempted to read or write protected memory. This is often an indication that other memory is corrupt.' #110355
Create new .Net 9 project and put code in Visual Studio 2022
using System.Collections.Concurrent;
var breakingBadHoleInTheBag = new ConcurrentBag<ConcurrentBagItem>();
int tries = 500000;
while (tries-- > 0)
{
breakingBadHoleInTheBag.SingleOrDefault(x => x == (object)breakingBadHoleInTheBag);
breakingBadHoleInTheBag.Add(new ConcurrentBagItem());
}
class ConcurrentBagItem { }
Execute with or without debugger
Actual result:
An unhandled exception of type 'System.AccessViolationException' occurred in System.Collections.Concurrent.dll
Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Expected result:
Works without error, as in .Net 9.
Please introduce ConcurrentBag - from .Net 8 because uinstable work in .Net 9 breaks my app
changed the title [-]System.AccessViolationException: 'Attempted to read or write protected memory. This is often an indication that other memory is corrupt.'[/-][+][Win11] [Bug] [ConcurrentBag regression in .Net 9] System.AccessViolationException: 'Attempted to read or write protected memory. This is often an indication that other memory is corrupt.'[/+]on Nov 29, 2024
It's very unlikely this is actually related to ConcurrentBag. It's more likely some code in your app is resulting in corruption that then appears as an AV in other code, in this case in CB. Without a repro or crash dump, though, we can't investigate.
using System.Collections.Concurrent;
var breakingBadHoleInTheBag = new ConcurrentBag<ConcurrentBagItem>();
int tries = 500000;
while (tries-- > 0)
{
breakingBadHoleInTheBag.SingleOrDefault(x => x == (object)breakingBadHoleInTheBag);
breakingBadHoleInTheBag.Add(new ConcurrentBagItem());
}
class ConcurrentBagItem { }
Build for .Net 9 and run => Access Violation,
Build for .Net 8 and run => No error.
Please return .Net 8 implementation since other software might expect old behavior, or new one create with postsfix ConcurrentBagV2/put into breaking changes list.
This is not about the ConcurrentBag implementation.
I suspect this may be the same as the issue fixed by #109074. If you add <CETCompat>false</CETCompat> into a PropertyGroup in your csproj, does the problem go away?
But guys, seriously, we're in the dark times, when its needed to modify csproj config to make ConcurrentBag work.
Again, this has little to do with ConcurrentBag. It is a runtime bug to do with Intel's CET security mechanism, it's already been fixed in main with #109074 and it's being fixed in 9.0 with #109548 (cc: @janvorli, @jeffschwMSFT). I mentioned the csproj property to both confirm this is the same problem and to give you a temporary workaround.
Activity
drweb86 commentedon Nov 29, 2024
If to go through stack trace - System.Linq is third one, Ion double click on it VIsual Studio 2022 crashes (!).
[-]System.AccessViolationException: 'Attempted to read or write protected memory. This is often an indication that other memory is corrupt.'[/-][+][Win11] [Bug] [ConcurrentBag regression in .Net 9] System.AccessViolationException: 'Attempted to read or write protected memory. This is often an indication that other memory is corrupt.'[/+]ViktorHofer commentedon Dec 3, 2024
@dotnet/area-system-collections
stephentoub commentedon Dec 4, 2024
It's very unlikely this is actually related to ConcurrentBag. It's more likely some code in your app is resulting in corruption that then appears as an AV in other code, in this case in CB. Without a repro or crash dump, though, we can't investigate.
drweb86 commentedon Dec 4, 2024
drweb86 commentedon Dec 5, 2024
Here's the reproduction sample
Build for .Net 9 and run => Access Violation,
Build for .Net 8 and run => No error.
Please return .Net 8 implementation since other software might expect old behavior, or new one create with postsfix ConcurrentBagV2/put into breaking changes list.
I updated first post with steps.
stephentoub commentedon Dec 6, 2024
Thanks for the repro.
This is not about the ConcurrentBag implementation.
I suspect this may be the same as the issue fixed by #109074. If you add
<CETCompat>false</CETCompat>into a PropertyGroup in your csproj, does the problem go away?drweb86 commentedon Dec 6, 2024
@stephentoub ,
Adding
worked.
But guys, seriously, we're in the dark times, when its needed to modify csproj config to make ConcurrentBag work.
stephentoub commentedon Dec 6, 2024
Again, this has little to do with ConcurrentBag. It is a runtime bug to do with Intel's CET security mechanism, it's already been fixed in main with #109074 and it's being fixed in 9.0 with #109548 (cc: @janvorli, @jeffschwMSFT). I mentioned the csproj property to both confirm this is the same problem and to give you a temporary workaround.
stephentoub commentedon Dec 6, 2024
Closing as a duplicate of #109074. Thanks for reporting.
drweb86 commentedon Dec 6, 2024
@stephentoub Thanks!