Search code examples
c#.netdllvb6

Using a DLL (C#, Entity Framewok, .Net 4.8) with VB6 application - Cannot Register, Cannot Debug


We have this config:

  1. mainApp [ VB6 ]
  2. DLL [ C#, .Net Framework 4.8, Entity Framework]
  3. TestApp [ C#, .Net Framework 4.8]

The DLL should be called from the mainApp application to do this:

  1. read some info from the database [EF]
  2. send the info to the api and get response code
  3. update the code to the database [EF]

I read this and this and they suggest to copy the .config file

  1. as VB6.exe.config (in my vb6 folder- to use for debugging)
  2. as mainApp.exe.config (to be used from the .exe)

PROBLEM1: I am not able to test it because I cannot reference my dll from the VB6 IDE.

I tried to add reference to my dll from VB6 but it failed. Tried to regsrv32.exe my dll and i got the error below:

The module "mydll.dll" was loaded but the entry-point DllRegisterServer was not found. Make sure that "mydll.dll" is a valid DLL OR OCX file and then try again later.'

PROBLEM2: Now that I have created correctly the DLL and have register it I am trying to Debug both the maniApp and the DLL, I have break points in the DLL but are never hit.

What should I do?


Solution

  • With the help of @GSerg pointing me to the right direction I managed to find a solution that worked for my case. My goal was to be able to use the DLL and debug both projects at the same time.

    These are the steps followed

    1. Create An Interface for properties and methods of the classes.
    2. Assign a GUID to every class - this is to help VB to "read" properly the DLL
    3. Enable the Register for COM interop check box in Project Properties>Build
    4. Enable the Make assembly COM-Visible in project properties>Application>Assembly Information...
    5. Sign the assembly with a strong name (in Visual Studio> Developer PowerShell Run sn -k "path-to-key\myKey123.snk" )
    6. Register the DLL with regasm (In CMD with administrative privileges run regasm "full-path-to-my-dll\\mydll.dll" /tlb:"full-path-to-my-tlb\\mydll.tlb")
    7. Register the DLL to GAC with gacutil (in Visual Studio> Developer PowerShell Run gacutil /i "path-to-mydll-debug-folder\mydll.dll")
    8. In Project Properties > Debug > Start Action select Start External Program and browse to the location of VB6.exe.
    9. Copy the App.config file from the TestApp (it needs to have the connection string in it) to my VB6.exe folder and renamedit as VB6.exe.config

    Every time changes are done in the C# class library project dig steps 6 & 7 again

    UPDATE: All referenced projects must be changed to x86 ( Project Properties > Build > Platform Target) and signed with a strong name (Project Properties > Signing> Sign the assembly checkbox and select or create a strong name key file)

    Resources:

    TheGeneral's Answer to Similar Problem

    Exposing .NET Components to COM

    Create a DLL by CSharp or VB.Net for VBA

    How to: Sign an assembly with a strong name

    Signing assemblies - basics

    GAC-Global Assembly Cache