Search code examples
.netcomcom-interopfoxprovisual-foxpro

"Parameter is incorrect" error when invoking .NET assembly via COM component


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!


Solution

  • 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.