cannot add a reference .NET

后端 未结 6 1757
独厮守ぢ
独厮守ぢ 2021-02-05 22:50

I have a DLL which I would like to add as a reference to my project, but everytime I try to do it a dialog pops up telling me:

The reference could not be

相关标签:
6条回答
  • 2021-02-05 23:19

    Try changing your Platform Target from Any CPU to x86. (project properties -> Build -> Platform Target)

    0 讨论(0)
  • 2021-02-05 23:21

    There are multiple answeres to your question:

    1. you may face this problem because the assembly you are trying to add is targeted and compiled for a x86 processor architecture. Just try change the Target Platform from x64 to x86 and even if that doent work, try change it to AnyCPU. AnyCPU Platform target makes your application executable on both types of architecture because it is architecture-free.

    2. If the assembly happens to be a DLL, and it cannot be added as a reference, then it is not a COM as well as .NET assembly. It will be a native assembly like others (for example, shell32.dll, user32.dl etc). You have to use them via DllImport attribute, but you must first check the documentation of that dll to get the list of functions implemented in that dll.

    0 讨论(0)
  • 2021-02-05 23:21

    Some DLL's cant be added as a reference, but however, they can still be used by C# with the famous [DllImport( params go here...)]

    You might also have to inspect the dll in order to get the address of the functions you want to use . This can be achieved by using GetProcAddress

    0 讨论(0)
  • after trying to analyse the issue, I discover the following

    [1] sometimes you see the reference in the reference manager, but you will not find the dll files in the mentioned directory where the Reference manager is not able to actualize the references.

    [2] check the permission of your dll file.

    0 讨论(0)
  • 2021-02-05 23:39

    You can not add unmanaged DLLs as references in Visual Studio, regardless of the 32/64 "bittyness". And I doubt that it worked on your x86 machine.

    There's a difference between "normal" DLLs and COM-DLLs.

    You can add a reference to a COM-DLL after it was registered with the system (actually you reference the exposed COM object and a reference to the DLL is added automatically). This can be done on the "COM"-Tab of the "Add reference" dialog (here you have to make sure that your project is built as a x86 target in most cases).

    "normal" DLLs can - as I said - not be added at all. You can include them in the solution (right click solution, select "Add existing file"), but they will not be referenced unless you declare something like

    [DllImport("...")]
    public static extern void MyFunction();
    

    I suspect that in your other solution, there's some kind of wrapper DLL, which you are actually referencing and which contains the DLL imports.

    0 讨论(0)
  • 2021-02-05 23:44

    Possibly the Type Library Importer (Tlbimp.exe) can help. It creates a wrapper .NET dll. The original COM DLL must still be there and must be registered! (Try to register it first, before trying it with TlbImp.)

    If the 64-bit version does not work, set the platform target to x84 in your project build properties.

    0 讨论(0)
提交回复
热议问题