I looked on StackOverflow, but did not see a posted question/solution for this (but maybe missed).
I am looking for a way to test my COM server that is created in C# (i.e. registered for COM interop). When I try and add a reference to the COM object in a different C# project I get the error "...COMTest.tld was exported from a .NET assembly and cannot be added as a reference." I tried from VB and, of course, the same error. The references for the new projects in C# and VB were done from the COM tab after selecting Add Reference when right clicking on the solutions. Finally, I went to Visual C++, but did not see a way to add the reference and access COMTest.
Thanks for looking and any help! Feel free to let me know if any clarification is needed.
Related
Hi guys im just new in C# i came from a PHP background. I'm working on a RFID project which has RRU1861CSharp.dll which is dependent to basic.dll. I am able to add reference RRU1861CSharp.dll but when i'm trying to add reference basic.dll it says:
"basic.dll could not be added please make sure that the file is accessible, and that is a valid assembly or COM component".
I cant post picture sorry i don't have enough reputation.
You don't need to add the dependencies of RRU1861CSharp.dll to the project. It sounds like it's not a .NET assembly which is why you can't; however, you do have to ensure that it is installed on the final client/server where your app will run, along with all the other dependencies of RRU1861CSharp.dll.
It also has to be accessible on you dev machine to run the app from VS.
However, it is not a reference: References are only the things your app needs directly.
I am actually trying to use a DLL on a C# project. The problem is, whenever I try to import it in my project by adding it as a reference, I get this error message :
A reference to "C:\FilePath\LnkEMP.dll" could not be added.
Check that the file is an assembly or a valid COM component
The library is "LnkEMP.dll", used for a program called Expert/M Plus. I need this library to interract with this program.
I think that this DLL is made in C++, which could be one of the reason that my C# project can't load it.
I tried to make a C++ Library and importing it, but this time I had another error message :
A reference to "C:\FilePath\LnkEMP.dll" could not be added,
because it is not an assembly .NET, or not a registered ActiveX control
Do you have any idea of what should I do to get it work ?
You can fall back on dynamic loading of dll using Win32 api calls. There should be lots of examples of dynamical loading/calling of external dll. Hopefully your dll comes with doc on how to use it.
I have a ActiveX COM control and its source code. I wanted to change one of the method's input parameter, so I changed the IDL etc and generated the COM DLL and TLB.
But when I imported the COM DLL in a .NET project the method had retained its old signature. So I tried to generate the ActiveX DLL using AXIMP (though it is all the same, I wanted to give a try).
Still the method's signature did not change to what I changed to.
But when I generated the interop DLL using TLBIMP from the TLB file generated, the method signature changed correctly.
Where can I be wrong?
Thanks.
There are a lot of manual steps involved so it easy to miss one. It rather depends on how you imported the type library, there's more than one way to do it. If you picked the reference from the Add Reference + COM tab then the likely mistake is that you forgot to re-register the new COM server. Or you accidentally picked the old one instead of the new one, which can happen when you change the guids, like you should, and forgot to cleanup the old one. Cleaning up is pretty important and easily missed since it needs to be done before you rebuild the COM server. You can end up with a lot of garbage in the registry.
And yes, using Tlbimp.exe directly is the most reliable way to avoid accidents. Since you run it directly on the type library and don't use the registry at all.
A recipe for having the least possible amount of trouble could look like this:
Unregister the old COM server first by running regsvr.exe -u
Delete the old DLL and TLB files
Change the IDL to add your new method
Assign a new IID for the interface you changed
Assign a new CLSID for the coclass that uses the interface
Increment the library version
Change the name of the output DLL, favor including the major+minor version in the name
Build the new COM server
Register the server with regsvr32.exe
Run Tlbimp.exe to generate the interop library
Remove the reference to the old interop library in your .NET project
Use Add Reference + Browse to add the new interop library
Skipping any of these steps can invoke build trouble, registry pollution, DLL Hell and having an all-around lousy wrecked day without getting anything done.
i have download the code from the codeProject web site but while runnig this i got the reference error of the dll in the reference folder. the dll file is located in my bin/debug/
folder. still it not found it. when i add this file from add reference tag i give the error
that this is not valid com component.
please help in this
thanks in advance.
If the DLL is a COM library, you will need to register it manually using regsvr32. Then you can access it by name from the COM tab of the Add Reference dialog (see below).
(source: com.com)
If, on the other hand the DLL is native code as Jon Skeet suggested, you will only be able to use it by p/invoking to call its interface directly - if this is the case, it is best to create a class that acts as a wrapper around the DLL - that puts a layer of indirection between your code and all the p/invoke stuff so your code isn't too tightly bound to the interface of the DLL.
Well, you haven't said which project it is... but my guess is that you're trying to add a reference to a native code DLL, rather than either a COM library or a .NET class library.
If you provide more details, we're far more likely to be able to help you.
I have a DLL (Test.dll) which contains some Excel Addin, i don't know which version this is build with (might be with VB6, but i am not sure).
When i tried referencing this DLL in the VS2008 i get the message
A reference to the <DLL Name> could not be added. Please make sure that the file is accrssible, and that it is a valid assembly or COM Component.
If anyone could please help me in this, it will be great.
Any help is appreciated.
Thanks and Regards,
Tushar
It seems to me the DLL you're trying to load isn't a managed DLL, or one that the CLR can treat as managed.
One solution would be to use managed C++ (C++/CLI) to build a wrapper around the DLL. Another is to use PInvoke which is explained here and there's a tool for it I came across here.
You can also look in this thread: Unable to Use DLL of VB6 Into ASP.NET.
Hope one these work out for you,
Asaf