TestContext.WriteLine has

In test class I was using TestContext.WriteLine trying to output JSON string, I’ve got
System.FormatException : Input string was not in a correct format.
at System.Text.StringBuilder. AppendFormatHelper(IFormatProvider provider, String format, ParamsArray args)
at System.String.FormatHelper(IFormatProvider provider, String format, ParamsArray args)
at System.String.Format(IFormatProvider provider, String format, Object[] args)
at Microsoft.VisualStudio.TestPlatform.MSTestFramework.TestContextImplementation.WriteLine(String format, Object[] args)

Example of code that works for Debug.WriteLine, but not for TestContext.WriteLine is the following:

var msg = “{curly braces}”;

I found, that TestContext.WriteLine expects first parameter as a format string, that consider { and } as placeholder delimiters.

UPDATE: Simple workaround,  suggested in a comment by Steve Gilham


I had to write EscapeCurlyBraces extension

public static string EscapeCurlyBraces( this string message)
string ret = message.Replace( “{“, “{{” ).Replace(“}”, “}}”);
return ret;

and call
TestContext.WriteLine(msg.EscapeCurlyBraces() );
I’ve wrote a suggestion to MS Connect that it will be good to have separate overload TestContext.WriteLine(string msg); that doesn’t consider the parameter as format and doesn’t expect any additional parameters.

The file  https://github.com/MNF/CommonDotNetHelpers/blob/master/src/Strings/StringFormatExtensions.cs and corresponding unit tests https://github.com/MNF/CommonDotNetHelpers/blob/master/Tests/Strings/StringFormatExtensionsTests.cs are located on GitHub.

Pocket Favorites are not available when you off-line

I am using Pocket(previously known as Read It Later) and sometimes sent to support my suggestions.
Unfortunately they do not have convenient support forums(or uservoice sites), so I post my suggestions here to have them visible:

IPad Pocket Favorites are not available when you off-line. It shows message similar to Archives. For Archives it makes sense, but why favorites have this limitation?
Could you please allow to access Favorites list off-line.

The support person agreed that including the Favorites would be great approach to improving upon this feature.

He also ask to submit the request officially here: http://pocket.co/soPybA This helps the team prioritize most requested features we receive.

I don’t understand why email to support is not considered as official request. Anyway everyone who wants to suggest something to Pocket, should fill the boring form

#favorites, #pocket, #support

Globally replace obsolete NLog.WarnException using regular expression

I’ve updated NLog ver 2.0 to 4.3.5. After this I’ve noticed a compiler warning that 
WarnException(msg,exc) is obsolete and should be replaced by Warn(exc,msg)

It could be globally replaced using regular expressions 


Warn($2, $1);

See saved regex in https://regex101.com/r/kL8cR4/1

#nlog, #regex

FromToRange generic class

