Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine if Copy Local is necessary

I tried to reference System.Device in a Razor view of my MVC C# project. It complained that the reference was missing even after I added it to the project. I did not have the assembly in my GAC, and to test I added the below dummy line in my global.asax.cs file (and compiled with multiple debug flags enabled, I wouldn't imagine it was optimized away).

new System.Device.Location.GeoCoordinate();

as well as this line in my controller's action:

System.Diagnostics.Debug.WriteLine(System.Device.Location.GeoCoordinate.Unknown.IsUnknown);

This still did not do it. Finding this solution I checked my GAC but it was not there (which made sense, but good to check). After finding this solution I marked the reference as Copy Local and the issue went away.

Why did I need to mark my reference as Copy Local even though I explicitly made a call to the library?

like image 781
mlhDev Avatar asked Jan 20 '17 21:01

mlhDev


1 Answers

If the DLL isn't in a "discoverable" location, such as the GAC or a path in the path environment variable, then you need to use copy local to automatically move it (on build) to your output directory, which is discoverable (or, more correctly, is on the probing path).

like image 90
competent_tech Avatar answered Sep 29 '22 09:09

competent_tech