kylewest / DotNetShipping

UPS, FedEx, USPS shipping rate calculators for .NET
MIT License
78 stars 66 forks source link

Rates to some countries fail because of RegionInfo call to get English name in Address.cs file #38

Closed jjohndrow closed 8 years ago

jjohndrow commented 8 years ago

We had an issue with this and several countries. One issue is that we have a very old site and our system was storing England (EN) instead of Great Britain (GB). I had to manually translate this to GB before passing it in. That's fine and dandy as our DD should be changed to GB. Other countries though have issues too. The RegionInfo call that is made to pull back the countries name from the 2 letter code errors for some countries do to that call. This relies on different versions of RegionInfo depending on system. On my development machine it works fine but if you deploy that to an older server, Say server 2008 R2. It will blow chunks with an error like below which you would see in your servers event viewer.

An unhandled exception occurred and the process was terminated. Application ID: /LM/W3SVC/8/ROOT/ShipCalc Process ID: 28816 Exception: System.ArgumentException Message: The region name BS should not correspond to neutral culture; a specific culture name is required. Parameter name: name StackTrace: at System.Globalization.RegionInfo..ctor(String name) at DotNetShipping.Address.GetCountryName() at DotNetShipping.ShippingProviders.USPSInternationalProvider.GetRates()

Specifically this is Barbados but many others also blow chunks. The worst part about this error is there is not only does the call fail, but it fails hard and eventually takes out the entire app pool breaking the application. Ones I know have issues at times. Bahamas (BS->BAHAMAS), Saint Vincent (VC -> GRENADINES), Hong Kong (HK->China), Tanzania (TZ->TANZANIA) , and South Korea (KR-> South Korea).

I pulled source and found where the issue is. Its in Address.cs and the call is

var regionInfo = new RegionInfo(CountryCode); toReturn = regionInfo.EnglishName;

The correct fix would be to not rely on RegionInfo and instead have a translation list. I have replaced mine with custom translation for the countries we are having issues with.

kylewest commented 8 years ago

@jjohndrow did you find a fix for this? thanks,

kyle

judah4 commented 8 years ago

I made a pull request to make the country name assignable and to prevent the RegionInfo from crashing the whole application. https://github.com/kylewest/DotNetShipping/pull/44

Soulfire86 commented 8 years ago

Merged PR #44 Thanks @judah4