The current status of System.Net.Http vs. Microsoft.Net.Http

This has been for a long time and continues to be confusing. I have seen such messaging myself but as of right now, it appears System.Net.Http is the correct choice, at least for .NET on the Windows platform and has no external dependencies. For .NET Core, I have used Microsoft.Net.Http although it does require Microsoft.BCL. … Read more

Why no AutoResetEventSlim in BCL?

ManualResetEvent and ManualResetEventSlim both are designed so that they remained signaled after calling. This is typically for a very different scenario than AutoResetEvent. AutoResetEvent immediately returns to the unsignaled state after usage, which is typically used for a different set of scenarios. From AutoResetEvents documentation: Typically, you use this class when threads need exclusive access … Read more

Why does List implement IReadOnlyList in .NET 4.5?

Because List<T> implements all of the necessary methods/properties/etc. (and then some) of IReadOnlyList<T>. An interface is a contract that says “I can do at least these things.” The documentation for IReadOnlyList<T> says it represents a read-only collection of elements. That’s right. There are no mutator methods in that interface. That’s what read-only means, right? IReadOnlyList<T> … Read more

Why is a Dictionary “not ordered”?

Well, for one thing it’s not clear whether you expect this to be insertion-order or key-order. For example, what would you expect the result to be if you wrote: var test = new Dictionary<int, string>(); test.Add(3, “three”); test.Add(2, “two”); test.Add(1, “one”); test.Add(0, “zero”); Console.WriteLine(test.ElementAt(0).Value); Would you expect “three” or “zero”? As it happens, I think … Read more

Why is a “bindingRedirect” added to the app.config file after adding the Microsoft.Bcl.Async package?

The assemblies Microsoft.Threading.Tasks and Microsoft.Threading.Tasks.Extensions are still referencing v1.5.11.0 of System.Runtime and System.Threading.Tasks. Without the bindingRedirect, the Microsoft.* assemblies would try to load an old version of the System.* assemblies, which would fail.

How to create multiple directories from a single full path in C#?

I would call Directory.CreateDirectory(@”C:\dir0\dir1\dir2\dir3\dir4\”). Contrary to popular belief, Directory.CreateDirectory will automatically create whichever parent directories do not exist. In MSDN’s words, Creates all directories and subdirectories as specified by path. If the entire path already exists, it will do nothing. (It won’t throw an exception)