1

This doesn't seem to make sense.

I'm trying to use the System.Device library in a project to take advantage of the geo location functionality. I'm adding code to a Razor page as I usually do.

I have a reference to the library and I've added the using to the top of the razor view:

@using System.Device;

Device has a red underline because it cannot be found. Typing System.D does not yield Device in intellisense. This doesn't seem to make sense as the library is definitely referenced.

The web.config is in Views has no mention of System.Device. If I do a full search of the solution for 'device' there are no mentions of it anywhere I wouldn't expect.

I've open and closed files, removed the reference, restarted VS, restarted my computer. Everything. It still persists.

I feel like either there's something I don't know or I'm doing something stupid. Am I missing something here?

Jon
  • 3,173
  • 3
  • 39
  • 66
  • You want the geo-location of the server, or the client? Razor pages run server-side, not client side. – Ron Beyer Nov 02 '15 at 21:55
  • I'm just wanting to use the functionality, I'm actually just taking advantage of the methods that tell me the difference between lat-long coords. – Jon Nov 02 '15 at 21:56
  • Instead of trying to include that, just get a formula for the great circle distance and use that, its a simple calculation and doesn't require you to try to include a library that isn't relevant for ASP. – Ron Beyer Nov 02 '15 at 21:58
  • That is certainly true but I had included this because it is faster than writing and testing a formula - time pressures, etc. I would also like to understand why this reference isn't working. – Jon Nov 02 '15 at 22:01
  • @RonBeyer It's not a simple calculation! But the formula has already been done in C# so should be easy to use. – DavidG Nov 02 '15 at 22:14
  • And here you go: http://www.geodatasource.com/developers/c-sharp – DavidG Nov 02 '15 at 22:15

1 Answers1

3

The web.config is in Views has no mention of System.Device.

You need to add System.Device to your web.config. Depending on whether you're using Areas you may need to add it to the web.config for that area too. If it's not in web.config, razor doesn't know about it.

 <namespaces>
    <add namespace="System.Device" />
 </namespaces>

Further, try setting Copy Local to True for the Reference Properties of System.Device. It didn't work for me until I did both.

Thomas Boby
  • 778
  • 8
  • 22
  • You can reference a library on individual Razor views by typing `@System.Whatever.Library` at the top of your view, much as you would any C# file. – Jon Nov 02 '15 at 22:27
  • How about setting the Reference to Copy Local = true? – Thomas Boby Nov 02 '15 at 22:33
  • The combo of copy local and adding it to the web.config is what seemed to solve this. I would like to understand why that solved the issue when I am referencing other libraries at the top of Razor views just fine. Doesn't seem to make any sense. – Jon Nov 03 '15 at 12:25