如何从用 C# 创建的经典 ASP 调用参数化函数
我在 C#(框架 3.5)中创建了一个 dll,并且在该 dll 中声明了一个参数化函数。我已经成功编译了dll。之后,我创建了一个经典 ASP 页面,我想从此页面调用参数化函数,该函数会生成以下错误。
Microsoft VBScript 运行时 (0x800A01C2) 参数数量错误或属性分配无效:'GetData'
我正在附加下面的代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
namespace SayHello
{
[ComVisible(true)]
public class SayHello : IMyStorage
{
[ComVisible(true)]
public string GetData([In, MarshalAs(UnmanagedType.BStr)] string Name)
{
return "hello " + Name;
}
#region IMyStorage Members
[ComVisible(true)]
public void GetData(string name, out string helloName)
{
helloName = "hello " + name;
}
#endregion
}
[ComImport]
[Guid("73EB4AF8-BE9C-4b49-B3A4-24F4FF657B26")]
public interface IMyStorage
{
[DispId(1)]
void GetData([In, MarshalAs(UnmanagedType.BStr)] String name,
[Out, MarshalAs(UnmanagedType.BStr)] out String helloName);
}
}
现在我正在粘贴 asp 的代码,
Dim obj
Set obj = Server.CreateObject("SayHello.SayHello")
' Set obj = Server.CreateObject("SayHello.dll")
' Set obj= obj.Load("SayHello.dll")
inputStr = "myString"
GetObj = obj.GetData(inputStr)
SET Obj = NOTHING
Response.Write (GetObj)
请帮助我。
I have created a dll in C# (framework 3.5) and i have declared a parameterized function into that dll. I have compiled the dll successfully. After that I have created a Classic ASP page and I want to call the parameterized function from this page that generates the following error.
Microsoft VBScript runtime (0x800A01C2)
Wrong number of arguments or invalid property assignment: 'GetData'
I am Attaching the code below
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
namespace SayHello
{
[ComVisible(true)]
public class SayHello : IMyStorage
{
[ComVisible(true)]
public string GetData([In, MarshalAs(UnmanagedType.BStr)] string Name)
{
return "hello " + Name;
}
#region IMyStorage Members
[ComVisible(true)]
public void GetData(string name, out string helloName)
{
helloName = "hello " + name;
}
#endregion
}
[ComImport]
[Guid("73EB4AF8-BE9C-4b49-B3A4-24F4FF657B26")]
public interface IMyStorage
{
[DispId(1)]
void GetData([In, MarshalAs(UnmanagedType.BStr)] String name,
[Out, MarshalAs(UnmanagedType.BStr)] out String helloName);
}
}
Now I am pasting the code of asp
Dim obj
Set obj = Server.CreateObject("SayHello.SayHello")
' Set obj = Server.CreateObject("SayHello.dll")
' Set obj= obj.Load("SayHello.dll")
inputStr = "myString"
GetObj = obj.GetData(inputStr)
SET Obj = NOTHING
Response.Write (GetObj)
Please Help me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你们非常接近。
在我看来,您对
object.GetData()
的调用只传递了一个参数。同时,该 COMVisible 对象上有两个
GetData()
方法。但 COM 不支持重载:两个方法具有相同的名称和不同的参数集。
COM->.NET - 无法访问重载方法
如果您查看在生成的 COM 接口中,将有两种方法,一种名为
GetData
,需要一个参数,另一种名为GetData_2
,需要两个参数。我从来没有在任何地方找到过这个记录;这正是我在像你这样的情况下观察到的情况。COM 互操作 (CCW) 中的重载 - IDispatch 名称包含后缀(_2、_3 等)
如果您希望这两个易于访问,我建议您通过名称明确区分它们,而不是依赖于我所描述的行为。
另外:如果您在这两个
GetData
方法上保留COMVisible
,则应将它们都包含到IMyStorage
中。You're very close.
It looks to me like your call into
object.GetData()
is passing just one parameter.At the same time, there are two
GetData()
methods on that COMVisible object.But COM doesn't support overloading: Two methods with the same name and different sets of parameters.
COM->.NET - can't access overloaded method
If you look at the generated COM interface, there will be two methods in it, one named
GetData
that takes one parameter, and one calledGetData_2
that takes two. I never found this documented anywhere; it's just what I observed in cases like yours.Overloads in COM interop (CCW) - IDispatch names include suffix (_2, _3, etc)
If you want both of those to be accessible, I'd advise that you discriminate among them explicitly by name, rather than relying on the behavior I described.
Also: if you keep
COMVisible
on both of thoseGetData
methods, you should include both of them intoIMyStorage
.你调用GetData的时候是不是少了第一个参数?
Microsoft VBScript 运行时 (0x800A01C2) 参数数量错误或无效的属性分配:“GetData”
也许可以解决此问题:
Aren't you missing the first parameter when you call GetData?
Microsoft VBScript runtime (0x800A01C2) Wrong number of arguments or invalid property assignment: 'GetData'
maybe the following fixes the issue: