.NET DLL for VBS

StuartProgramming Blog

I had a strange requirement to make a .NET client available for VBScripting through COM. This isn't generally a problem, except the functionality of the .NET application was to connect with a WCF Service Reference. The generated Reference.cs file that contains the WCF Service Reference code is all Public; therefore, making the entire project COM Visible has some problems. Specifically, regasm.exe throws an error because of the generic types used in Reference.cs.

Type library exporter warning processing 'MyProj1ComObject.ServiceReference1.IMyProj1.GetStatusAsync(#0), MyProj1ComObject'. Warning: Type library exporter encountered a generic type instance in a signature. Generic code may not be exported to COM.
Type library exporter warning processing 'MyProj1ComObject.ServiceReference1.IMyProj1.GetStatusAndDetailsAsync(#0), MyProj1ComObject'. Warning: Type library exporter encountered a generic type instance in a signature. Generic code may not be exported to COM.
Type library exporter warning processing 'MyProj1ComObject.ServiceReference1.IMyProj1.PostNewJobAsync(#0), MyProj1ComObject'. Warning: Type library exporter encountered a generic type instance in a signature. Generic code may not be exported to COM.
Type library exporter warning processing 'MyProj1ComObject.ServiceReference1.IMyProj1.UpdateStatusAsync(#0), MyProj1ComObject'. Warning: Type library exporter encountered a generic type instance in a signature. Generic code may not be exported to COM.
Type library exporter warning processing 'MyProj1ComObject.ServiceReference1.IMyProj1.PostAttachmentToJobAsync(#0), MyProj1ComObject'. Warning: Type library exporter encountered a generic type instance in a signature. Generic code may not be exported to COM.
Assembly exported to 'C:\Users\****\MyProj1ComObject\bin\Release\MyProj1ComObject.tlb', and the type library was registered successfully

My process:

  1. Go through the generated reference.cs file for the service reference to find any class or function that appears in the regasm. Add the [ComVisible(false)] tag to these
  2. 'c:\windows\Microsoft.NET\Framework\v4.0.30319\RegAsm.exe MyProj1ComObject.dll /tlb
  3. '”c:\Program Files (x86)\Microsoft SDKs\Windows\v8.0a\bin\NETFX 4.0 Tools\gacutil.exe” /f /i MyProj1ComObject.dll
  4. Make sure you call the 64-bit wscript on a 64-bit machine. The contents of testing.vbs are below. 'c:\windows\syswow64\wscript.exe testing.vbs
Dim testingObject
Set testingObject = CreateObject("MyProj1ComObject.MyProj1Com")
testingObject.setUser("myusername")
testingObject.setPass("mypass")
MsgBox testingObject.postReturnFile("testingFile", "12345", 999)

Tags: 

Stuart.NET DLL for VBS