Yossi Dahan [BizTalk]


Thursday, September 27, 2007

Problem due to an overload with a generic type

Here's another interesting one -

Imagine a class that looks something like this -

public class MyClass
public static void test(string a, string b)
public static void test(int a, string b)

From an expression shape in BizTalk you can now use



and everything compiles just fine.

but add the following overload to your class -
        public static void test(string a, IDictionary c)
and now try to use the first overload from an expression shape (which worked just fine before) -


and you will get - "unknown system exception" with no file name or line number to help in sight.

I know BizTalk does not support generics, but I did not think having generics in the another method, one I'm not calling from BizTalk, would be a problem; and in fact - change the call in the expression shape to the overload that takes the int first -
and it would compile just fine.

From this I can only gather that this has something to do with how .net resolves the overload to to use - in the error case, it looks at the first parameter passed in and identifies it as a string, so both the [string,string] and the [string,IDictionary] overloads fit, which means it needs to evaluate the second parameter, and, presumably, this is where it "blows up";
By changing the first parameter passed in to be an int, the compiler does not need to look into the overload that uses IDictionary as all and so it compiles ok.

And indeed, as soon as I add one this overload to the class -

public static void test(int a, IDictionary c)
I get an "unknown system exception" when calling using int as the first parameter.

Labels: , ,


Post a Comment

<< Home