最も簡単な修正は何ですか?
このコードがオーストラリア (書かれた場所) で実行されると、動作します。
public static void CreatePointTest()
{
double lat = -33.613869;
double lon = 153.123456;
var text = string.Format("POINT({0} {1})", lon, lat);
// 4326 is most common coordinate system used by GPS/Maps
var ExceptionOnThisLine = DbGeography.PointFromText(text, 4326);
}
コンピューターの地域コードを「フランス語 (フランス)」に変更して実行すると、return ステートメントで例外が発生し、数値形式に関連しているように見えます。
System.Reflection.TargetInvocationException was unhandled
_HResult=-2146232828 _message=Exception has been thrown by the target of an invocation. HResult=-2146232828 IsTransient=false Message=Exception has been thrown by the target of an invocation. Source=mscorlib StackTrace:
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
[snip...]
InnerException: System.FormatException
_HResult=-2146233033
_message=24141: A number is expected at position 16 of the input. The input has ,613869.
HResult=-2146233033
IsTransient=false
Message=24141: A number is expected at position 16 of the input. The input has ,613869.
Source=Microsoft.SqlServer.Types
StackTrace:
at Microsoft.SqlServer.Types.WellKnownTextReader.RecognizeDouble()
at Microsoft.SqlServer.Types.WellKnownTextReader.ParsePointText(Boolean parseParentheses)
at Microsoft.SqlServer.Types.WellKnownTextReader.ParseTaggedText(OpenGisType type)
at Microsoft.SqlServer.Types.WellKnownTextReader.Read(OpenGisType type, Int32 srid)
at Microsoft.SqlServer.Types.SqlGeography.ParseText(OpenGisType type, SqlChars taggedText, Int32 srid)
at Microsoft.SqlServer.Types.SqlGeography.GeographyFromText(OpenGisType type, SqlChars taggedText, Int32 srid)
at Microsoft.SqlServer.Types.SqlGeography.STPointFromText(SqlChars pointTaggedText, Int32 srid)
InnerException: