开发者

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

开发者 https://www.devze.com 2022-12-20 20:43 出处:网络
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:

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!


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号