简体   繁体   English

在为 COM 互操作注册的 c# 程序集中调用简单方法时出现“类型不匹配”错误

[英]“Type mismatch” error when calling a simple method in a c# assembly registered for COM interop

I've build a classlibrary using c# and the .net framework 3.5.我使用 c# 和 .net 框架 3.5 构建了一个类库。 In my class library there is a class called Utilities with two methods.在我的 class 库中,有一个名为 Utilities 的 class 有两种方法。

public string Method1(int length)
{
}

public string Method2(int length, string aStringParameter)
{
}

Now I went and build a simple asp page calling my methods.现在我去构建一个简单的 asp 页面来调用我的方法。 Method1 work like a charm. Method1 像魅力一样工作。 Method2 causes a "Type Mismatch" error. Method2 导致“类型不匹配”错误。 What am I missing here?我在这里想念什么?

Try to put试着放

  MarshalAs(UnmanagedType.BStr)

for string type that you are passing to method2.对于您传递给方法 2 的字符串类型。

Here is a detailed explanation.这里有一个详细的解释。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM