2

I'm trying to use Dapper to call a stored procedure that has a couple Output parameters, using VB.NET (and .NET 4.0).

However, it seems I cannot use the DynamicParameters.Add method, because I'm getting the following compiler error:

'Add' is ambiguous because multiple kinds of members with this name exist in class 'Dapper.DynamicParameters'.

...when I try to write the following line:

p.Add("@NewRecordID", DbType:=DbType.Int32, direction:=ParameterDirection.Output)

A quick search tells me this sometimes happens when using a C# library that has multiple methods that differ only in name case (VB.NET being case-insensitive). Searching the Dapper source code for DynamicParameters does show the following two overloads for the Add method, but they both use the same case, and the compiler should be able to discern between the two.

public void Add(string name, object value, DbType? dbType, ParameterDirection? direction, int? size)

public void Add(string name, object value = null, DbType? dbType = null, ParameterDirection? direction = null, int? size = null, byte? precision = null, byte? scale = null)

(I've also tried adding scale:=Nothing to the call to force the second overload, to no avail.)

While I can work around this with the input parameters by passing in an anonymous object to the DynamicParameters constructor, I can't find a way around this when adding the output parameters.

I've checked the project references to ensure there aren't multiple or ambiguous assembly references.

Has anybody encountered this problem before, and found a workaround?

At the moment, the only option I can think of is to re-write the stored procedure call without using Dapper, as implied here.

8
  • I suspect the ambiguity involves the optional parameters in the Add methods, which would mean the only resolution would be to change the signature of the Dapper methods. Commented May 8, 2015 at 16:51
  • Ooh, that's nasty. Unfortunately, the twin overload above is typical of adding optional parameters in a v2 api by making the old call have all non-optional parameters. Commented May 8, 2015 at 18:45
  • Can you try p.Add("@NewRecordID", Nothing, DbType.Int32, ParameterDirection.Output, Nothing) ? Commented May 8, 2015 at 18:47
  • Tried, with the same result, even if I go so far as p.Add("@NewRecordID", Nothing, DbType.Int32, ParameterDirection.Output, Nothing, Nothing, Nothing). Commented May 8, 2015 at 19:38
  • am I allowed to shout and scream "curse you VB!!!" ? Commented May 8, 2015 at 20:16

1 Answer 1

1

From what I can gather, the following are all potential solutions:

  1. Rewrite the Stored Procedure to not use Output parameters. (The option I was able to use in this case.)
  2. Rewrite the code calling the Stored Procedure to use standard ADO.NET.
  3. Rewrite Dapper to use a different overload pattern for DynamicParameters.Add.
  4. Update the project to use .NET 4.5.
  5. Reimplement IDynamicParameter(s) or possibly subclass DynamicParameters
Sign up to request clarification or add additional context in comments.

2 Comments

5. Reimplement IDynamicParameter(s) or possibly subclass DynamicParameters?
Good idea, added to the list.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.