Browsing 7239 questions and answers with Jon Skeet

Multi line string literal format gives me error Input string was not in a correct format

I have the following variable: var setting = $@"worker_processes {{0}}; worker_rlimit_nofile {{1}}; error_log logs/{{2}} {{3}}; events {{ ...
Jon Skeet
people
quotationmark

It's unclear exactly what's going on as there's version confusion, but I suspect you just want: var setting = @"worker_processes {0}; worker_rlimit_nofile {1}; error_log logs/{2} {3}; events {{ ... more 9/4/2015 4:08:40 PM

people

System.Net.WebClient exception calling UploadValues with encoded string containing single quote

I get the following exception when calling UploadValues with an encoded string containing a single quote: An exception of type 'System.Net.WebException' occurred in...
Jon Skeet
people
quotationmark

You're using HtmlEncode, but the value should be URL-encoded, as it will be uploaded as application/www-form-urlencoded content. Try using HttpUtility.UrlEncode instead. more 9/4/2015 2:37:39 PM

people

Is an EF query's null check performed on the db or webserver?

I'm using EF and Sql Server (CE). I'm trying to ensure as much as possible is run on the db. Consider this: var data = getSomeEntities() .OrderBy(a => a.Date) .Select(a...
Jon Skeet
people
quotationmark

That's performed in the database - if you add appropriate logging, you should see the appropriate SQL to get the right result. In C# 6 you can just use Ref = a.CustomerProfile?.Ref more 9/4/2015 12:15:38 PM

people

XML and JSON result showing different result for common class in WEB API

In my WEB API i get the result in XML and Json. it works fine. But, When I collect data from DB some records is empty. While on conversion to xml or json, the result is...
Jon Skeet
people
quotationmark

I think you probably want to use the XmlElementAttribute.IsNullable property: public class items { [JsonProperty(PropertyName = "frequency")] [XmlElement(ElementName = "frequency", IsNullable = true)] public string Frequency... more 9/4/2015 11:46:39 AM

people

How to map tinyint to c# byte using entityframework code first migration

I am trying to map tinyint column to byte property in c#How to achieve this efficiently. I want to store the values null, 0 and 1 to the database column. Please find below my...
Jon Skeet
people
quotationmark

There's no need to go via a string at all. Just use the explicit conversions: [Column("AuthorisationStatus")] public byte AuthorisationStatusByte { get { return (byte) AuthorisationStatus; } set { AuthorisationStatus = (TriState)... more 9/4/2015 10:11:12 AM

people

Is it possible using an "AND" operator for "ConditionalAttribute"?

Is it possible to use anAND-operator like this [Conditional("DEBUG")&& Conditional("ANNA")] ? Using an OR-operator works: [Conditional("DEBUG"),Conditional("ANNA")].
Jon Skeet
people
quotationmark

No, that isn't supported as far as I'm aware. I would suggest just defining a third symbol in that case. (I'd also try to do all of this really, really sparingly...) more 9/4/2015 9:22:07 AM

people

Retrieve list of possible DateTime formats from string value

I would like to be able to parse date and/or date-time values from a csv file and get their DateTime format (or in Excel terms NumberFormat). For example I would like to pass...
Jon Skeet
people
quotationmark

There's no such thing as "all possible date formats". A format of "'Year:' yyyy 'Month:' MM 'Day:' dd" would be valid, but highly unusual, for example. There's nothing that Noda Time supplies here that would be particularly helpful. I... more 9/4/2015 6:03:33 AM

people

Invoking setText() through reflection only if an object has an specific annotaion

I'm trying to set the text of a number of different components (JButton, JLabel, etc...) through reflection. I'm also using annotations in the fields that I want to change later...
Jon Skeet
people
quotationmark

You're trying to call the method on the Field - whereas you actually want to call it on the value of the field within your object. You want: Method method = field.getType().getMethod("setText", String.class); Object target =... more 9/4/2015 5:54:16 AM

people

String created from an array keeps returning null's

String[] n = new String[8]; String name = n[0] + n[1] + n[2] + n[3] + n[4] + n[5] + n[6] + n[7]; for(int x = 0; x < 8; x++) { int h = 97; char j = (char) h; n[x]...
Jon Skeet
people
quotationmark

You're concatenating the values in the array and assigning the result to name before you modify any of the values within the array... i.e. when every element of the array is null. Just move this line: String name = n[0] + n[1] + n[2] +... more 9/3/2015 9:58:10 PM

people

Code stops working in the middle of process with no errors

I have a function : public bool urlExists(string url) { try { HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest; ...
Jon Skeet
people
quotationmark

You're not disposing of your responses, so you're never returning the connections to the connection pool - if you're fetching multiple images from the same host, the connection pool is preventing you from opening more connections to that... more 9/3/2015 9:18:43 PM

people