Ho creato una DLL in C# utilizzando il framework .NET 3.0.Esegui codice .NET 3.0 da Office 2003
Di seguito si riporta il codice della mia 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;
}
}
}
Sto cercando di ottenere questo codice per eseguire dal codice VBA di Office 2003. La DLL è stata firmata utilizzando la firma predefinita di Visual Studio 2008.
sono riuscito a riferimento il mio assemblaggio con la creazione di un file TLB utilizzando
regasm /tlb c:\CompanyName.Net.dll
Ma quando voglio creare un'istanza dell'oggetto:
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
ottengo il seguente errore :
ActiveX component can't create Object
Cosa sto facendo male?
La macchina con cui sto eseguendo il test ha installato .NET nel framework .NET 3.5.
Questa è la guida più succinta e completa su questo problema che ho trovato dopo ore di tentativi per farlo funzionare. Grazie. –