The following exception types are too general to provide sufficient information to the user:
Throw Specific Exceptions
The following table shows parameters and which exceptions to throw when you validate the parameter, including the value parameter in the set accessor of a property:
Parameter Description Exception nullreferenceSystem.ArgumentNullException Outside the allowed range of values (such as an index for a collection or list) System.ArgumentOutOfRangeException Invalid enumvalueSystem.ComponentModel.InvalidEnumArgumentException Contains a format that does not meet the parameter specifications of a method (such as the format string for ToString(String))System.FormatException Otherwise invalid System.ArgumentException
This is just a spot to keep miscellaneous links. It also shows you what a geek I am.
Friday, March 30, 2018
Microsoft guidance on throwing exceptions
The rest of this post is a quote from this article at https://docs.microsoft.com/en-us/visualstudio/code-quality/ca2201-do-not-raise-reserved-exception-types:
Sunday, January 21, 2018
Git 2.16 and line endings
Git 2.16 introduces two new interesting options for dealing with line endings.
The first is the new
The first is the new
--ignore-cr-at-eol option to git diff, which ignores changes in line endings in a diff, which otherwise sometimes lead to it appear that the entire file has changed (which, in a sense, it has).git diff --cached --ignore-cr-at-eol
The second is the new --renormalize option to git add.
git add --renormalize .
To quote the man pages, git add --renormalize "is a new and safer way to record the fact that you are correcting the end-of-line convention and other "convert_to_git()" glitches in the in-repository data."
So the way to normalize line endings in a repository has been revised to the following:
echo "* text=auto" >.gitattributes
git add --renormalize .
git status # Show files that will be normalized
git commit -m "Introduce end-of-line normalization"
Note that the old way:
...
git read-tree --empty # Clean index, force re-scan of working directory
git add .
...
will cause Git to delete files from the repository that are included in .gitignore.
That might be a good thing for certain "undisciplined" repositories.
Friday, January 05, 2018
Easily building query strings in .NET
Instead of reinventing the wheel, try the following:
NameValueCollection queryString = System.Web.HttpUtility.ParseQueryString(string.Empty);
queryString["key1"] = "value1";
queryString["key2"] = "value2";
return queryString.ToString(); // Returns "key1=value1&key2=value2", all URL-encoded
Saturday, December 30, 2017
Be careful when using many HttpClient instances
Who knew? According to MSDN (emphasis added):
HttpClient is intended to be instantiated once and re-used throughout the life of an application. Instantiating an HttpClient class for every request will exhaust the number of sockets available under heavy loads.See more here: Disposable, Finalizers, and HttpClient
Wednesday, December 13, 2017
Cool JSON and SQL-related links found on a Hacker News post
https://quicktype.io/ – Parses sample JSON and creates code to serialize/deserialize it in several different languages.
https://github.com/rspeele/Rezoom.SQL – Rezoom.SQL is an F# ORM for SQL databases using type providers, so it will automatically pick up the schema on build. A HN commenter claimed it has better type support than any other ORM, a statement perhaps to be taken with a grain of salt.
https://github.com/ReactiveX/IxJS – Interactive Extensions for JavaScript (IxJS). IxJS is a set of libraries to compose synchronous and asynchronous collections and Array#extras style composition in JavaScript
https://github.com/rspeele/Rezoom.SQL – Rezoom.SQL is an F# ORM for SQL databases using type providers, so it will automatically pick up the schema on build. A HN commenter claimed it has better type support than any other ORM, a statement perhaps to be taken with a grain of salt.
https://github.com/ReactiveX/IxJS – Interactive Extensions for JavaScript (IxJS). IxJS is a set of libraries to compose synchronous and asynchronous collections and Array#extras style composition in JavaScript
Wednesday, November 22, 2017
Git line endings revisited and .gitignore
Git-scm.com revised their line ending fix-up instructions in a way that seems to remove ignored files from the repository.
Here are the new instructions:
Here are the new instructions:
echo "* text=auto" >.gitattributes
git read-tree --empty # Clean index, force re-scan of working directory
git add .
git status # Show files that will be normalized
git commit -m "Introduce end-of-line normalization"
Wednesday, September 20, 2017
.NET IsAssignableFrom
For some reason I have a mental block remembering which way .NET's
IsAssignableFrom() function works, so, using the excellent LINQPad and the following code snippet, I came up with the following results:typeof(BaseClass).IsAssignableFrom(typeof(DerivedClass)) // true
typeof(DerivedClass).IsAssignableFrom(typeof(BaseClass)) // false
Code:
void Main()
{
typeof(BaseClass).IsAssignableFrom(typeof(DerivedClass)).Dump("typeof(BaseClass).IsAssignableFrom(typeof(DerivedClass))");
typeof(DerivedClass).IsAssignableFrom(typeof(BaseClass)).Dump("typeof(DerivedClass).IsAssignableFrom(typeof(BaseClass))");
}
class BaseClass { }
class DerivedClass : BaseClass { }
Thursday, June 08, 2017
C# 6 String Interpolation Does Not Concatenate
Well, I learned something new today that's slightly disappointing. I had thought that C# 6 string interpolation concatenated strings or perhaps used the
Given this source code:
The resulting IL (compiled) code is the following (obtained using LINQPad):
Note the following two statements:
To compile the C# code and create IL code, I used Joe Albahari's excellent LINQPad program.
StringBuilder or some such under the hood. It turns out it merely creates a good, old-fashioned String.Format statement out of it.Given this source code:
The resulting IL (compiled) code is the following (obtained using LINQPad):
Note the following two statements:
ldstr "A{0}C"
call System.String.Format
These indicate that String.Format is being called with the familiar-looking format string "A{0}C".To compile the C# code and create IL code, I used Joe Albahari's excellent LINQPad program.
Wednesday, March 29, 2017
WebClient vs HttpClient vs HttpWebRequest
All the clients explained.
http://www.diogonunes.com/blog/webclient-vs-httpclient-vs-httpwebrequest/
To quote from the link:
http://www.diogonunes.com/blog/webclient-vs-httpclient-vs-httpwebrequest/
To quote from the link:
HttpWebRequestfor controlWebClientfor simplicity and brevityRestSharpfor both on non-.NET 4.5 environmentsHttpClientfor both + async features on .NET 4.5 environments
Friday, December 16, 2016
Shallow Copy an array in JavaScript
Who knew?
var copyOfArray = originalArray.slice();Apparently
Array.slice, if called with no parameters, returns a copy of the entire array. Kinda cool!
Wednesday, December 07, 2016
Formatting in ReSharper vs. formatting in Visual Studio
Interesting. Ctrl-K Ctrl-D reformats a file using Visual Studio rules, while Ctrl-Alt-Enter reformats a file using ReSharper rules.
Here's an example, using Visual Studio formatting (Ctrl-K Ctrl-D):
Here's an example, using Visual Studio formatting (Ctrl-K Ctrl-D):
var patient = new Patient { AccountNumber = accountNumber };
And the same code using ReSharper formatting (Ctrl-K Ctrl-F): var patient = new Patient {AccountNumber = accountNumber};
I would have thought that ReSharper would take over the Ctrl-K Ctrl-D and Ctrl-K Ctrl-F keyboard shortcuts, but it does not.
Saturday, November 26, 2016
Testing fonts for ambiguity
This is the string used by Visual Studio's font configuration that indicates whether a font is ambiguous or not for developers:
Tuesday, October 25, 2016
Setting Environment variables in ASP.NET Core
"Turns out environment variables for ASP.NET Core projects can be set without having to set environment variables for user or having to create multiple commands entries....
"This way you do not have to create special users for your pool or create extra commands entries inproject.json. Also, adding special commands for each environment breaks build once, deploy many times' as you will have to calldnu publishseparately for each environment, instead of publish once and deploying resulting artifact many times."
Wednesday, October 12, 2016
Monday, August 29, 2016
Git add non-whitespace changes revisited
There's a better version of what I blogged about here.
Source: http://stackoverflow.com/questions/3515597/add-only-non-whitespace-changes#comment61915463_7149602
Source: http://stackoverflow.com/questions/3515597/add-only-non-whitespace-changes#comment61915463_7149602
Wednesday, August 24, 2016
Visual Studio's most useful (and underused) tips
I discovered Map Mode for the scrollbar. I have seen people use that but always thought it was from a Visual Studio plugin.
Also, who knew you could compare files with Visual Studio?
Navigate to -- Ctrl+, -- is another discovery, as well as moving lines up and down with Alt-Up and Alt-Down.
Visual Studio's most useful (and underused) tips
Also, who knew you could compare files with Visual Studio?
Navigate to -- Ctrl+, -- is another discovery, as well as moving lines up and down with Alt-Up and Alt-Down.
Visual Studio's most useful (and underused) tips
Tuesday, July 05, 2016
GitTfs commands I use every day, round 2
I modified my TfsFetch.sh script to display the name of the current branch. This is to aid in situations where feature branches are being used.
Here's the current script:
Here's the current script:
Tuesday, May 31, 2016
Normalize line endings before removing ignored files
When using the scripts I have blogged about for normalizing line endings and removing ignored files, run the script to normalize line endings first before removing ignored files.
Thursday, May 26, 2016
The old 'TFS Repository can not be root and must start with "$/"' error
When using git-tfs to clone a repository using the bash shell, this error is common:
$ git tfs clone https://tfsserver/tfs/DefaultProjectCollection/ "$/path/to/tfs/project"
TFS repository can not be root and must start with "$/".
You may be able to resolve this problem.
The solution? Prepend MSYS_NO_PATHCONV=1 to the command, e.g.:$ MSYS_NO_PATHCONV=1 git tfs clone https://tfsserver/tfs/DefaultProjectCollection/ "$/path/to/tfs/project"
Initialized empty Git repository in C:/Projects/path/to/tfs/project/.git/
Fetching from TFS remote 'default'...
C6782 = 81584efc08348f7dc4c81297e4e82115789a1e3d
C6784 = 6a6a8bd55111286b24c7acd4825e4ef79030d693
C6863 = 60e8369f34b16a6123d7ed22bf60e59db46ee2e9
etc.
Friday, April 15, 2016
TestDisk - Partition Recovery and File Undelete
I wish I'd known about this a few months ago. I accidentally make a disk unbootable, but eventually, after many hours of struggle, I got it working again. This might have save me those many hours.
TestDisk - Partition Recovery and File Undelete
I found this reading the original Server Fault post on the huge data loss allegedly suffered by someone at a British web hosting company.
Linux command line mistake nukes web boss' biz • The Register
centos7 - Recovering from a rm -rf / - Server Fault
TestDisk - Partition Recovery and File Undelete
I found this reading the original Server Fault post on the huge data loss allegedly suffered by someone at a British web hosting company.
Linux command line mistake nukes web boss' biz • The Register
centos7 - Recovering from a rm -rf / - Server Fault