Quite often you need to return from method 2 values that describe the range, e.g. From/To or Min/Max. You could use standard MS classes Pair or Tuple https://msdn.microsoft.com/en-us/library/system.tuple.aspx. However the names of properties are not describe the meaning of the values.
So I am using own class FromToRange. It is done similar to Pair(from http://blog.o-x-t.com/2007/07/16/generic-pair-net-class/)

/// similar to Pair(from http://blog.o-x-t.com/2007/07/16/generic-pair-net-class/"
///See also  DateTimeRange ( https://github.com/MNF/CommonDotNetHelpers/blob/master/src/Dates/DateTimeRange.cs)

public class FromToRange
public T From { get; set; }
public T To { get; set; }

public FromToRange()

public FromToRange(T from, T to)
this.From = from;
this.To = to;
public override string ToString()
string sRet = String.Format("From {0} to {1}", From, To);
return sRet;
public override bool Equals(object obj)
if (this == obj) return true;
FromToRange pair = obj as FromToRange;
if (pair == null) return false;
return Equals(From, pair.From) && Equals(To, pair.To);

public override int GetHashCode()
return (From != null ? From.GetHashCode() : 0) + 29 * (To != null ? To.GetHashCode() : 0);


Changes in .psproj do not cause re-build

With PostSharp I  am using .psproj files 
If I did changes in .psproj file,  simple build didn’t recognize that the project has been changed and skipped the project.

 I had to manually Rebuild the project.

The fix is to change build type of the .psproj file from none to ‘content’ ( may be other types also will work)

#build, #postsharp

GMail considered

I’ve created a new email account @gmail.com to communicate with members of Russian Bards Songs Club . When I sent the first email to 15 people, it was rejected with the message:

Delivery to the following recipient failed permanently:

Technical details of permanent failure:

Message rejected.  See https://support.google.com/mail/answer/69585 for more information.

I’ve sent the same email to a single person and it was successful. I’ve wrote a small program to  vary some details and number of addressees, but the emails were continue to be blocked. I wasn’t able to send the email even to a single recipient. It means that gmail has more strict anti-spam criteria for smtp  clients then for gmail senders.

The email I was trying to send was written in Russian with some words in English and contained a few links. I didn’t know, what else make my email suspicious and submitted a question to Google. But they normally do not respond.

I’ve decided to test smaller emails to identify if particular part of content flags the email as spam. After a few attempts I found, that the trouble caused  the phrase

If you don’t want to receive more emails from us, please reply with the word ‘Unsubscribe’ in the subject.

I’ve seen multiple recommendations to include unsubscribe information in emails to bypass anti-spam filters. It seems that too many spammers started to add such sentences, that Google now consider it as a spam indication.

Maybe  they didn’t like that I have an instruction to unsubscribe via email instead of providing link to website.

For now, I removed the sentence from the email and finally was able to send it.


Couple weeks later I added a message “If you don’t want to receive emails any more, click on this link”( in Russian), but the actual URL contained the word “unsubscribe”. I’ve sent emails to 3 big groups of people(about 100 each). Two of them were sent successfully, but one was rejected(actually the first one).
I split the failed group in three smaller ones, and tried to send them. They were rejected again.

Additional annoyance was that “delivery failed” notifications were received slowly within 5 minutes, and initially I had an impression that some emails succeeded, and only some were rejected. However according to timestamp all emails were rejected at the same time.

Then I renamed the target URL to not use “unsubscribe” word, updated the link in email signature, and was able to send emails successfully.

RegEx for credit-card-numbers with spaces/dash delimiters

I’ve used regular expressions from http://www.richardsramblings.com/regex/credit-card-numbers/ that supports delimiters spaces/dashes, e.g. “3714-496353-98431” or “3714 496353 98431”. (by the way I’ve added Diner’s Club pattern  ((?:30[0-59]|(?:(?:36|38|39)[0-9]))[0-9]{11}) even they are obsolete now)
Unfortunately they use backreferences \1 in individual credit card matches, which doesn’t work if I use alternatives (Visa)|(Master)|(Amex).
I replaced numbered capturing groups with named capturing groups http://www.regular-expressions.info/named.html .
Javascript and .Net format for named groups are different. I’ve done initially using ?P syntax
(?<!\d)(?:(4\d{3}((?P[\ \-]?)(?:\d{4}(?P=DelimVI)){2}\d(?:\d{3})?)|(5([1-5]\d{2})(?P[\ \-]?)\d{4}(?P=DelimMC)\d{4}(?P=DelimMC)\d{4})|(3[47]\d\d(?P[\ \-]?)\d{6}(?P=DelimAX))\d{5}))(?!\d)
and then had to translate to .Net syntax
(?<!\d)(?:(4\d{3}(?’DelimVI'[\ \-]?)(?:\d{4}\k’DelimVI’){2}\d(?:\d{3})?)|(5([1-5]\d{2})(?’DelimMC'[\ \-]?)\d{4}\k’DelimMC’\d{4}\k’DelimMC’\d{4})|(3[47]\d\d(?’DelimAX’)[\ \-]?)\d{6}\k’DelimAX’\d{5}))(?!\d)
I’ve tested Javascript syntax in RegEx101 (see https://regex101.com/r/dX5zJ4/3), but for .Net I had to use http://regexstorm.net/tester and they are not comparable-RegEx101 is significantly user friendlier.

#credit-cards, #regex, #regular-expressions