Reference a .NET Core Library in a .NET 4.6 project

This can now be done with .Net Core RC2. Here is how: Ensure your .Net RC2 projects’ project.json is configured to include the relevant .net framework. For example this section references .Net 4.51 which can be reference by any of the frameworks equal or above this version: Example: “frameworks”: { “net451”: { }, “netstandard1.5”: { …

Read more

Finding out what exceptions a method might throw in C#

.NET does not have enforced (“checked”) exceptions like java. The intellisense might show this information, if the developer has added a /// <exception…/> block – but ultimately more exceptions can happen than you expect (OutOfMemoryException, ThreadAbortException, TypeLoadException, etc can all happen fairly unpredictably). In general, you should have an idea of what things are likely …

Read more

Why Tuple’s items are ReadOnly?

Tuples originated in functional programming. In (purely) functional programming, everything is immutable by design – a certain variable only has a single definition at all times, as in mathematics. The .NET designers wisely followed the same principle when integrating the functional style into C#/.NET, despite it ultimately being a primarily imperative (hybrid?) language. Note: Though …

Read more

What is really a Principal in .NET?

When authorizing access to a resource or the ability to run some code, it is not sufficient merely to know which user is authorizing the action, but under what role they are authorizing it. Think of this as being roughly equivalent to when you elevate a shell: the shell is now running under a different …

Read more

WebClient Unicode – Which UTF8?

They’re identical. UTF8Encoding inherits Encoding. Therefore, you can access all of the static members declared by Encoding through the UTF8Encoding qualifier. In fact, you can even write ASCIIEncoding.UTF8, and it will still work. It will compile to identical IL, even in debug mode. I would recommend using Encoding.UTF8, as it shows what’s going on more …

Read more

Finding property differences between two C# objects

IComparable is for ordering comparisons. Either use IEquatable instead, or just use the static System.Object.Equals method. The latter has the benefit of also working if the object is not a primitive type but still defines its own equality comparison by overriding Equals. object originalValue = property.GetValue(originalObject, null); object newValue = property.GetValue(changedObject, null); if (!object.Equals(originalValue, newValue)) …

Read more