【发布时间】:2014-09-12 15:45:25
【问题描述】:
我正在开发一个交给我的经典 ASP 应用程序,我必须使用它。我想使用仅在 .NET 框架中的组件。我需要制作一个 C# 类库,它可以执行可以通过经典 ASP 上的 COM 调用的 .NET 代码。
我想将一个经典的 ASP 字典传递给 C# com 组件。最好的情况是通过字典。我在我的 C# 代码中添加了来自 com 的 Scripting.Dictionary 作为参考。
这是我当前的代码。
经典 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#:
public byte[] GetReport(int Report_Type_Requested, Scripting.DictionaryClass Report_Params)
{
try
{
return report.GetReport(Report_Params);
}
catch (Exception e)
{
throw e;
}
}
但是当我运行它时,我得到:
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,如下所示:
public byte[] GetReport(int Report_Type_Requested, IDictionary Report_Params)
{
try
{
return report.GetReport(Report_Params);
}
catch (Exception e)
{
throw e;
}
}
编辑 2:
我尝试使用 Scripting.IDictionary 来更好地指定它。我得到了同样的错误“无效的过程调用或参数”:
public byte[] GetReport(int Report_Type_Requested, Scripting.IDictionary Report_Params)
{
try
{
return report.GetReport(Report_Params);
}
catch (Exception e)
{
throw e;
}
}
编辑 3:
我添加了获取报告的代码。我不断将 GetReport 参数更改为我正在测试的任何内容。
public byte[] GetReport(Scripting.IDictionary Report_Params)
{
return null;
}
【问题讨论】:
-
尝试
Scripting.IDictionary而不是Scripting.DictionaryClass。 -
函数参数的IDictionary?然后我是否将它转换为函数内部的字典类,或者我可以像那样正常使用它吗?
-
只要你从脚本中传递它,就可以尝试像那样使用它,而不是强制转换。
-
我似乎也没有在这方面取得任何成功。我在上面的编辑中发布了代码。
-
不仅仅是
IDictionary(可能是this),还有Scripting.IDictionary。
标签: c# dll dictionary asp-classic com