2

Possible Duplicate:
How do I register a COM DLL written in C# with Regsvr32?

I have written a DLL in C# (.Net 4 using VS2010). I have ticked the boxes to make it COM visible and register for COM interop. I then saved the DLL and associated files to the c:\Program Files\MyCode directory.

When I run regsvr32 for the DLL (I want to use it in an Excel VBA project), I get the above error message. I am running Windows XP with SP3. I have searched on the other threads with the same problem but have not found anything useful.

Any thoughts would be appreciated.

John.

Community
  • 1
  • 1
John Grogan
  • 31
  • 1
  • 1
  • 2

1 Answers1

4

I believe what you want is regasm, not regsvr32: http://msdn.microsoft.com/en-us/library/tzat5yw6(v=vs.71).aspx

If you're building a 32-bit assembly, be sure to run this regasm:

C:\Windows\Microsoft.NET\Framework\v4.0.30319\RegAsm.exe 

If you're building a 64-bit assembly, run this regasm:

C:\Windows\Microsoft.NET\Framework64\v4.0.30319\RegAsm.exe
Pete
  • 6,585
  • 5
  • 43
  • 69
  • I have also tried regasm but that gives the following error msg - RegAsm error: RA0000: Failed to load because it is not a valid .Net assembly. Is this just a setting within Visual Studio when I build the dll? – John Grogan Jan 03 '13 at 15:27
  • What version of regasm are you running? Are you building 32-bit or 64-bit? – Pete Jan 03 '13 at 15:35
  • I am using c:\windows\Microsoft.Net\Framework\v2.0.50727\regasm and am building for 32bit (x86). – John Grogan Jan 03 '13 at 15:37
  • You can't use the .NET 2.0 regasm to register a .NET 4.0 assembly. Updated answer. – Pete Jan 03 '13 at 15:38
  • Pete - that has worked. Many thanks for your input. However, this has now thrown up another problem - when I go into Excel VBA to include the reference to my project, it tells me that it "can't add a reference to the specified file". Any thoughts? – John Grogan Jan 03 '13 at 15:43
  • To be used by VBA, it needs to be an ActiveX control. You might try reading this article: http://www.codeproject.com/Articles/24089/Create-ActiveX-in-NET-Step-by-Step – Pete Jan 03 '13 at 15:49