title: Execute .NET 3.0 code from Office 2003
body: <p>I've created a DLL in C# using the .NET 3.0 framework.</p>
  
  <p>Below is the code of my DLL</p>
  
  <pre><code>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;
          }
      }
  }
  </code></pre>
  
  <p>I'm trying to get this code to run from Office 2003 VBA code. The DLL was signed using the default Visual Studio 2008 signing.</p>
  
  <p>I've managed to reference my assembly by creating a .TLB file using </p>
  
  <pre><code>regasm /tlb c:\CompanyName.Net.dll 
  </code></pre>
  
  <p>But when I want to create an instance of the object:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>I get the following error:</p>
  
  <blockquote>
    <p>ActiveX component can't create Object</p>
  </blockquote>
  
  <p>What am I doing wrong?</p>
  
  <p>The machine I'm testing with has .NET installed up to the .NET 3.5 framework.</p>