Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/299.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将经典的ASP脚本.Dictionary传递给C#COM类库?_C#_Dll_Dictionary_Asp Classic_Com - Fatal编程技术网

如何将经典的ASP脚本.Dictionary传递给C#COM类库?

如何将经典的ASP脚本.Dictionary传递给C#COM类库?,c#,dll,dictionary,asp-classic,com,C#,Dll,Dictionary,Asp Classic,Com,我正在开发一个交给我的经典ASP应用程序,我必须使用它。我想使用一个只在.NET framework中的组件。我需要制作一个C#类库,该类库可以执行.NET代码,这些代码可以通过经典ASP上的COM进行调用 我想将一个经典的ASP字典传入C#com组件。最好的办法是通过一本字典。我从com中添加了Scripting.Dictionary作为我的C#代码中的参考 这是我目前的代码 经典ASP: Set test = Server.CreateObject("Reporting") 'This is

我正在开发一个交给我的经典ASP应用程序,我必须使用它。我想使用一个只在.NET framework中的组件。我需要制作一个C#类库,该类库可以执行.NET代码,这些代码可以通过经典ASP上的COM进行调用

我想将一个经典的ASP字典传入C#com组件。最好的办法是通过一本字典。我从com中添加了Scripting.Dictionary作为我的C#代码中的参考

这是我目前的代码

经典ASP:

Set test = Server.CreateObject("Reporting") 'This is my custom Object
Set dic = Server.CreateObject("Scripting.Dictionary")
dic.Add "Test", 1
test.GetReport 1, dic
C#:

但当我运行这个时,我得到:

Message = "Unable to cast COM object of type 'System.__ComObject' to class type 'Scripting.DictionaryClass'. COM components that enter the CLR and do not support IProvideClassInfo or that do not have any interop assembly registered will be wrapped in the __ComObject ...
我也尝试过这个,但似乎不起作用:

public byte[] GetReport(int Report_Type_Requested, Dictionary Report_Params)
            {
                try
                {
                    return report.GetReport(Report_Params);
                }
                catch (Exception e)
                {               
                    throw e;
                }                       
            }
我原以为这首歌可能管用,但它告诉我你不能投:

public byte[] GetReport(int Report_Type_Requested, object Report_Params)
                {
                    try
                    {
                        return report.GetReport((Scripting.DictionaryClass)Report_Params);
                    }
                    catch (Exception e)
                    {               
                        throw e;
                    }                       
                }
我怎样才能完成我想做的事情

多谢各位

编辑:

我尝试使用IDictionary,如下所示,以获得“无效的过程调用或参数”:

编辑2:

我尝试使用Scripting.IDictionary来更好地指定它。我收到了相同的错误“无效的过程调用或参数”:

编辑3:

我添加了Get报告的代码。我一直将GetReport参数更改为我正在测试的任何参数

public byte[] GetReport(Scripting.IDictionary Report_Params)
        {
           return null;
        }
以下操作应该有效(当然,您需要引用“Microsoft脚本运行时”COM对象):


我用以下方法修复了它:

似乎当对象从经典ASP传递到COM对象时,它必须作为对象传递,因此最终定义为:

public byte[] GetReport(int Report_Type_Requested, object Report_Params)
为了将该对象强制转换为dictionary对象,我通过谷歌搜索找到了Marshal类:

制作我需要的线路:

Scripting.DictionaryClass Report_Dictionary = (Scripting.DictionaryClass)Marshal.CreateWrapperOfType(Report_Params, typeof(Scripting.DictionaryClass));
然后我就可以在代码中使用字典了


我还能够使用此技术在COM上引入ADODB.Recordset。

尝试
Scripting.IDictionary
而不是
Scripting.DictionaryClass
。那么函数参数的IDictionary呢?然后我是将其强制转换到函数内部的dictionaryclass中,还是可以像那样正常使用它?只要您从脚本中传递它,就可以尝试这样使用它,而不强制转换。我似乎在这方面也没有取得任何成功。我在上面的编辑中发布了代码。不仅仅是
IDictionary
(可能是),还有
Scripting.IDictionary
。这样做给了我无法将“System.\u ComObject”类型的COM对象强制转换为“Scripting.DictionaryClass”类型的类。进入CLR且不支持IProvideClassInfo或未注册任何互操作程序集的COM组件将被包装在_ComObject中。。。“错误抱歉,我复制并粘贴了我原始问题中的错误,但我仍然有相同的错误,只是使用Scripting.Dictionary。它对我很好。你应该共享一个复制项目。
public byte[] GetReport(Scripting.IDictionary Report_Params)
        {
           return null;
        }
    public byte[] GetReport(int Report_Type_Requested, object Report_Params)
    {
        Scripting.Dictionary dic = (Scripting.Dictionary)Report_Params;
        foreach (string key in dic)
        {
            object value = dic.get_Item(key);
        }
        ...
    }
public byte[] GetReport(int Report_Type_Requested, object Report_Params)
Scripting.DictionaryClass Report_Dictionary = (Scripting.DictionaryClass)Marshal.CreateWrapperOfType(Report_Params, typeof(Scripting.DictionaryClass));