Browsing 15655 questions and answers with Jon Skeet

"String was not recognized as a valid DateTime.” error occurs for some exact dates

I have a problem converting Gregorian calendar dates to Persian(Hijri calendar) using default system "en-GB" culture in my ASP.NET MVC Application. I used the globalization tag in...
Jon Skeet
people
quotationmark

Leaving the parsing error aside, this isn't going to achieve what you want to achieve. A DateTime value is always in the Gregorian calendar - trying to parse 31/04/1396 as a DateTime is never going to work because it's not a valid date in... more 5/26/2017 9:05:41 AM

people

Empty array in string breaking deserialization

I have a string of JSON that I'm trying to convert into a list. There is an empty array value which is breaking the deserialization (have tried removing it manually or changing to...
Jon Skeet
people
quotationmark

The value is an array, but your field is a string. I suggest you make it an array (or list) of the appropriate type - we can't tell what that type would be from your JSON, but perhaps you want a string array? I'd also suggest using... more 5/25/2017 4:29:20 PM

people

Decryption using Aes fails

I am using this function to encrypt data in my UWP project: public string Encrypt(string text, string key) { byte[] buffer = Encoding.UTF8.GetBytes(text); ...
Jon Skeet
people
quotationmark

The problem is what you're doing with the end of the decryption: return Convert.ToBase64String(buffer); You actually want to convert the decrypted binary data back into a string in a way that mirrors the original way you converted it... more 5/25/2017 12:42:22 PM

people

Operator '?' cannot be applied to operand of type 'T' (2)

I came across a weird behavior of C# compiler (VS 2015). In the code bellow, compiler is happy with Value2, but complains about Value1: Operator '?' cannot be applied to operand...
Jon Skeet
people
quotationmark

I believe the problem is that the compiler can't know the type of the expression _valueProvider?.Value. Let's simplify this a bit: public interface IValueProvider<T> { T Value { get; } } public class Test { public static... more 5/25/2017 7:38:58 AM

people

Got an Exception, while reading the google spread sheet

I am beginner to read the google spread using service account in my project .For few days it work fine but now i got an exception as ...
Jon Skeet
people
quotationmark

Okay, I have an alternative solution. It doesn't explain exactly why things are going wrong, but it means you don't need to make the call at all. As you've already managed to call GetRSAPrivateKey() successfully, that may be all you need.... more 5/25/2017 7:02:57 AM

people

.net core / standard string.ToLower() has no culture parameter

In .net fx i can do myString.ToLower(frenchCulture); But when looking at .net core or .net standard there is no more a culture parameter that can be passed. There is only...
Jon Skeet
people
quotationmark

It looks like the capability is there, just in a more roundabout way. Instead of: string output = input.ToLower(culture); use string output = culture.TextInfo.ToLower(input); Also note that the overload has been added in... more 5/24/2017 10:51:16 AM

people

Parsing Json to zoned date time

Im reciving following json time format "TimeEnd": "2017-05-24 09:52:51+02:00" my dto is as follows: @JsonProperty("TimeEnd") @JsonDeserialize(using =...
Jon Skeet
people
quotationmark

You shouldn't be trying to parse it as a ZonedDateTime, as it really doesn't have a time zone - it has a UTC offset. OffsetDateTime is more appropriate here. It's worth differentiating between the two types - you can create a ZonedDateTime... more 5/24/2017 10:24:38 AM

people

In java.time.Period class, what are the purposes of withDays(), withMonths(), withYears()

I noticed that the java.time.Period class contains a few instance methods that behave the same as the available static factory methods. .withDays() behaves the same as...
Jon Skeet
people
quotationmark

You made an unfortunate choice to test with, basically - "weeks" isn't an independent unit; it's just a shorthand for 7 days. From the docs for ofWeeks: The resulting period will be day-based, with the amount of days equal to the... more 5/24/2017 10:06:48 AM

people

Java main method not found error on Windows 10 even with correct main signature

I have a couple of Java files A.java and B.java that use a common jar file C.jar. B.java contains reference variables to the object of type A. B.java contains the main method I...
Jon Skeet
people
quotationmark

Am I making some mistake in my commands? Yes - you're not including anything apart from C.jar when trying to run. Use java -cp C.jar;. // Windows java -cp C.jar:. // Unix So that you're including the current directory (which is... more 5/24/2017 7:46:34 AM

people

how to convert optional parameter method to delegate in c#

i have a casting problem. public void Test(int a = 0) { } System.Action d = Test; this code works well in unity 5. but visual studio 2015 can't compile it. CS0123 No...
Jon Skeet
people
quotationmark

I'm surprised it works in Unity - it shouldn't. That sounds like a Mono compiler bug. The C# 5 specification isn't as clear on this as it should be, but from the draft of the upcoming ECMA C# 5 standard, from the clause on method group... more 5/24/2017 6:06:34 AM

people