C# COM dll - Could not create an instance of the OLE control or Automation server

Hello,

I'm developing a report for Navision 2009 SP1, where the need for extra functionality unavailable in NAV has arisen.

I have created a COM dll in C#, installed it and created an automation variable in NAV. When I try to CREATE it, I get the following error:
"Could not create an instance of the OLE control or Automation server identified by..... Check that the OLE control or Automation server is correctly installed and registered."

The DLL should be correct, this is the code (just sample code to get a working connection between NAV and DLL):
    [ComVisible(true), Guid("080a97fb-321c-4a2f-b948-dd52ce263415"), InterfaceType(ComInterfaceType.InterfaceIsDual)]
    public interface IPrinterTest
    {
        [DispId(1)]
        bool Print(string test, string bytesInStringRepresentation);
    }

    [ClassInterface(ClassInterfaceType.None), ComVisible(true), Guid("8d7b85a9-1a20-4ea0-a7d4-decf26632eee"), ProgId("Printer.PrinterTest")]
    public class PrinterTest : IPrinterTest
    {
        public PrinterTest()
        {

        }

        public bool Print(string test, string bytesInStringRepresentation)
        {
            return true;
        }
    }

The DLL is registered as a COM dll through InstallShield.

I hope you have enough information, or have been in the same situation and can help out.

Best regards
Marcus

Answers

  • DuikmeesterDuikmeester Member Posts: 308
    Does the dll come with a tlb.
  • MarcusRBMarcusRB Member Posts: 40
    Does the dll come with a tlb.

    I used regasm to generate a .tlb file and added it to the InstallShield setup.
  • DuikmeesterDuikmeester Member Posts: 308
    Did you use target framework 3.5? I have had also trouble before when targeting higher frameworks with 2009R2.
  • MarcusRBMarcusRB Member Posts: 40
    edited 2017-03-14
    Did you use target framework 3.5? I have had also trouble before when targeting higher frameworks with 2009R2.

    No, I used 4.0, I'll give 3.5 a whirl and report back :)

    EDIT: My bad, I was repairing a newer version of VS and didn't have access to the project, I am using 3.5 :/
  • MarcusRBMarcusRB Member Posts: 40
    Did you use target framework 3.5? I have had also trouble before when targeting higher frameworks with 2009R2.

    My bad, I was repairing a newer version of VS and didn't have access to the project, I am using 3.5 :/
  • DuikmeesterDuikmeester Member Posts: 308
    When run as Administrator and you build it in Visual Studio with [assembly: ComVisible(true)] and Register for COM interop in the Properties. Then it should pick up the DLL in the Build folder instead of the installer. I suspect the installer not doing the correct registrations.
  • MarcusRBMarcusRB Member Posts: 40
    When run as Administrator and you build it in Visual Studio with [assembly: ComVisible(true)] and Register for COM interop in the Properties. Then it should pick up the DLL in the Build folder instead of the installer. I suspect the installer not doing the correct registrations.

    I think you're right. I don't know how I should deploy the DLL and register it for COM interop manually on a non-developer PC (client pc) with .NET Framework Client Profile (don't know if that makes a difference either, shouldn't think so).
  • MarcusRBMarcusRB Member Posts: 40
    Anyone else got an idea?
  • wakestarwakestar Member Posts: 207
    edited 2017-03-16
    For .NET Assemblies with COM Interface I use Visual Studio 2010 Setup Project and the deployment / installation works fine for me.
    I have several .NET Assemblies which I created and I use them for oldschool nav clients (NAV5.0) using COM interfaces and the setup is always done with VS2010 setups (Windows Installer .msi)

    But:
    Your problem could be also a dependency loading issue. - Have a look at this:
    http://stackoverflow.com/questions/255669/how-to-enable-assembly-bind-failure-logging-fusion-in-net
  • MarcusRBMarcusRB Member Posts: 40
    edited 2017-03-21
    wakestar wrote: »
    For .NET Assemblies with COM Interface I use Visual Studio 2010 Setup Project and the deployment / installation works fine for me.
    I have several .NET Assemblies which I created and I use them for oldschool nav clients (NAV5.0) using COM interfaces and the setup is always done with VS2010 setups (Windows Installer .msi)

    But:
    Your problem could be also a dependency loading issue. - Have a look at this:
    http://stackoverflow.com/questions/255669/how-to-enable-assembly-bind-failure-logging-fusion-in-net

    Thank you thank you thank you!

    I had no idea that Visual Studio had an installer toolset... By fiddling around with the VS installer project, I was able to correctly register the DLL for COM interop.

    The key points to successfully registering a .NET DLL for COM interop are as follows:
    1. Make sure that the assembly is strong signed, otherwise it won't get registered for COM interop.
    2. The interface/class has to conform to these requirements:
      1. The names must match, e.g. IPrintTest and PrintTest.
      2. They must be public and "ComVisible".
    3. You have to generate a TLB file for the DLL and add it to the installer filesystem.

    I would provide you (you = everybody else with this issue, that might see this in the future) the project, but I can't since this is work related. I will however write a blog post about this when I get home and provide an example project there.
Sign In or Register to comment.