views:

83

answers:

2

Hello all!

I have a .NET assembly that lives in the GAC. It is registered correctly so that it can be invoked by COM components. This .NET assembly contains a method and an overload to the method:

public void Foo(string sValString, out string sOutString, string sOverloadString)
{
    if( sOverloadString == string.Empty )
        // do something
    else
        // do something else
}

public void Foo(string sValString, out string sOutString)
{
    Foo(sValString, out sOutString, string.Empty);
}

Now, I can use FoxPro to invoke this assembly:

o = CREATEOBJECT("FooNamespace.FooClass")   
sValString = "blah"
sOutString = "blahblah"
o.Foo(sValString, @sOutString, "") *OK!
o.Foo(sValString, @sOutString)     *Generates error

Invoking the three parameter version works ok, but the two parameter version gives the following error when invoked by the COM component:

OLE error code 0x80070057: The parameter is incorrect.

Any ideas?? Thank you!

+2  A: 

COM has no support at all for method overloads. Your second Foo() function will be renamed when Regasm.exe generates the type library. You can use the Oleview.exe tool to take a look at it if Foxpro can't tell you what name was used.

Best thing to do is to completely avoid the problem and simply give the overload another name so you don't have to guess at it.

Hans Passant
Thanks for your help! Accepted answer, +1.
Ken
+1  A: 

Why quit so fast.

using System.Runtime.InteropServices;
...
public void Foo(string sValString, out string sOutString, [Optional] string sOverloadString)

And this is not a C# 4.0 feature.

wqw
Oh, interesting. Haven't tried this, but I googled real quick and it seems like it is a C#4 feature, but there is some debate on whether it works on earlier versions. Would this work with C#2.0?
Ken