0

I have a .Net 4.5 DLL that is exposed to COM. I normally register it with regasm dllname /tlb /codebase with administrative privileges and everything runs fine.

But then I do some changes in the code; it does not involve changing the names of the methods, changing parameters, or adding/deleting new methods, just changing the logic inside. When I build the DLL and replace it, then the programs that use DLL can invoke the methods until I register the DLL again.

It is as if with every build something is changed in the DLL and the methods are not recognized anymore. Needless to say, the class exposed is assigned its proper GUID and the assembly also has its proper GUID and neither changes between builds.

Any clue of what is going on?

3 Answers3

0

For COM exposed dot net dll .tlb file is used identify the type and functions. After recompiling the dll changes but the .tlb file was for old version of dll. Hence it does not work. Each time the dll is built the .tlb file needs to be recreated.

SRK_124
  • 70
  • 4
  • What I understand from what you are saying is that if I replace the dll and the tlb file (both), then there is no need to register the dll again? Is that correct? – hushed user May 12 '20 at 14:52
  • In my experience it does not work always. Please have a look into below link. https://stackoverflow.com/questions/16661056/does-a-tlb-file-have-an-association-with-architecture – SRK_124 May 12 '20 at 15:39
0

Are you project build configuration checked as 'Register for COM Interop'?

Project COM Interop Configuration

/// <summary>
/// Summary description for CustomESRIBaseTool.
/// </summary>
[Guid("8d6dc751-0e58-46a6-8233-807b3d75a9fa")]
[ClassInterface(ClassInterfaceType.None)]
[ProgId("BaseTools.CustomESRIBaseTool")]
public class CustomESRIBaseTool : BaseTool
{
    #region COM Registration Function(s)

    [ComRegisterFunction()]
    [ComVisible(false)]
    static void RegisterFunction(Type registerType)
    {
        //
        // TODO: Add any COM registration code here
        //
    }

    [ComUnregisterFunction()]
    [ComVisible(false)]
    static void UnregisterFunction(Type registerType)
    {
        //
        // TODO: Add any COM unregistration code here
        //
    }

    #endregion
}
  • It is not checked because that only registers the dll in my development machine, which is equivalent to me doing the regasm registry manually. It would mean that every time Visual Studio builds the DLL it registers it in my development machine, which is exactly what I do not want, because the DLL is already registered, and I just want to replace without the need to register again. – hushed user May 12 '20 at 15:43
  • I'm used to developing extensions using and creating new COM Objects, the projects that i create new COM Objects are always checked as COM Interop, this option make the .net generate the .tlb file. – Gustavo Oliveira May 12 '20 at 15:50
  • That is correct, but as I mentioned, I can register the dll myself manually and generate the tlb file. What I do not want is to do that for every build of the dll, since I'm not changing the interface or signature of the class or methods exposed, I'm just changing some internal logic. – hushed user May 12 '20 at 16:56
  • I edited the answer adding an example from my class with methods of COM RegisterFunction, do you have have something similar in your code? – Gustavo Oliveira May 12 '20 at 17:41
  • No, I do not have something similar, because the registration / unregistration is handled manually via using regasm.exe (regasm /tlb /codebase). The DLL does expose the methods to be used with: [ComVisible(true)] [ClassInterface(ClassInterfaceType.AutoDual)] [Guid("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX")] – hushed user May 12 '20 at 19:36
0

Thanks for all the answers, but they really did not attack the question why I needed to register the dlls every time. Finally what I decided to do is to use RegFree COM, creating a manifest file, so now I do not need to register any dll at all.