EDIT: This is now part of MoreLINQ.
What you need is a “distinct-by” effectively. I don’t believe it’s part of LINQ as it stands, although it’s fairly easy to write:
public static class EnumerableExtensions
public static IEnumerable<TSource> DistinctBy<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
HashSet<TKey> seenKeys = new HashSet<TKey>();
foreach (TSource element in source)
yield return element;
Source: c# – LINQ’s Distinct() on a particular property – Stack Overflow
Got this error when building a .NET framework (version 4.6.1) solution containing multiple projects:
The type 'HttpResponseMessage' exists in both 'System.Net.Http, Version=188.8.131.52, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' and 'System.Net.Http, Version=184.108.40.206, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
Install System.Net.Http version 4.0.0 as nuget package to the “failing project”.
Added this to the “failing” project app.config file:
<!-- other dependentAssembly bindings here -->
<assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-220.127.116.11" newVersion="18.104.22.168" />
Updated the “failing” projects .csproj file like this:
Removed this line or similar for System.Net.Http:
<!--<Reference Include="System.Net.Http, Version=22.214.171.124, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />-->
Added “hintpath” with projects relative path to the nuget packages.
In my example its 3 level up and then down (..\..\..) you might need to adjust to your projects folderstructure.
<Reference Include="System.Net.Http, Version=4.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
// A class that contains MSTest unit tests. (Required)
public class YourUnitTests
public static void AssemblyInit(TestContext context)
// Executes once before the test run. (Optional)
public static void TestFixtureSetup(TestContext context)
// Executes once for the test class. (Optional)
public void Setup()
// Runs before each test. (Optional)
public static void AssemblyCleanup()
// Executes once after the test run. (Optional)
public static void TestFixtureTearDown()
// Runs once after all tests in this class are executed. (Optional)
// Not guaranteed that it executes instantly after all tests from the class.
public void TearDown()
// Runs after each test. (Optional)
// Mark that this is a unit test method. (Required)
public void YouTestMethod()
// Your test code goes here.
Source: Most Complete MSTest Unit Testing Framework Cheat Sheet
I’m thrilled to announce that Blazor WebAssembly is now officially released. This is a fully-featured and supported release of Blazor WebAssembly that is ready for production use. Full stack web development with .NET is now here!
Source: Blazor WebAssembly 3.2.0 now available | ASP.NET Blog
Application logs are the most useful data available for detecting and solving a wide range of production issues and outages. Seq makes it easier to pinpoint the events and patterns in application behavior that show your system is working correctly — or why it isn’t.
Seq is built for modern structured logging with message templates. Rather than waste time and effort trying to extract data from plain-text logs with fragile log parsing, the properties associated with each log event are captured and sent to Seq in a clean JSON format. Message templates are supported natively by ASP.NET Core, Serilog, NLog, and many other libraries, so your application can use the best available diagnostic logging for your platform.
Seq accepts logs via HTTP, GELF, custom inputs, and the
seqcli command-line client, with plug-ins or integrations available for .NET Core, Java, Node.js, Python, Ruby, Go, Docker, message queues, and many other technologies.
Free for development and single-user deployment
The free single-user license included with Seq lets developers run Seq locally, and now supports individual developers in production.
Source: Seq — centralized structured logs for .NET, Java, Node.js
Strip HTML using HtmlAgilityPack
public static string StripHtml(this string value)
HtmlDocument htmlDoc = new HtmlDocument();
if (htmlDoc == null)
Source: Strip HTML using HtmlAgilityPack
After adding a new 3rd party reference to a project and then building for Release configuration I got this error (not present when in debug build):
Error Could not load file or assembly ‘x’ or one of its dependencies. The system cannot find the file specified. SGEN
Here is a solution that worked for me:
If you are having this problem while building your VS.NET project in Release mode here is the solution: Go to the project properties and click on the Build tab and set the value of the “Generate Serialization Assembly” dropdown to “Off”. Sgen.exe is “The XML Serializer Generator creates an XML serialization assembly for types in a specified assembly in order to improve the startup performance of a XmlSerializer when it serializes or deserializes objects of the specified types.” (MSDN)
Source: c# – sgen.exe fails during build – Stack Overflow
Measure which methods takes longest time (cpu analysis) or how the memory is used in a .NET application with the built-in Performance Profiler in Visual Studio 2017
Logging information in .NET, or really in any production application, is invaluable. In many cases, developers don’t have direct access to the production environment to debug issues. Good quality logs are the difference between solving problems like Sherlock Holmes and stumbling upon solutions like Inspector Jacques Clouseau. As you can imagine, we’re pretty big on logging here at Stackify, and we’ve written quite a few other blog posts on .NET logging frameworks. I’d encourage you to try out the search and read a few of our previous articles.
Source: NLog vs log4net vs Serilog: Compare .NET Logging Frameworks