When you select the data value in a property of the class the following error is generated "Input string not in a correct format".
I'm converting the date as in the image one it generates correct, but when assigning the error is generated.
I converted it to DateTime and also created it as new, but still the error happens.
The same occurs when use Scheduled = sd,
I am using asp.net core
1. Convert.ToDateTime is bothering me, although is not throwing this exception.
First of all, you should not call Convert.ToDateTime on a date time object.
it does not throw exception but it does not do any conversion also.
Refer MSDN Documentation here.
2. The exception has clear details that it is failed to convert a string to number
Stack trace is showing that "System.Number.StringToNumber" conversion failed.
So it is one of the other 3 properties which are string and you are trying to convert them to Int64 or long.
You would know which property by line number if you are running solution in debug mode.
3. If your values are integer strings (e.g. "10" ) even then if it is not working, then there is problem in culture settings of machine.
Please refer the complete thread here
It is saying that sometimes your conversion fails from "10" to integer value 10 because some registry settings are not set correctly. You can correct them by:
While it is possible to directly edit the value for the problem key,
the preferred method is to change the Regional Settings to a different
Region/Language and then reset it to the desired setting:
Open the Regional and Language Options applet from the Control Panel.
Note the Current Format.
Change the Current Format to English (Australian)
Click Apply.
Change the Current Format to the noted format, eg, English (American).
Click Apply and then click OK.
This should resolve your issue.
Related
I am completely lost with this.
So, I'm trying to use int.TryParse to parse a string, a perfectly valid string containing literally the number "3", that's it. But, it's giving me back false when I try to parse it.
This is how I'm using it - I've debugged it, and int.TryParse is definitely giving back false, as the code in the if statement runs:
if (!int.TryParse(numberSplitParts[0], out int hour))
return false;
And I've looked in the debugger numberSplitParts[0] is definitely the digit 3, that's perfectly valid!
Now, I did some research and people have been saying to use the invariant CultureInfo, so, I did that, here's the new updated line (I also tried NumberStyles.Any and that didn't work either):
if (!int.TryParse(numberSplitParts[0], NumberStyles.Integer, CultureInfo.InvariantCulture, out int hour))
return false;
That also doesn't work - it continues to give me back false, and hour is 0.
I've tried all of the other number types as well - byte.Parse, Int16.Parse etc. All of those gave back false too.
And, I've tried regular int.Parse, and that simply gives me the following exception:
System.FormatException: 'Input string was not in a correct format.'
But then, I tried it in a different project, so, I replicated the string array and everything, and it worked there - both with and without "InvariantCulture".
So, I'm suspecting that the project I'm working in must be configured in such a way that caused int.Parse/int.TryParse to not work. This is in a class library, that is being accessed from a UWP Application - could the fact that this is running under UWP have any effect?
As discussed in the comments, this is due to a couple of LEFT-TO-RIGHT MARK Unicode characters in your input.
When you did your test in a different project, you probably hard-coded the string "3", or got your input from a source which didn't add the same invisible characters.
A better test is to check whether numberSplitParts[0] == "3", either in the watch window or in your code itself. Another is to set numberSplitParts[0] = "3" in your UWP project, and see if that parses correctly.
In my experience, most cases of "this string looks fine but <stuff> fails" is due to invisible Unicode characters sneaking into your input.
I have a method that prints labels from a Web Application in MVC5, for this I am using the Neodinamyc plugin
The problem is that this method delivers the encoded parameters, for the first printerName parameter I was able to decode it in the following way and I succeeded
But I think that the second parameter called location that is of integer type gives it to me as hexadecimal or at least I think so, since the error says: "can not be converted from int to string"
I'm currently testing with
ubicacion = Convert.ToInt32(ubicacion);
and it does not work for me, it still has the same value
Why do I get this hexadecimal type number when I pass an integer?
How can I convert this parameter to an integer? any help for me?
The value doesn't need to be converted, it's already an integer.
Your tooltip is just displaying it in hexadecimal. You can change this by right-clicking the tooltip and unselecting Hexadecimal Display
For formatting our Dates in the RDL-Files, we use the following format:
=First(FormatDateTime(Fields!SomeDate.Value, 2))
According to this Page, it should take the Computer's Regional Settings.
The problem is: If I call the Reporting-Service via another Service and try to set the Language:
rs.SetExecutionParameters(MapParameters(Report.Parameters).ToArray(), "de-CH");
This gets ignored. I tried to override the Thread-Cultures via
System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("de-CH");
System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("de-CH");
Which gets ignored as well.
Whats really string: The Reporting-Server itself has de-CH as culture as well, but it keeps using the english date-format.
Can someone tells me what's meant with "Computer's Regional Settings" and why the Reporting-Service refuses to take the passed Culture?
Edit: The language in the Report is
=User!Language
Generally said I'd like to pass the Report-Language from outside, be it via CurrentThread or via Parameter. But both get ignored.
Short Answer
Instead of FormatDateTime, you could use Format and specify your expected output format:
=First(Format(Fields!SomeDate.Value, "dd.MM.yyyy"))
Or another alternative to have the culture in a parameter, but in this case you will have to read the long answer.
Long answer
Your first attempt with the SetExecutionParameters was to set the culture of the parameters, which does not affect the report itself (only the parameters you pass to it).
Your second attempt was to change the culture of the client application, which also does not affect the report (only the client application culture).
The FormatDateTime function usually uses the computer regional settings, but not in Reporting Services. It will take the report culture, which in your case is User!Language.
User!Language returns the language configured in the client web browser when browsing to the report server.
I'm not sure what the behavior is when calling from web services (a specific setting taken or default to en-US).
The Report Language property can be an expression, so nothing stops you from adding another text parameter to the report, say, ReportCulture, and use this in Properties => Language:
=Parameters!ReportCulture.Value
You would have to keep using your expression for the dates:
=First(FormatDateTime(Fields!SomeDate.Value, 2))
You can configure a default value (de-CH in your case), so that this setting will only be specified if you want to override it.
I'm receiving an error which looks like it is due to an error using hexidecimal inputs in a uint field. It occurs on both versions of the web service I'm working on.
System.ArgumentException: Cannot convert 0x2 to System.UInt32.
Parameter name: type ---> System.FormatException: Input string was not in a correct format.
However, my coworker says that it works for him on a previous version of the web service I have, when he calls it using C++, but it doesn't work on the current version I'm working on.
Has anyone experienced this?
Are you using something like this in your code? If not, try to implement this (replace "CF01" with your input value):
int i = Convert.ToInt32("CF01", 16);
Edit:
For the particular case with the 0x prefix:
public int32 GetInt32FromHex(string h) {
h = h.substring(2, (h.length - 2));
return convert.ToInt32(h, 16);
}
This is quite an interesting error because it seems like the Parse method of UInt32 is only able to parse numbers of the form [ws][sign]digits[ws] per the documentation. There is a version of the method that can take NumberStyles flags see documentation. One of the values of this is AllowHexSpecifier which you'd think would allow the 0x. However if you read the documentation for both the Parse method and the NumberStyles unable to handle the 0x format at all. If you look at the it says:
If s is the string representation of a hexadecimal number, it cannot be preceded by any decoration (such as 0x or &h) that differentiates it as a hexadecimal number. This causes the conversion to fail.
The AllowHexSpecifier makes it so that only numbers of the form [ws]hexdigits[ws]
It seems like you are going to have to get rid of the leading 0x before parsing or use another method of parsing.
One way to do that, especially if there is a leading 0x is to do the following:
var value = UInt32.Parse( "0x2".TrimStart('0').TrimStart('x'));
You will have to be careful here to do checking to make sure you have the proper base though and you may need to use the NumberStyles.AllowHexSpecifier to parse correctly.
I tried searching google and stackoverflow without success.
I'm having a problem with "Input string was not in a correct format." exception with an application I'm working at.
Thing is, that I convert some double values to strings with doubleNumber.ToString("N2"); in order to store them in XML file. When I switch testing machines, XML file stored on one can't be returned back to double values.
I've tried all of the solutions I could think of, but setting number culture didn't work, using CultureInfo.InvariantCulture, replacing characters also doesn't work. Sometimes the values are stored like "3,001,435.57" and sometimes (on other PC) like "3.001.435,57".
Is there some function or a way to parse a double from string, whatever the input format is?
Thanks.
You have to specify a culture because (eg.) "3,001" is ambiguous - is it 3.001 or 3001?
Depending on what your numbers look like, perhaps you could attempt to detect the culture by counting number of , and . characters and/or checking their positions.
Here is what you are looking for...
http://msdn.microsoft.com/en-us/library/9s9ak971.aspx
This will accept a string variable and a format provider. You need to create a format provider that provides the culture information you are looking to convert out of.