-
Notifications
You must be signed in to change notification settings - Fork 229
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
MongoDb GetCollection error: get MakeGenericMethod may only be called on a method for which MethodBase.IsGenericMethodDefinition is true. #816
Comments
The issue appears to be something like this: public abstract class MyBaseClass {
public abstract T GetCollection<T>();
// this is just a helper to get an instance of the internal class
public static MyBaseClass test() {
return new MyInternalClass();
}
}
internal sealed class MyInternalClass : MyBaseClass {
public override T GetCollection<T>() {
throw new NotImplementedException();
}
} MyBaseClass.test().GetCollection[object] which results in:
A possible workaround is to enable private bindings with the |
Thanks, you are right, the code in mongodb driver is:
Internal without public...., But how to to enable private bindings with the PrivateBinding option? Can add any paramters to the CreateEngine method? IronPython.Hosting.Python.CreateEngine() |
I modified the source code, changed the class MongoDatabaseImpl from internal to public, and recompile it. namespace MongoDB.Driver
{
public sealed class MongoDatabaseImpl : MongoDatabaseBase
} The GetCollection in above code run correctly, but in mongodb, there are many methods with default value as default(CancellationToken), i.e. long CountDocuments(FilterDefinition<TDocument> filter, CountOptions options = null, CancellationToken cancellationToken = default(CancellationToken)); but in IronPython, when we call the method: GetCollection[BsonDocument]("collection") got IronPython.Runtime.Exceptions.TypeErrorException: expected CancellationToken, got NoneType I seems that IronPython does't support default value for structs, such as default(CancellationToken) |
You can enable private binding like this: Python.CreateEngine(new Dictionary<string, object> { {"PrivateBinding", true} }); |
.NET6 and IronPython 2.7.11
call the function:
database.GetCollection raise error:
The text was updated successfully, but these errors were encountered: