0

I have a class library and want more than one application to reference it without setting the (Copy Local) property of the reference to True, i.e. I want the absolute path of the class library.

When I add reference to the DLL file of the class library it throws a run time error for not finding the location of the DLL file.

Is it possible to reference the class library with absolute path ?

MORE DETAILS

I was trying to test a specific scenario; I have a static class with a static variable in the class library and I made 2 test WinForm applications identical to each other (that simply set and get a static variable) that reference the class library.

I wanted to check if the static variable is shared between those 2 applications or not but I found they are not because the class library DLL file is copied to each application output directory.

This test was to decide if I should make a class in a class library in an application I am developing be static or no-static ?

Taher
  • 565
  • 1
  • 14
  • 32
  • Why do you want to use an absolute path to reference a file? That doesn't sound very portable and usable. That will easily break as soon as the directory structure is not the same anymore because the project has been moved or even loaded on a different computer. Please [edit] your question to include a more detailed description of your problem, the project structure you have, the problem you have with "Copy Local" and where/how you get the runtime error (including the error message as well). – Progman Feb 26 '21 at 22:45
  • I added more details to my question, and as for the error its most probably that the application can't find the DLL file in the root directory. – Taher Feb 27 '21 at 06:34
  • 1
    Does this answer your question? [Static members behavior with multiple instance of application - C#](https://stackoverflow.com/questions/17272544/static-members-behavior-with-multiple-instance-of-application-c-sharp) – Progman Feb 27 '21 at 08:23
  • I looked at the link you mentioned from what I understood, it applies on the same application but multiple instances but I can't be sure if this will apply to a class library that is being referenced by multiple application. In case I allowed the reference to be copied to the application output directory, sure it will work and the AppDomian stuff will work as mentioned in the link. But will this be applicable if I used an absolute path for the DLL reference, thats what I was trying to test but I have no way to do so. – Taher Feb 27 '21 at 09:17
  • 1
    It doesn't matter if you use an absolute path or not, the build process will copy the DLL file to the output directory `debug/` or `release/` anyway. You can put the DLL in the [Global Assembly Cache](https://learn.microsoft.com/en-us/dotnet/framework/app-domains/gac) (but you shouldn't do that) and your application will load the assembly from there. But in the end, `static` fields are still only "static" inside the application process as mentioned in the linked question, the content will not be shared between two application processes/instances. – Progman Feb 27 '21 at 09:28
  • Well that interesting to know. So the GAC is where .NET assemblies (like System.Drawing, System.Windows.Forms , etc) is located without having to make a copy of those reference to my app or my application will be very big in size, so if I want my class library that way I should put it in the GAC. Thanks, @Progman – Taher Feb 27 '21 at 09:47

0 Answers0