Dwarika Nath
Dwarika Nath

Reputation: 13

How to call parameterized Function from Classic ASP Created in C#

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.

Upvotes: 1

Views: 2036

Answers (2)

Cheeso
Cheeso

Reputation: 192527

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 called GetData_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 those GetData methods, you should include both of them into IMyStorage.

Upvotes: 2

Carlos Quintanilla
Carlos Quintanilla

Reputation: 13303

Aren't you missing the first parameter when you call GetData? Microsoft VBScript runtime (0x800A01C2) Wrong number of arguments or invalid property assignment: 'GetData'

GetObj = obj.GetData(inputStr)  ' where is the string name?

maybe the following fixes the issue:

Dim sName
GetObj = obj.GetData(sName, inputStr) 
Response.Write (inputStr)

Upvotes: 0

Related Questions