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?
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With