GPS detection problem

Mar 25, 2011 at 8:08 PM

In my app, I need to get GPS data from a usb/serial GPS. I was going to use a simple serial connection and parse the GPS data, when I found this project.

I'm trying to implement dotspatial.positioning but have a few issues. The first one is the lack of tutorials etc, so i'm using the source code of the GPS demo project. Unfortunately I'm unable to detect any gps devices. This is my code :

            DotSpatial.Positioning.Devices.DeviceDiscovered += new EventHandler<DeviceEventArgs>(Devices_DeviceDiscovered);
            DotSpatial.Positioning.Devices.DeviceDetectionAttemptFailed += new EventHandler<DeviceDetectionExceptionEventArgs>(Devices_DeviceDetectionAttemptFailed);
            DotSpatial.Positioning.Devices.BeginDetection();
And detection fails with the following error : 
{"Attempt by security transparent method 'DotSpatial.Positioning.SerialDevice.get_AllowConnections()' to access security critical method 'DotSpatial.Positioning.Devices.get_AllowSerialConnections()' failed.\n\nAssembly 'DotSpatial.Positioning, Version=1.0.0.34700, Culture=neutral, PublicKeyToken=f6f66d1554473068' is marked with the AllowPartiallyTrustedCallersAttribute, and uses the level 2 security transparency model.  Level 2 transparency causes all methods in AllowPartiallyTrustedCallers assemblies to become security transparent by default, which may be the cause of this exception."}

 I tried to just start the NmeaInterpreter but with same error

            _gpsInterpreter = new NmeaInterpreter();
            _gpsInterpreter.PositionChanged += new System.EventHandler<DotSpatial.Positioning.PositionEventArgs>(this.nmeaInterpreter1_PositionChanged);
            _gpsInterpreter.Start();

What am i doing wrong ?

 

btw: I'm using .net framework 4, vs2010, windows 7 64 bit

Editor
Apr 2, 2011 at 8:02 PM

The .NET 4.0 security model changes things up a bit... I resolved this by opening the DotSpatial.Positioning project, and changing the following:

In Devices.cs, add the [SecurityCritical] attribute to the Devices class by changing the class declaration from:

public static class Devices

... to ...

    [SecurityCritical]
    public static class Devices
You may have to import System.Security as well.
Coordinator
Apr 7, 2011 at 4:28 AM

Hi Brandon, I'm jut getting caught up here. Did you actually commit this change to the code? I hope that you feel comfortable committing such things. - Dan

Developer
Aug 4, 2011 at 2:40 AM

And this fixed it? Eureka! Ted and I had some issues with the security attributes (not our forte) when I merged the DotSpatial.Positioning namespace. If this fixes it then GREAT - it means that the refactored DotSpatial.Positiong classes without issue.

I can't belive it's that simple!!!

Oct 11, 2011 at 4:49 PM

I have the same issue. Downloaded the source and rebuilt ok but when I run DemoGPS it fails with the same security violation. The source has the above fix in it. Any ideas?

Dec 13, 2011 at 5:06 PM

Do we have any resolution or work around for this. Making the changes noted above does not solve this issue.

Dec 14, 2011 at 6:10 PM

I have been using DotSpatial successfully, but struggled with this issue quite bit. I had to make the following changes to get it to work:

 



1. BluetoothDevice.cs

Add:

[SecuritySafeCritical]
internal void Refresh()


2. Devices.cs

Add:

[SecuritySafeCritical]
public static class Devices
{

3. NmeaInterpreter.cs

    [SecuritySafeCritical]
    public class NmeaInterpreter : Interpreter
    {

These changes are on the latest source.

Regards

Kobus

Jan 24, 2012 at 9:21 AM

I downloaded the latest version, and the error in question still arises. Why?

Developer
Jan 25, 2012 at 3:19 PM

I didn't find those changes in the latest source. I'll move this to a work item. And make the changes. Please verify that these updates work for you.

Developer
Jan 25, 2012 at 3:20 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Nov 5, 2012 at 9:04 PM

Hello

When I look in the source code I have downloaded the changes mentioned in this thread is present, but when I run the DemoGPS program it does not detect the GPS unit I have attached to the PC.

It is a Garmin GPS18x USB.

I hope someone can help me figure out how to make DemoGPS detect the unit.

Developer
Nov 14, 2012 at 6:46 AM

Hi mudnug, I couldn't find this work item - has it already been completed?

Developer
Nov 14, 2012 at 6:48 AM

Great work kobusherbst! this was the major problem we faced after bringing the project over from GPS .NET 3.0