Extension methods cannot be dynamically dispatched ...

S

Shapper

Hello,

On a class library I have the following extension:

public static Int32 Execute(this IDbConnection cnn, String sql, dynamic param = null)

I am trying to expose this extension through a method on my class:

public class Repository : IRepository {

private IDbConnection _connection;

public Repository(IDbConnection connection) {
_connection = connection;
} // Repository

public Int32 Execute(String sql, dynamic param = null) {
return _connection.Execute(sql, param);
} // Execute

} // Repository

But I keep getting the following error:

'System.Data.IDbConnection' has no applicable method named 'Execute' but appears to have an extension method by that name. Extension methods cannot bedynamically dispatched. Consider casting the dynamic arguments or calling the extension method without the extension method syntax.

I tried to change my code in a few ways but no luck ...

Any idea of how to solve this?

Thank You,
Miguel
 
A

Arne Vajhøj

On a class library I have the following extension:

public static Int32 Execute(this IDbConnection cnn, String sql, dynamic param = null)

I am trying to expose this extension through a method on my class:

public class Repository : IRepository {

private IDbConnection _connection;

public Repository(IDbConnection connection) {
_connection = connection;
} // Repository

public Int32 Execute(String sql, dynamic param = null) {
return _connection.Execute(sql, param);
} // Execute

} // Repository

But I keep getting the following error:

'System.Data.IDbConnection' has no applicable method named 'Execute' but appears to have an extension method by that name. Extension methods cannot be dynamically dispatched. Consider casting the dynamic arguments or calling the extension method without the extension method syntax.

I tried to change my code in a few ways but no luck ...

Any idea of how to solve this?

The error message has two suggestions.

But I think you should go a third route.

I am highly skeptical about you really needing dynamic, so I
would suggest you try whether object or maybe object[] / List<object>
would work just as well for you.

Arne
 
S

Shapper

On a class library I have the following extension:

public static Int32 Execute(this IDbConnection cnn, String sql, dynamic param = null)

I am trying to expose this extension through a method on my class:

public class Repository : IRepository {

private IDbConnection _connection;

public Repository(IDbConnection connection) {
_connection = connection;
} // Repository

public Int32 Execute(String sql, dynamic param = null) {
return _connection.Execute(sql, param);
} // Execute

} // Repository

But I keep getting the following error:

'System.Data.IDbConnection' has no applicable method named 'Execute' but appears to have an extension method by that name. Extension methods cannot be dynamically dispatched. Consider casting the dynamic arguments or calling the extension method without the extension method syntax.

I tried to change my code in a few ways but no luck ...

Any idea of how to solve this?

The error message has two suggestions.

But I think you should go a third route.

I am highly skeptical about you really needing dynamic, so I
would suggest you try whether object or maybe object[] / List<object>
would work just as well for you.

Arne

Yes, in fact for a 3.0 version there is object[] ...

But I was able so solve it. I just need to use something like:

SqlMapper.Execute( ... )

I forgot that ...

Thank You,
Miguel
 
A

Arne Vajhøj

On a class library I have the following extension:

public static Int32 Execute(this IDbConnection cnn, String sql, dynamic param = null)

I am trying to expose this extension through a method on my class:

public class Repository : IRepository {

private IDbConnection _connection;

public Repository(IDbConnection connection) {
_connection = connection;
} // Repository

public Int32 Execute(String sql, dynamic param = null) {
return _connection.Execute(sql, param);
} // Execute

} // Repository

But I keep getting the following error:

'System.Data.IDbConnection' has no applicable method named 'Execute' but appears to have an extension method by that name. Extension methods cannot be dynamically dispatched. Consider casting the dynamic arguments or calling the extension method without the extension method syntax.

I tried to change my code in a few ways but no luck ...

Any idea of how to solve this?

The error message has two suggestions.

But I think you should go a third route.

I am highly skeptical about you really needing dynamic, so I
would suggest you try whether object or maybe object[] / List<object>
would work just as well for you.

Yes, in fact for a 3.0 version there is object[] ...

But I was able so solve it. I just need to use something like:

SqlMapper.Execute( ... )

I forgot that ...

If SqlMapper is the class of your extension method then that is
one of the suggestions in the error message.

But even though you now have gotten it to compile, then
I still can not see any reason for using dynamic.

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top