简体   繁体   English

C#Convert.ToDouble输入字符串在Windows服务中的格式不正确

[英]C# Convert.ToDouble Input string was not in a correct format in Windows service

I have been running a console app for the past few weeks with no issues. 过去几周我一直在运行控制台应用程序,没有任何问题。 However as soon as I converted the app to a windows service Ive been getting errors where I convert string to doubles using the Convert.ToDouble() function. 但是,一旦我将应用程序转换为Windows服务,我就会收到错误,其中我使用Convert.ToDouble()函数将字符串转换为双精度。 Here I get the error message "Input string was not in a correct format". 在这里,我收到错误消息“输入字符串的格式不正确”。

Other posts mainly refers to using culture info such as Convert.ToDouble(string, CultureInfo.InvariantCulture). 其他帖子主要指使用区域性信息,例如Convert.ToDouble(string,CultureInfo.InvariantCulture)。

But my code has been running for weeks without any issues, why would running the same code as a service make a difference? 但是我的代码已经运行了好几周没有任何问题,为什么运行与服务相同的代码会有所作为?

Thanks in advance! 提前致谢!

Your service probably runs under a different user (this is the most common problem (and answer regarding windows services) with a different culture. 您的服务可能在具有不同区域性的其他用户(这是最常见的问题(以及有关Windows服务的答案))下运行。

To quickly test this - set your service to start as You. 要快速进行测试-将您的服务设置为以您的身份启动。 If my theory is correct it should run ok. 如果我的理论是正确的,那应该可以。 Do not solve the problem this way. 不要这样解决问题。 Instead change back to the user you should use and verify you get the problem back. 而是改回您应该使用的用户,并验证是否可以解决问题。 Now you Know it is user related. 现在您知道它与用户相关。

Then do what the interwebs propose with InvariantCulture to solve the problem properly. 然后使用InvariantCulture进行互连网建议以正确解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 输入字符串在Convert.ToDouble(“ Infinity”)上的格式不正确 - Input string was not in a correct format on Convert.ToDouble(“Infinity”) Convert.ToDouble 异常:输入字符串的格式不正确 - Convert.ToDouble exception: Input string was not in a correct format 输入字符串的格式不正确。 在改变文化的IE中调用TimeSpan.FromSeconds(Convert.ToDouble(time)) - Input string was not in a correct format. calling TimeSpan.FromSeconds(Convert.ToDouble(time)) in IE on Changing Culture C#Convert.ToDouble格式异常错误 - c# Convert.ToDouble format exception error C#:在Windows 10上处理Convert.ToDouble('Infinity')的格式异常 - C#: Dealing with format exception for Convert.ToDouble('Infinity') on Windows 10 C#Convert.ToDouble()在将字符串转换为double时丢失小数点 - C# Convert.ToDouble() loses decimal points when converting string to double C#-将NumberFormatInfo与Convert.ToDouble一起使用以返回double - C# - Using NumberFormatInfo with Convert.ToDouble to return double C#webjob convert.todouble在azure上工作错误 - C# webjob convert.todouble works wrong on azure 为什么返回C#Convert.ToDouble(5/100)0.0而不是0.05 - Why returns C# Convert.ToDouble(5/100) 0.0 and not 0.05 C#中的Convert.ToDouble和Double.Parse - Convert.ToDouble and Double.Parse in C#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM