VS2005 C#: Reloading a reference - c#

Similar to coryr (see this question), I am referencing a dll within a C# project. The DLL often changes but I the C# project does not recognize this. Unlike coryr, the DLL is a VB6 ActiveX DLL. Any suggestions for how to reload the reference other than removing and adding it?

The problem here is that when you add a reference to a COM DLL, you don't actually add a reference to the DLL. Instead a primary interop assembly is generated for the DLL and a reference is added to that. When the main DLL is changed a new PIA (primary interop assembly) is not generated.
You can verify this by doing the following
Expand the references collection
Hit F4. This will bring up the properties page
Look at the path property
The path will be the path to the PIA.
The problem is that VS is watching the PIA and not the original DLL. So when the original DLL changes it doesn't actually reload the reference. The best way to get this to work is to unfortunately delete and re-add the reference.
Another solution is to manually generate the PIA and place it over the referenced PIA on disk. This will force VS to reload the DLL reference.

Related

Reference 3rd-party C++ DLL into VS 2013 Project

I've been provided a DLL that has been written in C++. Along with the DLL I receive the required input parms and expected output as well as a .h include file.
Can't seem to get it included as a Reference in my project. My procedure is to right click References and Add Reference, click Browse and then double click on the DLL. The error I get is:
A reference to 'c:......\dll' could not be added. Please make sure
that the file is accessible, and that it is a valid assembly or COM
component.
The problem is likely due to the name mangling of C++, but I'm not sure how to overcome the problem. I've been told by the author of the DLL that it was written for another customer who ran into the same issue, but was eventually successful in getting it referenced. I don't have access to that 'customer' and was wondering if anyone had suggestions.
Adding a reference is not how you link to this unmanaged DLL from your C# code. Instead you need to either:
Translate the header file to C# p/invoke calls, or
Create a C++/CLI wrapper around the unmanaged DLL and add a reference to that from your C# project. This option would typically involve linking to the .lib import library for the DLL which should be supplied with the DLL.

How to Replace DLL Reference in Windows Phone App

A code sample I am referencing also provides updated DLL's to reference in the sample project. When I delete the current DLLs and then add a reference to the new versions, I get an error saying A reference to a higher version or incompatible assembly cannot be added to the project. Not sure what this means, the assemblies are specifically for a windows phone project and are meant to be as updates/replacements to fix some bug issues.
The DLL to be referenced must be Unblocked beforehand. Right Click on the DLL, go to the properties option, then select Unblock. This must be done one at a time for each DLL to be added.

Why I need to remove and add dll reference every time in Visual Studio .NET

I am adding one dll reference to my project. Whenever I modify the dll, I copy the dll the same folder overwriting the old one. But my compiler starts giving errors on the dll methods. Every time I have to remove the dll reference from the project and re-add the reference to build it.
My question is, why I need to remove and add reference every time? .NET should take the new dll automatically?
As others have stated, this appears to be a versioning issue. An alternative to adding the project to your solution (if you don't want it in there for some reason, or you have a requirement to reference the dll directly) is to modify your reference so that it doesn't look for a specific version.
Find the reference to the built assembly in the 'References' project folder
Right click on the reference
Change 'Specific Version' to false
hth
If you have one project depending on the other, put them in the same solution and add the dependant project as a "Project Reference" rather than referencing the DLL directly.
Alternatively, if you want to use an assembly in multiple places, you can create a NuGet package. You can place these in either public or private feeds - and then add the dependency using NuGet.
If you do either of these the dependency will be managed for you.

Add a VB6 ActiveX DLL reference to a VS2008 project

At work, we have a VB6 project (ActiveX DLL) that we need to be able to add as a reference to another VS2008 C# project.
A developer there tells me that in the past, they have been able to do so but now we made a change to the VB6 DLL and had to recompile it.
As such, we need to update the reference in the VS2008 project but when we try to add the reference to the VB6 DLL back (after removing the old reference) to the VS2008 project, we get a yellow "!" icon on the newly added reference and then when we build, VS2008 says the reference cannot be found.
I tried the "Browse" and "COM" tabs where you can add reference, no luck.
Do we need some kind of TLB to be able to add it or something ?
Thanks.
You need to do the following from a command prompt:
#CD to wherever the dll is located
regsrv32 /u foo.dll
regsrv32 foo.dll
This will unregister the old com object and register the new one.
He's right, you could do that from command prompt.
Remember though, your Active-X control DLL could be 16-bit, so use
regsrv /u foo.dll
regsrv foo.dll
from command prompt. But 32-bit works fine for regsrv32!
I used OLE/COM object viewer (included in Windows SDK 6.0A) then I saw a bunch of COM entries in "All objects" ie: MyDLLName.className and some were pointing to a DLL file which did not exist anymore. Deleted all the relevant COM entries in the Windows registry that pointed to the deleted DLL and left all the ones which pointed to the existing DLL and then I could import it successfully in my VC# project.

Problems adding a UserControl referencing a C++/CLI wrapper to a unmanaged dll to a form

My UserControl references a C++/CLI wrapper to an unmanaged C++ dll. When I try to add the UserControl to a form, I get a Visual Studio error, which says "Failed to create component 'userControl'", giving a System.IO.FileNotFoundException as the cause.
From what I've been able to determine, the problem stems from visual studio not copying the C++/CLI wrapper assembly's unmanaged dependencies. If I put the unmanaged dependencies on the system PATH, everything works fine.
Is there a better way of doing this?
The easiest thing to do would be to include the actual .dll in your project, mark its build action as "Content", then set the Copy to Output Directory to "Always". This should get the .dll into your output directory so that your application can run, and just including the file in the project should put it in the project directory so that the designer can find it.
Be sure that your setup project includes a project output for the Content files from that project as well.
Edit
If those don't work, you can also edit the reference paths of the project itself (in the project properties), though I am not certain that this will affect the designer. If that doesn't then your only real option is to have the .dll in one of the system path directories.
Old thread, but submitting my solution since I just encountered the issue and found this question during the process.
Basically I just made the native DLLs to be delay loaded in my wrapper C++/CLI library. Since the C++/CLI part of the wrapper contains the interface specs used by Visual Studio and the framework, the native DLL is never needed or loaded. I answered it with a little more details in this question too:
https://stackoverflow.com/a/15481687/34440

Categories

Resources