1

I am trying to test a sample project called Android.Routing.Offline from OsmSharp.Samples in Github.

After two taps on the screen (the first one gets just the GeoCoordinate) I get a ProtoBuf.ProtoException in the Router.cs

private static IBasicRouterDataSource<CHEdgeData> _graph;

    public static void Initialize()
        {
            var routingSerializer = new CHEdgeDataDataSourceSerializer();
            _graph = routingSerializer.Deserialize(
                Assembly.GetExecutingAssembly().GetManifestResourceStream(@"Android.Routing.Offline.kempen-big.contracted.mobile.routing"));
        }

    public static Route Calculate(GeoCoordinate from, GeoCoordinate to)
            {
                try
                {
                    lock(_graph)
                    {
                        var router = Router.CreateCHFrom(_graph, new CHRouter(), new OsmRoutingInterpreter());

                        // The exception happens here below
                        var fromResolved = router.Resolve(Vehicle.Car, from); 
                        var toResolved = router.Resolve(Vehicle.Car, to);

                        if(fromResolved != null && toResolved !=null)
                        {
                            return router.Calculate(Vehicle.Car, fromResolved, toResolved);
                        }
                    }
                }
                catch(Exception ex)
                {
                    OsmSharp.Logging.Log.TraceEvent("Router", OsmSharp.Logging.TraceEventType.Critical, "Unhandled exception occured: {0}", ex.ToString());
                }
                return null;
            }

And the exception:

  > {ProtoBuf.ProtoException: Invalid wire-type; this usually means you
    > have over-written a file without truncating or setting the length; see
    > http://stackoverflow.com/q/2152978/23354  at
    > ProtoBuf.ProtoReader.ReadSingle () ...

I didnt overwrite the file (kempen-big.contracted.mobile.routing) just added it as a linked file in the project. Any ideas how I can solve this issue?

Stam
  • 2,410
  • 6
  • 32
  • 58

1 Answers1

0

Well, the first thing to try is to check that the contents of the Stream you are reading (via GetManifestResourceStream) contains exactly the contents you are expecting, and not some wrapper or otherwise-corrupt mess. If you have some checksum algorithm you can run: great! Checking just the .Length would be a great start. Otherwise, you could cheat (just for the purposes of validating the contents) by getting the hex:

using (var ms = new MemoryStream())
{
    stream.CopyTo(ms);
    string hex = BitConverter.ToString(
        ms.GetBuffer(), 0, (int)ms.Length);
    // dump this string, and compare it to the same output run on the
    // oringal file; they should be identical
}

Note that this duplicates the contents in-memory, purely so we can get a byte[] (oversized) to get the hex from - it isn't intended for "real" code, but until you are sure that the contents are correct, all other bets are off. I strongly suspect that you'll find that the contents are not identical to the contents in the original file. Note that I'm also implicitly assuming that the original file works fine in terms of deserialization. If the original file doesn't work: again, all bets are off.

Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900
  • What do you mean by saying original file? I just downloaded the file from the github and I put a link of this file in the project .. even if I put the actual file in the project the same exception happens. – Stam Oct 28 '14 at 14:41
  • @Stam I mean the file that contains protobuf data. If that file doesn't parse in a simple console exe (not doing anything fancy like manifest streams), then there is a problem. – Marc Gravell Oct 28 '14 at 15:06