c# – COM Interop(如何通过经典ASP将数组传递给com)

前端之家收集整理的这篇文章主要介绍了c# – COM Interop(如何通过经典ASP将数组传递给com)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我需要为我的经典asp创建一个com对象,因为我可以创建一个.net程序集并将它与’interop’一起使用,所以我继续创建一个像这样的.net程序集: –
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Runtime.InteropServices;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Data.sqlClient;
  7. using System.Data;
  8. using System.Configuration;
  9. using System.Web;
  10.  
  11.  
  12. namespace LMS
  13. {
  14.  
  15. [ComVisible(true)]
  16. public class Calc
  17. {
  18.  
  19. public int Add(int val1,int val2,out string[] outputz)
  20. {
  21. int total = val1 + val2;
  22. outputz = new string[5];
  23. outputz[1] = "test2";
  24. outputz[2] = "test3";
  25. outputz[3] = "test4";
  26. outputz[4] = "test5";
  27. return total;
  28. }
  29.  
  30.  
  31. }
  32. }

接下来,我做了通常的,构建,运行:gacutil& RegAsm

在我的经典asp页面中我有这个: –

  1. Dim params
  2. dim objPassport3
  3. set objPassport3 = Server.CreateObject("LMS.Calc")
  4. comTest2 = objPassport3.Add(1,1,params)

我得到错误

Error Type:
Microsoft VBScript runtime (0x800A0005)
Invalid procedure call or argument: ‘Add’
/eduservice/test.asp,line 25

但是,如果我修改程序集不使用数组,它只是工作,我甚至可以将正常的字符串或int发送到程序集和从程序集到经典的asp.
我读了很多东西,但我得到了同样的错误,

有人试过这个并且成功了,请分享你的解决方

谢谢

解决方法

ASP只能处理变量的数组,而不是字符串或整数的数组.所以尝试使用对象,例如,
  1. public int Add(int val1,out object outputz)
  2. {
  3. int total = val1 + val2;
  4. outputz = new object[5]
  5. {
  6. "test1","test2","test3","test4","test5"
  7. };
  8.  
  9. return total;
  10. }

猜你在找的C#相关文章