PC Review


Reply
Thread Tools Rate Thread

Extension methods cannot be dynamically dispatched ...

 
 
Shapper
Guest
Posts: n/a
 
      24th Mar 2012
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
 
Reply With Quote
 
 
 
 
Arne Vajh°j
Guest
Posts: n/a
 
      24th Mar 2012
On 3/24/2012 6:31 AM, Shapper wrote:
> 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


 
Reply With Quote
 
 
 
 
Shapper
Guest
Posts: n/a
 
      25th Mar 2012
On Saturday, March 24, 2012 5:26:55 PM UTC, Arne Vajh°j wrote:
> On 3/24/2012 6:31 AM, Shapper wrote:
> > 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
 
Reply With Quote
 
Arne Vajh°j
Guest
Posts: n/a
 
      26th Mar 2012
On 3/25/2012 10:12 AM, Shapper wrote:
> On Saturday, March 24, 2012 5:26:55 PM UTC, Arne Vajh°j wrote:
>> On 3/24/2012 6:31 AM, Shapper wrote:
>>> 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

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
proper way to pass pointers by reference from managed c++ methods to native c++ methods Scott McFadden Microsoft VC .NET 1 22nd Apr 2006 06:10 AM
Why Petshop Changed all static methods to instance methods when upgrading from version 3.0 to version 3.1? Neo Microsoft ASP .NET 1 7th Jan 2005 02:46 AM
How do I automatically code documents as printed and dispatched. =?Utf-8?B?bHV0Y2hyZA==?= Microsoft Word Document Management 2 12th Nov 2004 04:32 PM
what's better Static Methods or Instace Methods David Microsoft Dot NET Framework 12 22nd Sep 2004 05:42 PM
How to dispatched the ip until user logon W2K server. Almon Cheng Microsoft Windows 2000 Networking 2 29th Jul 2003 09:48 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:16 AM.