Bug 11824 - Enumerating dictionary in embedded Mono throws "System.InvalidOperationException: out of sync"
Summary: Enumerating dictionary in embedded Mono throws "System.InvalidOperationExcept...
Alias: None
Product: Runtime
Classification: Mono
Component: JIT ()
Version: unspecified
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2013-04-17 09:58 UTC by Dmitriy Pyalov
Modified: 2013-04-17 10:33 UTC (History)
2 users (show)

Is this bug a regression?: ---
Last known good build:

Project to reproduce the bug (18.38 KB, application/x-gzip)
2013-04-17 09:58 UTC, Dmitriy Pyalov

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Dmitriy Pyalov 2013-04-17 09:58:19 UTC
Created attachment 3822 [details]
Project to reproduce the bug

I enumerate dictionary via Mono embedded C API.
The dictionary is not modified, but when I call MoveNext on the enumerator - it throws:

Unhandled Exception:
System.InvalidOperationException: out of sync
  at System.Collections.Generic.Dictionary`2+Enumerator[System.String,System.Object].VerifyState () [0x00000] in <filename unknown>:0 
  at System.Collections.Generic.Dictionary`2+Enumerator[System.String,System.Object].MoveNext () [0x00000] in <filename unknown>:0 

This exception is only thrown when the dictionary generation differs from the enumerator stamp:

private void VerifyState ()
	if (this.dictionary == null)
		throw new ObjectDisposedException (null);
	if (this.dictionary.generation != this.stamp)
		throw new InvalidOperationException ("out of sync");

But I've checked stamp and generation - they are equal! And there is no such problem when I use old compatibility IDictionaryEnumerator.

The only difference I see is that the normal enumerator is a struct, but the old compatibility one is a class. So it's rather a some kind of JIT bug, or C API has problems calling methods on structs.

The project to reproduce the bug is attached to the issue. It's configured to build and run on default 3.0.10 installation of Mono (/Library/Frameworks/...) with Boehm GC

So, is it a bug, or am I working with the structs the wrong way?
Comment 1 Dmitriy Pyalov 2013-04-17 10:33:58 UTC
OK, i've resolved this.

The structs have to be unboxed before method calls or undefined behavior happens.

This is not an issue anymore.