我使用 .NET 3.0 框架用 C# 创建了一个 DLL。
下面是我的 DLL 代码:
namespace CompanyName.Net
{
[Guid("F7075E8D-A6BD-4590-A3B5-7728C94E372F")]
[ClassInterface(ClassInterfaceType.AutoDual)]
[ProgId("CompanyName.Net.Webrequest")]
public class WebRequest
{
public string Result { get; private set; }
public string Url { get; set; }
public string StatusDescription { get; private set; }
public HttpStatusCode StatusCode { get; private set; }
public WebRequest()
{
//explicit constructor
}
public string GetResponse(string url)
{
System.Net.WebRequest webreq = System.Net.WebRequest.Create(url);
HttpWebResponse response = (HttpWebResponse) webreq.GetResponse();
// Store the status.
StatusDescription = response.StatusDescription;
StatusCode = response.StatusCode;
// Get the stream containing content returned by the server.
Stream dataStream = response.GetResponseStream();
// Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader(dataStream);
// Read the content.
Result = reader.ReadToEnd();
// Cleanup the streams and the response.
reader.Close();
dataStream.Close();
response.Close();
//return the response
return Result;
}
}
}
我正在尝试从Office 2003 VBA代码中运行此代码。该DLL使用默认的Visual Studio 2008签名进行签名。
我已经成功通过创建.TLB文件来引用我的程序集
regasm /tlb c:\CompanyName.Net.dll
但是当我想要创建对象的实例时:
Private Sub Command0_Click()
Dim o As Object
Set o = CreateObject("CompanyName.Net.WebRequest")
Dim s As String
s = o.GetResponse("http://www.google.be")
MsgBox s
End Sub
我遇到了以下错误:
ActiveX组件无法创建对象
我做错了什么?
我测试的机器上已安装.NET框架,版本为.NET 3.5。