Skip to content

[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

@drweb86

Description

@drweb86

Steps:

  1. 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 { }
  1. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions