RobThree / NGeoNames

Inspired by https://github.com/AReallyGoodName/OfflineReverseGeocode
MIT License
88 stars 22 forks source link

Reverse geocoders for different entity types are not possible #1

Closed dispmaxstaff closed 8 years ago

dispmaxstaff commented 8 years ago

Unfortunately it's impossible to create reverse geocoders of different entity types. It's unfortunate because I really like this library.

[TestMethod]
public void Geonames_MultipleEntities()
{
    var rgc1 = new ReverseGeoCode<Postalcode>();
    var rgc2 = new ReverseGeoCode<ExtendedGeoName>();
}
Test Name:  Geonames_MultipleEntities
Test FullName:  Tests.BetterGeocoding_LongRunning.Geonames_MultipleEntities
Test Outcome:   Failed
Test Duration:  0:00:00.012107

Result Message: 
Test method Tests.BetterGeocoding_LongRunning.Geonames_MultipleEntities threw exception: 
System.TypeInitializationException: The type initializer for 'DoubleMath' threw an exception. ---> System.ArgumentException: An item with the same key has already been added.
Result StackTrace:  
at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
   at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
   at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
   at KdTree.Math.TypeMath`1.Register[DataType](ITypeMath`1 math)
   at NGeoNames.ReverseGeoCode`1.DoubleMath..cctor()
 --- End of inner exception stack trace ---
    at NGeoNames.ReverseGeoCode`1.DoubleMath..ctor()
   at NGeoNames.ReverseGeoCode`1..ctor(IEnumerable`1 nodes)
   at NGeoNames.ReverseGeoCode`1..ctor()
   at Tests.BetterGeocoding_LongRunning.Geonames_MultipleEntities() in 
dispmaxstaff commented 8 years ago

Well, it happens that 2 DoubleMaths are created because of templating, I fixed by moving it out of templated class (ReverseGeoCode) which fixes the issue though this is really a kludge, so I won't send pull request.

RobThree commented 8 years ago

Was just looking into it. Expect a fix/update today.

dispmaxstaff commented 8 years ago

Hi Rob, great, thanks a lot! Is this possible for you to update nuget package too please, b/c now I have to use git submodule, which visual studio doesn't work well with. Anyway, thank you very much! :+1:

RobThree commented 8 years ago

Ofcourse, I'll publish an updated package :wink:

RobThree commented 8 years ago

Fixed (0fed42dc573f3f25b72bccf9869ff33f869ffcb1) and new NuGet package is published. :+1:

dispmaxstaff commented 8 years ago

Rob, thank you very much for a fix and great library!

RobThree commented 8 years ago

You're welcome :wink: