mongodb/mongo-csharp-driver — pull request #166 by ogoun (2013-08-12 14:09:15+00:00)
Title: Stopped working MongoCursor.GetEnumerator()

When you replace this code:
```C#
// v.1.7.1
public virtual IEnumerator GetEnumerator()
{
IsFrozen = true;
return new MongoCursorEnumerator(this);
}
```

on next:
```C#
// master version
public virtual IEnumerator GetEnumerator()
{
IsFrozen = true;
var readerSettings = new BsonBinaryReaderSettings
{
Encoding = Collection.Settings.ReadEncoding ?? MongoDefaults.ReadEncoding,
GuidRepresentation = Collection.Settings.GuidRepresentation
};
var writerSettings = new BsonBinaryWriterSettings
{
Encoding = Collection.Settings.WriteEncoding ?? MongoDefaults.WriteEncoding,
GuidRepresentation = Collection.Settings.GuidRepresentation
};
// the following values are overridden for commands that can't be sent to a secondary
var flags = Flags;
var readPreference = ReadPreference;
if (readPreference.ReadPreferenceMode != ReadPreferenceMode.Primary && Collection.Name == "$cmd")
{
if (Server.ProxyType == MongoServerProxyType.ReplicaSet && !CanCommandBeSentToSecondary.Delegate(Query.ToBsonDocument()))
{
// if the command can't be sent to a secondary, then we use primary here
// regardless of the user's choice.
readPreference = ReadPreference.Primary;
// remove the slaveOk bit from the flags
flags &= ~QueryFlags.SlaveOk;
}
}
var readOperation = new QueryOperation(Database.Name,Collection.Name,readerSettings,writerSettings,BatchSize,Fields,flags,Limit,Options,Query,readPreference,SerializationOptions,Serializer,Skip);
return readOperation.Execute(new MongoCursorConnectionProvider(Server, readPreference));
}
```

My code was broken!
I use next construction for access to capped collection:
```C#
private MongoCursorEnumerator> InitializeCursor()
{
var cursor = _queue
.Find(Query.GT("_id", _lastId))
.SetFlags(
QueryFlags.AwaitData |
QueryFlags.NoCursorTimeout |
QueryFlags.TailableCursor
)
.SetSortOrder(SortBy.Ascending("$natural"));
return (MongoCursorEnumerator>)cursor.GetEnumerator();
}
```

And after last update i'll begun receive the next exception:
```C#
Unable to cast object type
"d__0[MongoDBDataAccess.ServiceBusMessage`1[MongoDBCappedCollection.Foo]]" to type "MongoDB.Driver.MongoCursorEnumerator`1[MongoDBDataAccess.ServiceBusMessage`1[MongoDBCappedCollection.Foo]]".
```

What am I doing wrong? There was a problem with a driver update through nuget.