Browsing 15711 questions and answers with Jon Skeet

Adding two periods on nodatime

Where listObjAge is a list with multiple periods; Period objTotalPeriod = listObjAge[0].period; for (int i = 1; i < listObjAge.Count; i++) { objTotalPeriod +=...
Jon Skeet
people
quotationmark

It sounds like you're looking for something to normalize the months and days (and weeks?). The existing Normalize method deals with everything from "days downwards" (e.g. hours) so you can use that to start with: public static Period... more 6/1/2017 4:07:27 PM

people

PerformanceCounter CPU usage value allways 0

For below Performance counter, I am always getting % Processor Time is 0, even my CPU shows 100% usage, what could be the reason? PerformanceCounter pc = new...
Jon Skeet
people
quotationmark

It's explained by the remarks in the NextValue() documentation: If the calculated value of a counter depends on two counter reads, the first read operation returns 0.0. Resetting the performance counter properties to specify a... more 5/31/2017 9:27:59 AM

people

Google Cloud API grammar

Using this code I've found on a youtube video (don't know if i'm able to post) : if (File.Exists("audio.raw")) { var speech = SpeechClient.Create(); var response =...
Jon Skeet
people
quotationmark

Assuming that you just want to add SpeechContext to your request, just add instances to the RecognitionConfig's SpeechContexts property: var context = new SpeechContext { Phrases = { "first", "second" } }; var config = new... more 5/31/2017 8:58:36 AM

people

Returning disposable object and getting CA2000 warning

I am trying to return XMLNodeReader to another function but getting CA2000 warning XmlNodeReader obj =new XmlNodeReader(section); return ser.method(obj); If I use the following...
Jon Skeet
people
quotationmark

Well we have no idea what ser.method does, but passing a disposed object into method seems like a bad idea to me. Basically, your "fix" is bad. There are three possibilities here (and probably others, but these are the main... more 5/31/2017 8:35:41 AM

people

Unable to parse String to Date type in iOS swift 3

I'm trying to parse String to date but getting nil value for some specific date. The parsing of 2017-04-21 09:00:00 Tis successfully, but getting nil value for string 2017-05-30...
Jon Skeet
people
quotationmark

You're using hh as the hours specifier. That's a 12-hour value, and "23" clearly falls outside that range. ("09" parses because it's in range.) Use HH instead: dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss" more 5/30/2017 1:42:52 PM

people

C# WebClient uploads file that is around twice as large as original

I am testing some file uploads using WebApi 2.0. I created a controller that has an upload method and I also created a console application to perform the upload. I am doing...
Jon Skeet
people
quotationmark

You shouldn't be using StreamReader and StreamWriter - those are for text, and your content isn't text. Just use Stream instead: private async Task ReadStreamAsync(HttpContext context, string filePath) { using (var input =... more 5/30/2017 1:01:47 PM

people

"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