Skip to content

AccessViolationException in ArrayDictionary #858

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

Open
KirillOsenkov opened this issue Mar 4, 2025 · 4 comments
Open

AccessViolationException in ArrayDictionary #858

KirillOsenkov opened this issue Mar 4, 2025 · 4 comments

Comments

@KirillOsenkov
Copy link
Owner

Fatal error. System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
   at Microsoft.Build.Collections.ArrayDictionary`2[[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].Add(System.__Canon, System.__Canon)
   at Microsoft.Build.Logging.StructuredLogger.BuildEventArgsReader.CreateDictionary(System.Collections.Generic.List`1<System.ValueTuple`2<Int32,Int32>>)
   at Microsoft.Build.Logging.StructuredLogger.BuildEventArgsReader.ReadNameValueList()
   at Microsoft.Build.Logging.StructuredLogger.BuildEventArgsReader.PreprocessRecordsTillNextEvent(System.Func`2<Microsoft.Build.Logging.StructuredLogger.BinaryLogRecordKind,Boolean>)
   at Microsoft.Build.Logging.StructuredLogger.BuildEventArgsReader.Read()
   at Microsoft.Build.Logging.StructuredLogger.BinLogReader.Replay(System.IO.Stream, Microsoft.Build.Logging.StructuredLogger.Progress)
   at Microsoft.Build.Logging.StructuredLogger.BinaryLog.ReadBuild(System.IO.Stream, Microsoft.Build.Logging.StructuredLogger.Progress, Byte[], Microsoft.Build.Logging.StructuredLogger.ReaderSettings)
   at Microsoft.Build.Logging.StructuredLogger.BinaryLog.ReadBuild(System.String, Microsoft.Build.Logging.StructuredLogger.Progress, Microsoft.Build.Logging.StructuredLogger.ReaderSettings)
   at Microsoft.Build.Logging.StructuredLogger.BinaryLog.ReadBuild(System.String, Microsoft.Build.Logging.StructuredLogger.Progress)
   at Microsoft.Build.Logging.StructuredLogger.BinaryLog.ReadBuild(System.String)
   at BinlogTool.BinlogToolCommandBase.ReadBuild(System.String, Boolean)
   at BinlogTool.ListNuget.Run(System.String, System.String)
   at BinlogTool.Program.Main(System.String[])
@BenjaminBrienen
Copy link

We also encountered this

##[error]Fatal error. System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at Microsoft.Build.Logging.StructuredLogger.BuildEventArgsReader.CreateDictionary(System.Collections.Generic.List`1<System.ValueTuple`2<Int32,Int32>>)
at Microsoft.Build.Logging.StructuredLogger.BuildEventArgsReader.ReadNameValueList()
at Microsoft.Build.Logging.StructuredLogger.BuildEventArgsReader.Read()
at Microsoft.Build.Logging.StructuredLogger.BinLogReader.Replay(System.IO.Stream, Microsoft.Build.Logging.StructuredLogger.Progress)
at Microsoft.Build.Logging.StructuredLogger.BinaryLog.ReadBuild(System.IO.Stream, Microsoft.Build.Logging.StructuredLogger.Progress, Byte[], Microsoft.Build.Logging.StructuredLogger.ReaderSettings)
at Microsoft.Build.Logging.StructuredLogger.BinaryLog.ReadBuild(System.String, Microsoft.Build.Logging.StructuredLogger.Progress, Microsoft.Build.Logging.StructuredLogger.ReaderSettings)
at Microsoft.Build.Logging.StructuredLogger.Serialization.Read(System.String, Microsoft.Build.Logging.StructuredLogger.Progress, Microsoft.Build.Logging.StructuredLogger.ReaderSettings)
at Microsoft.Build.Logging.StructuredLogger.Serialization.Read(System.String) 

@KirillOsenkov
Copy link
Owner Author

I don't have the foggiest idea what could be causing an AV here:

var dictionary = new ArrayDictionary<string, string>(list.Count);

Looks like a .NET runtime bug honestly, since it's very rare and intermittent.

Reading a binlog is an incredibly CPU intensive operation with a ton of parallelism that is saturating your CPUs. I can imagine this bug only surfacing under extreme load.

Or am doing something stupid somewhere, but I just can't see what it could be.

@KirillOsenkov
Copy link
Owner Author

If possible, try to capture a dump of the process state when this happens.

You can use this registry setting and for every crashed process a dump will appear in C:\CrashDumps:
https://github.com/KirillOsenkov/dotfiles/blob/main/LocalDumps.reg

Don't forget to create the C:\CrashDumps directory first, of course.

Once we have a dump, we can look at what's going on using a native debugger. A managed debugger alone won't show what's going on here.

@KirillOsenkov
Copy link
Owner Author

I forgot that I opened the bug initially. Well, I suppose I'll remember to grab a dump next time I see this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants