简体   繁体   English

Navision C / AL使用C#COM dll创建错误

[英]Navision C/AL Create error with C# COM dll

I'm developing a report for Navision 2009 SP1 (Classic Client), where the need for extra functionality unavailable in NAV has arisen. 我正在为Navision 2009 SP1(经典客户端)编写一份报告,其中出现了对NAV中不可用的额外功能的需求。

I have created a COM dll in C#, installed it (using InstallShield "free" vs version) and created an automation variable in NAV. 我已经在C#中创建了一个COM dll,并安装了它(使用InstallShield“免费” vs版本),并在NAV中创建了一个自动化变量。 The class and interface are visible and I see the Print method, but when I try to CREATE the variable, I get the following error: 类和接口是可见的,并且可以看到Print方法,但是当我尝试创建变量时,出现以下错误:

"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." “无法创建由...标识的OLE控件或自动化服务器的实例。请检查OLE控件或自动化服务器是否已正确安装和注册。”

This is the code (just trying to get a connection going): 这是代码(只是尝试建立连接):

[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 production environment only has .NET Framework Client Profile (3.5 and 4.0), this means that Regasm is available (in 4.0) and that gacutil is not. 生产环境仅具有.NET Framework Client Profile(3.5和4.0),这意味着Regasm可用(在4.0中),而gacutil则不可用。

I'm assuming that there's something wrong with my code and not InstallShield, since the dll is available for selection in Navision,- and that the issue arises when I try to create the nav automation variable. 我假设我的代码有问题,而不是InstallShield,因为dll可在Navision中选择,并且在尝试创建nav自动化变量时会出现问题。

Best regards Marcus 最好的问候马库斯

Alright, so there's nothing wrong with the above code, and apparently Visual Studio also has an installer toolset. 好的,上面的代码没有任何问题,显然Visual Studio也具有安装程序工具集。

I created a new solution, recreated the library project and added the VS installer project instead of the InstallShield one. 我创建了一个新的解决方案,重新创建了库项目,并添加了VS安装程序项目而不是InstallShield。 I made sure that the library assembly was strong signed and I added a TLB file that I generated to the "FileSystem" in the installer project. 我确保库程序集是经过强签名的,然后将生成的TLB文件添加到安装程序项目中的“ FileSystem”。 The installer project will automatically register the TLB file as a dependency, so the TLB file can be deleted from the "FileSystem" afterwards. 安装程序项目将自动将TLB文件注册为依赖项,因此之后可以从“ FileSystem”中删除TLB文件。

With that setup I was able to correctly register the DLL for COM interop. 通过该设置,我能够正确注册用于COM互操作的DLL。

So the key points to remember are: 因此,要记住的关键点是:

  • If you have the same setup as I do (interface and class), make sure that both of them are ComVisible and public. 如果您具有与我相同的设置(接口和类),请确保它们都是ComVisible且是公共的。 Furthermore they need to have matching names, eg "IPrinterTest" & "PrinterTest". 此外,它们需要具有匹配的名称,例如“ IPrinterTest”和“ PrinterTest”。
  • Make sure that the assembly is strong signed. 确保程序集带有强符号。
  • You have to generate a TLB file for the DLL and add it to the installer "FileSystem". 您必须为DLL生成一个TLB文件,并将其添加到安装程序“ FileSystem”中。

I'll edit this answer later with a blog post detailing the whole process. 我将在稍后的博客文章中详细介绍整个过程,以编辑此答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM