<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>.NET on InternetException</title><link>https://internetexception.com/categories/.net/</link><description>Recent content in .NET on InternetException</description><generator>Hugo</generator><language>en-us</language><lastBuildDate>Fri, 31 Oct 2025 09:49:42 +0100</lastBuildDate><atom:link href="https://internetexception.com/categories/.net/index.xml" rel="self" type="application/rss+xml"/><item><title>Enhancing your .NET API with query language</title><link>https://internetexception.com/2025/10/30/enhancing-your-net-api-with-query-language/</link><pubDate>Thu, 30 Oct 2025 21:14:03 +0100</pubDate><guid>https://internetexception.com/2025/10/30/enhancing-your-net-api-with-query-language/</guid><description>&lt;p&gt;What is query language? SQL is Structured Query Language and you use it to query your database for data you are interested in. It does not have to do anything with your API. If you ever were working with big XML files you probably used XQuery or XPath, query languages designed to XML for data. There are specialized languages that are designed to work with APIs to query &lt;strong&gt;them&lt;/strong&gt; for data. For example, you probably heard about GraphQL or even used it when you were working with some API.&lt;/p&gt;</description></item><item><title>HLinq design</title><link>https://internetexception.com/2025/10/28/hlinq-design/</link><pubDate>Tue, 28 Oct 2025 21:14:55 +0100</pubDate><guid>https://internetexception.com/2025/10/28/hlinq-design/</guid><description>&lt;h2 id="a-bit-of-history"&gt;A bit of history&lt;/h2&gt;&#10;&lt;p&gt;I remember the day when I started writing the HLinq query language. It was weekend and I was experimenting with writing Single endpoints for &lt;a href="https://internetexception.com/2013/02/07/why-i-dont-like-python-anymore/" data-type="post" data-id="228"&gt;Hamster Wheel.&lt;/a&gt; Single endpoints were almost done and next step was to write List endpoint. This would allow to get list of records of specific type. After I got single GET returns correct data for chosen record id, list should not be hard to implement. Then just create, update and delete. Basic CRUD API in Hamster Wheel would be finished. I was thrilled that I actually was able to do such thing.&lt;/p&gt;</description></item><item><title>Disable Xunit Test on specific OS</title><link>https://internetexception.com/2025/10/04/disable-xunit-test-on-specific-os/</link><pubDate>Sat, 04 Oct 2025 22:51:15 +0200</pubDate><guid>https://internetexception.com/2025/10/04/disable-xunit-test-on-specific-os/</guid><description>&lt;p&gt;Lately I was having a problem with some of my tests causing problems for other developers on the project I am working on. They were using Windows for their development while I am using Debian for my work. The application that was being tested was not designed for non Unix system - now rarely anybody is hosting they production code on Windows Server - everybody is using Unix for .net.&lt;/p&gt;</description></item><item><title>Writing a simple C# source code generator with Fluent API</title><link>https://internetexception.com/2025/10/02/writing-simple-c-source-code-generator/</link><pubDate>Thu, 02 Oct 2025 16:05:39 +0200</pubDate><guid>https://internetexception.com/2025/10/02/writing-simple-c-source-code-generator/</guid><description>&lt;h1 id="introduction"&gt;Introduction&lt;/h1&gt;&#10;&lt;p&gt;Usually in .NET world when you want to write generic code you use generic method or classes. But sometimes it is still not enough when you want to automate some things. I.e. you want to dynamically register in &lt;a href="https://learn.microsoft.com/en-us/aspnet/core/fundamentals/dependency-injection?view=aspnetcore-9.0" target="_blank" rel="noopener noreferrer"&gt;DI&lt;/a&gt;&#10; all the classes that implements some interface. Probably, in this case, you would do something like that:&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-csharp" data-lang="csharp"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;implementations&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;typeof&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;MyClass&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;Assembly&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Types&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Where&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;GetInterfaces&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="n"&gt;Any&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="p"&gt;==&lt;/span&gt; &lt;span class="k"&gt;typeof&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;IMyInterface&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;foreach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;implementation&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;implementations&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;{&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;services&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;AddScoped&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;IMyInterface&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;(&lt;/span&gt;&lt;span class="n"&gt;implementation&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;}&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;And it would be completely fine. Even if Reflection is pretty slow, your application would not be getting significantly slower because of that. Certainly you would not notice the slow down.&lt;/p&gt;</description></item><item><title>HamsterWheel.FluentCodeGenerators is out</title><link>https://internetexception.com/2025/10/01/hamsterwheel-fluentcodegenerators-is-out/</link><pubDate>Wed, 01 Oct 2025 16:58:21 +0200</pubDate><guid>https://internetexception.com/2025/10/01/hamsterwheel-fluentcodegenerators-is-out/</guid><description>&lt;p&gt;I released today first new Nuget package connected to my new project that I am working on for sometime: dynamically configurable, zero-downtime API, with low-code flows to write small pieces of logic - &lt;a href="https://internetexception.com/why-hamster-wheel/" data-type="page" data-id="666"&gt;Hamster Wheel&lt;/a&gt;.&lt;br&gt;&#10;&lt;br&gt;&#10;System heavily relies on dynamic source code generation. For that I wrote&lt;br&gt;&#10;&lt;a href="https://www.nuget.org/packages/HamsterWheel.FluentCodeGenerators" target="_blank" rel="noopener noreferrer"&gt;https://www.nuget.org/packages/HamsterWheel.FluentCodeGenerators&lt;/a&gt;&#10; and &lt;a href="https://www.nuget.org/packages/HamsterWheel.FluentCodeGenerators.Abstractions" target="_blank" rel="noopener noreferrer"&gt;https://www.nuget.org/packages/HamsterWheel.FluentCodeGenerators.Abstractions&lt;/a&gt;&#10;&lt;br&gt;&#10;small package that helps with writing C# incremental source code generators for Roslyn compiler.&lt;br&gt;&#10;&lt;br&gt;&#10;Original Roslyn APIs are a bit hard to use so this package helps with that. Also it helps with:&lt;br&gt;&#10;\&lt;/p&gt;</description></item><item><title>.NET/C# interview questions</title><link>https://internetexception.com/2022/10/26/net-c-interview-questions/</link><pubDate>Wed, 26 Oct 2022 10:21:52 +0200</pubDate><guid>https://internetexception.com/2022/10/26/net-c-interview-questions/</guid><description>&lt;ul&gt;&#10;&lt;li&gt;&#10;&lt;p&gt;&lt;a href="https://internetexception.com/2022/10/18/idisposable-interface-pattern/" data-type="URL" data-id="/2022/10/18/idisposable-interface-pattern/"&gt;&lt;code&gt;IDisposable&lt;/code&gt;&lt;/a&gt;&lt;/p&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;&lt;a href="https://internetexception.com/2022/10/18/supressfinalize-in-idisposable-interface/" data-type="URL" data-id="/2022/10/18/supressfinalize-in-idisposable-interface/"&gt;&lt;code&gt;SupressFinalize&lt;/code&gt; in &lt;code&gt;IDisposable&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;/li&gt;&#10;&lt;li&gt;&#10;&lt;p&gt;&lt;a href="https://internetexception.com/2022/10/19/asynchronous-programming-in-net/" data-type="URL" data-id="/2022/10/19/asynchronous-programming-in-net/"&gt;Asynchronous programming in .NET&lt;/a&gt;&lt;/p&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;&lt;a href="https://internetexception.com/2022/10/19/async-await-in-c/" data-type="post" data-id="491"&gt;&lt;code&gt;async&lt;/code&gt;/&lt;code&gt;await&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;!-- --&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;&lt;a href="https://internetexception.com/2022/10/19/avoid-deadlock-with-asynchronous-methods/"&gt;Avoid deadlock with &lt;code&gt;async&lt;/code&gt;/&lt;code&gt;await&lt;/code&gt;&lt;/a&gt;&#10;&lt;/li&gt;&#10;&lt;li&gt;&lt;a href="http://2022/10/19/does-async-await-creates-new-thread/" target="_blank" rel="noopener noreferrer"&gt;Does &lt;code&gt;async&lt;/code&gt;/&lt;code&gt;await&lt;/code&gt; creates new thread?&lt;/a&gt;&#10;&lt;/li&gt;&#10;&lt;li&gt;&lt;a href="https://internetexception.com/2022/10/19/cpu-bound-vs-i-o-bound/"&gt;CPU bound vs I/O bound tasks&lt;/a&gt;&#10;&lt;/li&gt;&#10;&lt;li&gt;&lt;a href="https://internetexception.com/2022/10/19/what-is-synchronizationcontext-in-net/"&gt;SynchronizationContext&lt;/a&gt;&#10;&lt;/li&gt;&#10;&lt;li&gt;&lt;a href="https://internetexception.com/2022/10/19/thread-vs-task-in-net/"&gt;Threads/tasks&lt;/a&gt;&#10;&lt;/li&gt;&#10;&lt;li&gt;&lt;a href="https://internetexception.com/2022/10/19/locking-in-net/" data-type="URL" data-id="/2022/10/19/locking-in-net/"&gt;locking in .NET&lt;/a&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;&lt;a href="https://internetexception.com/2022/10/19/locking-with-integer/" data-type="post" data-id="513"&gt;locking with integer&lt;/a&gt;&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;/li&gt;&#10;&lt;li&gt;&lt;a href="https://internetexception.com/2022/10/19/task-parallel-library-tpl/" data-type="URL" data-id="/2022/10/19/task-parallel-library-tpl/"&gt;TPL&lt;/a&gt;&lt;/li&gt;&#10;&lt;li&gt;&lt;a href="https://internetexception.com/2022/10/19/threadpool/" data-type="URL" data-id="/2022/10/19/threadpool/"&gt;ThreadPool&lt;/a&gt;&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;/li&gt;&#10;&lt;li&gt;&#10;&lt;p&gt;&lt;a href="https://internetexception.com/2022/10/19/net-type-system/" data-type="URL" data-id="/2022/10/19/net-type-system/"&gt;Type system&lt;/a&gt;&lt;/p&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;&lt;a href="https://internetexception.com/2022/10/19/reference-types-vs-value-types/" data-type="URL" data-id="/2022/10/19/reference-types-vs-value-types/"&gt;Reference types vs value types&lt;/a&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;&lt;a href="https://internetexception.com/2022/10/19/value-types-as-fields-in-objects/" data-type="URL" data-id="/2022/10/19/value-types-as-fields-in-objects/"&gt;value types as fields in objects&lt;/a&gt;&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;!-- --&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;&lt;a href="https://internetexception.com/2022/10/19/what-type-can-not-be-object-field/"&gt;What kind of types cannot be object field?&lt;/a&gt;&#10;&lt;/li&gt;&#10;&lt;li&gt;&lt;a href="https://internetexception.com/2022/10/19/ref-struct-types/" data-type="URL" data-id="/2022/10/19/ref-struct-types/"&gt;&lt;code&gt;ref struct&lt;/code&gt; types&lt;/a&gt;&lt;/li&gt;&#10;&lt;li&gt;&lt;a href="https://internetexception.com/2022/10/19/strings-in-net/" data-type="post" data-id="535"&gt;Strings in .NET&lt;/a&gt;&lt;/li&gt;&#10;&lt;li&gt;&lt;a href="https://internetexception.com/2022/10/19/data-structures-in-net/" data-type="post" data-id="537"&gt;Data Structures&lt;/a&gt;&lt;/li&gt;&#10;&lt;li&gt;&lt;a href="https://internetexception.com/2022/10/19/net-generics/" data-type="URL" data-id="/2022/10/19/net-generics/"&gt;Generics&lt;/a&gt;&lt;/li&gt;&#10;&lt;li&gt;&lt;a href="https://internetexception.com/2022/10/19/covariance-and-contravariance/" data-type="post" data-id="541"&gt;Covariance and Contravariance&lt;/a&gt;&lt;/li&gt;&#10;&lt;li&gt;&lt;a href="https://internetexception.com/2022/10/25/equals-and-gethashcode/" data-type="post" data-id="587"&gt;Equals and GetHashCode&lt;/a&gt;&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;/li&gt;&#10;&lt;li&gt;&#10;&lt;p&gt;&lt;a href="https://internetexception.com/2022/10/19/garbage-collector/" data-type="post" data-id="545"&gt;Garbage Collector&lt;/a&gt;&lt;/p&gt;</description></item><item><title>Equals and GetHashCode</title><link>https://internetexception.com/2022/10/25/equals-and-gethashcode/</link><pubDate>Tue, 25 Oct 2022 16:36:49 +0200</pubDate><guid>https://internetexception.com/2022/10/25/equals-and-gethashcode/</guid><description>&lt;p&gt;Custom implementation is usually only necessary if default, reference equality is not enough. In example:&lt;/p&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;entities value based equality&lt;/li&gt;&#10;&lt;li&gt;value equality of deserialized objects&lt;/li&gt;&#10;&lt;li&gt;custom comparisons based on other criterias&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-csharp" data-lang="csharp"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ImaginaryNumber&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;IEquatable&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;ImaginaryNumber&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;{&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="n"&gt;RealNumber&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;get&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;set&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="n"&gt;ImaginaryUnit&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;get&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;set&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;override&lt;/span&gt; &lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="n"&gt;Equals&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;object&lt;/span&gt; &lt;span class="n"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="p"&gt;{&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;Equals&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;obj&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;ImaginaryNumber&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="p"&gt;}&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="n"&gt;Equals&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ImaginaryNumber&lt;/span&gt; &lt;span class="n"&gt;other&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="p"&gt;{&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;other&lt;/span&gt; &lt;span class="p"&gt;!=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt; &lt;span class="p"&gt;&amp;amp;&amp;amp;&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;RealNumber&lt;/span&gt; &lt;span class="p"&gt;==&lt;/span&gt; &lt;span class="n"&gt;other&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;RealNumber&lt;/span&gt; &lt;span class="p"&gt;&amp;amp;&amp;amp;&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;ImaginaryUnit&lt;/span&gt; &lt;span class="p"&gt;==&lt;/span&gt; &lt;span class="n"&gt;other&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ImaginaryUnit&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="p"&gt;}&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;override&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;GetHashCode&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="p"&gt;{&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;HashCode&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Combine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;RealNumber&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ImaginaryUnit&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="p"&gt;}&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;}&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;</description></item><item><title>Difference between Controller and ControllerBase</title><link>https://internetexception.com/2022/10/25/difference-between-controller-and-controllerbase/</link><pubDate>Tue, 25 Oct 2022 16:28:23 +0200</pubDate><guid>https://internetexception.com/2022/10/25/difference-between-controller-and-controllerbase/</guid><description>&lt;ul&gt;&#10;&lt;li&gt;&lt;code&gt;Controller&lt;/code&gt; type inherits from &lt;code&gt;ControllerBase&lt;/code&gt; and have Views support&lt;/li&gt;&#10;&lt;li&gt;&lt;code&gt;ControllerBase&lt;/code&gt; type is better suited for APIs&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p&gt;Further read:&lt;/p&gt;&#10;&lt;p&gt;&lt;a href="https://learn.microsoft.com/en-us/aspnet/core/web-api/?view=aspnetcore-6.0" target="_blank" rel="noopener noreferrer"&gt;https://learn.microsoft.com/en-us/aspnet/core/web-api/?view=aspnetcore-6.0&lt;/a&gt;&#10;&lt;/p&gt;</description></item><item><title>Kestrel</title><link>https://internetexception.com/2022/10/25/kestrel/</link><pubDate>Tue, 25 Oct 2022 15:56:40 +0200</pubDate><guid>https://internetexception.com/2022/10/25/kestrel/</guid><description>&lt;ul&gt;&#10;&lt;li&gt;default application server for .net&lt;/li&gt;&#10;&lt;li&gt;cross platform&lt;/li&gt;&#10;&lt;li&gt;best performance and memory utilization&lt;/li&gt;&#10;&lt;li&gt;may not have some advanced features of HTTP.sys on Windows&lt;/li&gt;&#10;&lt;li&gt;may be used with proxy server or as internet facing server&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p&gt;Further read:&lt;/p&gt;&#10;&lt;p&gt;&lt;a href="https://learn.microsoft.com/en-us/aspnet/core/fundamentals/servers/kestrel?view=aspnetcore-6.0" target="_blank" rel="noopener noreferrer"&gt;https://learn.microsoft.com/en-us/aspnet/core/fundamentals/servers/kestrel?view=aspnetcore-6.0&lt;/a&gt;&#10;&lt;/p&gt;</description></item><item><title>ASP.NET Core controller level exception handling</title><link>https://internetexception.com/2022/10/25/asp-net-core-controller-level-exception-handling/</link><pubDate>Tue, 25 Oct 2022 15:53:52 +0200</pubDate><guid>https://internetexception.com/2022/10/25/asp-net-core-controller-level-exception-handling/</guid><description>&lt;p&gt;To handle exceptions on Controller/Action level Exception Filters are used.&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-csharp" data-lang="csharp"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="na"&gt;[TypeFilter(typeof(SampleExceptionFilter))]&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ExceptionController&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Controller&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Exception Filters are implemented using &lt;code&gt;IExceptionFilter&lt;/code&gt; with &lt;code&gt;OnExcetion&lt;/code&gt; method override to handle exceptions.&lt;/p&gt;&#10;&lt;p&gt;Exception Filters can be applied to Controller and Action level.&lt;/p&gt;&#10;&lt;p&gt;Further read:&lt;/p&gt;&#10;&lt;p&gt;&lt;a href="https://learn.microsoft.com/en-us/aspnet/core/mvc/controllers/filters?view=aspnetcore-7.0#exception-filters" target="_blank" rel="noopener noreferrer"&gt;https://learn.microsoft.com/en-us/aspnet/core/mvc/controllers/filters?view=aspnetcore-7.0#exception-filters&lt;/a&gt;&#10;&lt;/p&gt;&#10;&lt;p&gt;&lt;a href="https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.mvc.filters.iexceptionfilter?view=aspnetcore-7.0" target="_blank" rel="noopener noreferrer"&gt;https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.mvc.filters.iexceptionfilter?view=aspnetcore-7.0&lt;/a&gt;&#10;&lt;/p&gt;</description></item><item><title>ASP.NET Core global exception handling</title><link>https://internetexception.com/2022/10/25/asp-net-core-global-exception-handling/</link><pubDate>Tue, 25 Oct 2022 15:49:53 +0200</pubDate><guid>https://internetexception.com/2022/10/25/asp-net-core-global-exception-handling/</guid><description>&lt;p&gt;To add global exception handling in ASP.NET Core just use configuration method:&lt;/p&gt;&#10;&lt;p&gt;&lt;code&gt;app.UseExceptionHandler&lt;/code&gt;&lt;/p&gt;&#10;&lt;p&gt;&lt;a href="https://learn.microsoft.com/en-us/aspnet/core/fundamentals/error-handling?view=aspnetcore-6.0#exception-handler-lambda" target="_blank" rel="noopener noreferrer"&gt;https://learn.microsoft.com/en-us/aspnet/core/fundamentals/error-handling?view=aspnetcore-6.0#exception-handler-lambda&lt;/a&gt;&#10;&lt;/p&gt;</description></item><item><title>What ASP.NET Middleware can do?</title><link>https://internetexception.com/2022/10/25/what-asp-net-middleware-can-do/</link><pubDate>Tue, 25 Oct 2022 15:45:12 +0200</pubDate><guid>https://internetexception.com/2022/10/25/what-asp-net-middleware-can-do/</guid><description>&lt;p&gt;Pretty much everything. Default ASP.NET Core request handling pipeline is consisting of bunch of middlewares:&lt;/p&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;&lt;a href="https://learn.microsoft.com/en-us/aspnet/core/security/authentication/identity?view=aspnetcore-6.0" target="_blank" rel="noopener noreferrer"&gt;Authentication&lt;/a&gt;&#10;&lt;/li&gt;&#10;&lt;li&gt;&lt;a href="https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.builder.authorizationappbuilderextensions.useauthorization" target="_blank" rel="noopener noreferrer"&gt;Authorization&lt;/a&gt;&#10;&lt;/li&gt;&#10;&lt;li&gt;&lt;a href="https://learn.microsoft.com/en-us/aspnet/core/security/cors?view=aspnetcore-6.0" target="_blank" rel="noopener noreferrer"&gt;CORS&lt;/a&gt;&#10;&lt;/li&gt;&#10;&lt;li&gt;&lt;a href="https://learn.microsoft.com/en-us/aspnet/core/fundamentals/http-logging/?view=aspnetcore-6.0" target="_blank" rel="noopener noreferrer"&gt;HTTP Logging&lt;/a&gt;&#10;&lt;/li&gt;&#10;&lt;li&gt;&lt;a href="https://learn.microsoft.com/en-us/aspnet/core/mvc/overview?view=aspnetcore-6.0" target="_blank" rel="noopener noreferrer"&gt;MVC&lt;/a&gt;&#10;&lt;/li&gt;&#10;&lt;li&gt;&lt;a href="https://learn.microsoft.com/en-us/aspnet/core/fundamentals/static-files?view=aspnetcore-6.0" target="_blank" rel="noopener noreferrer"&gt;Static Files&lt;/a&gt;&#10;&lt;/li&gt;&#10;&lt;li&gt;other&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p&gt;Whole list of built-in middlewares can be found here:&lt;/p&gt;&#10;&lt;p&gt;&lt;a href="https://learn.microsoft.com/en-us/aspnet/core/fundamentals/middleware/?view=aspnetcore-7.0#built-in-middleware" target="_blank" rel="noopener noreferrer"&gt;https://learn.microsoft.com/en-us/aspnet/core/fundamentals/middleware/?view=aspnetcore-7.0#built-in-middleware&lt;/a&gt;&#10;&lt;/p&gt;&#10;&lt;p&gt;There is possibility to write custom middleware too.&lt;/p&gt;</description></item><item><title>Middleware in OWIN</title><link>https://internetexception.com/2022/10/25/middleware-in-owin/</link><pubDate>Tue, 25 Oct 2022 15:40:45 +0200</pubDate><guid>https://internetexception.com/2022/10/25/middleware-in-owin/</guid><description>&lt;p&gt;There are 2 ways of writing OWIN middleware in ASP.NET Core.&lt;/p&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;Pure OWIN - usefull if you want to integrate with OWIN compatible module but not written in C#&lt;/li&gt;&#10;&lt;li&gt;ASP.NET Core OWIN middleware&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;h2 id="aspnet-core-middleware"&gt;ASP.NET Core Middleware:&lt;/h2&gt;&#10;&lt;p&gt;This type of middleware can be:&lt;/p&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;delegate of &lt;code&gt;Func&amp;lt;HttpContext, Func&amp;lt;&lt;/code&gt;Task&amp;gt;&lt;code&gt;, Task&amp;gt;&lt;/code&gt;&lt;/li&gt;&#10;&lt;li&gt;class with &lt;a href="https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.http.imiddleware?view=aspnetcore-7.0" data-type="URL" data-id="https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.http.imiddleware?view=aspnetcore-7.0"&gt;&lt;code&gt;IMiddleware&lt;/code&gt;&lt;/a&gt; imlementation&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-csharp" data-lang="csharp"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;async&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;next&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;{&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="c1"&gt;// Do work that can write to the Response.&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;next&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Invoke&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="c1"&gt;// Do logging or other work that doesn&amp;#39;t write to the Response.&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;});&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id="pure-owin-middleware"&gt;Pure OWIN Middleware:&lt;/h2&gt;&#10;&lt;p&gt;This rather would be used to integrate with OWIN middlewares written in different language, so that ASP.NET Core implementation directly is not possible.&lt;/p&gt;</description></item><item><title>Owin model and Kestrell request handling</title><link>https://internetexception.com/2022/10/24/owin-model-and-kestrell-request-handling/</link><pubDate>Mon, 24 Oct 2022 15:23:02 +0200</pubDate><guid>https://internetexception.com/2022/10/24/owin-model-and-kestrell-request-handling/</guid><description>&lt;ul&gt;&#10;&lt;li&gt;&lt;strong&gt;OWIN&lt;/strong&gt; - Open Web Interface for .NET&lt;/li&gt;&#10;&lt;li&gt;allows web apps to be decoupled from web servers&lt;/li&gt;&#10;&lt;li&gt;defines standard way for middleware to be used in a pipeline to handle requests and provide responses&lt;/li&gt;&#10;&lt;li&gt;ASP.NET Core applications can interoperate with OWIN-based applications, servers and middleware&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p&gt;Microsoft.AspNetCore.Owin package provides two adapter implementations:&lt;/p&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;ASP.NET Core to OWIN&lt;/li&gt;&#10;&lt;li&gt;OWIN to ASP.NET Core&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p&gt;This allows ASP.NET Core to be hosted on top of an OWIN compatible server/host or for other OWIN compatible components to be run on top of ASP.NET Core.&lt;/p&gt;</description></item><item><title>Expression Trees</title><link>https://internetexception.com/2022/10/24/expression-trees/</link><pubDate>Mon, 24 Oct 2022 15:08:43 +0200</pubDate><guid>https://internetexception.com/2022/10/24/expression-trees/</guid><description>&lt;ul&gt;&#10;&lt;li&gt;&amp;rsquo;tree like&amp;rsquo; data structure&lt;/li&gt;&#10;&lt;li&gt;each node is expression (method call, equality comparison, binary operation etc.) representing a piece of code&lt;/li&gt;&#10;&lt;li&gt;you can compile expression tree and run code it represent&lt;/li&gt;&#10;&lt;li&gt;enables dynamic code generation at runtime&lt;/li&gt;&#10;&lt;li&gt;LINQ queries on DBs are implemented with Expression Trees&lt;/li&gt;&#10;&lt;li&gt;used in the dynamic language runtime (DLR)&lt;/li&gt;&#10;&lt;li&gt;anonymous lambda expression can be converted to &lt;code&gt;ExpressionTree&lt;/code&gt; via compiler (i.e. &lt;code&gt;x =&amp;gt; x*2&lt;/code&gt; can be represented as tree instead of delegate or anonymous lambda function)&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p&gt;Further read:&lt;/p&gt;</description></item><item><title>Linq</title><link>https://internetexception.com/2022/10/24/linq/</link><pubDate>Mon, 24 Oct 2022 15:05:47 +0200</pubDate><guid>https://internetexception.com/2022/10/24/linq/</guid><description>&lt;ul&gt;&#10;&lt;li&gt;consistent model for working with data from various kinds of sources and formats (XML, SQL, ADO.NET, Datasets, .NET collections etc)&lt;/li&gt;&#10;&lt;li&gt;3 stages of working with LINQ:&#10;&lt;ul&gt;&#10;&lt;li&gt;obtain data source&lt;/li&gt;&#10;&lt;li&gt;create the query&lt;/li&gt;&#10;&lt;li&gt;execute the query&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;/li&gt;&#10;&lt;li&gt;data sources implements &lt;code&gt;IEnumerable&amp;lt;&amp;gt;&lt;/code&gt; and are called &lt;code&gt;queryable types&lt;/code&gt;&lt;/li&gt;&#10;&lt;li&gt;&lt;code&gt;IQueryable&amp;lt;&amp;gt;&lt;/code&gt; interface inherits from &lt;code&gt;IEnumerable&amp;lt;&amp;gt;&lt;/code&gt;&lt;/li&gt;&#10;&lt;li&gt;generally it is better to use LINQ via &lt;code&gt;IQueryable&amp;lt;&amp;gt;&lt;/code&gt; which produces &lt;code&gt;deferred query&lt;/code&gt; instead of producing result immediately&lt;/li&gt;&#10;&lt;li&gt;queries can be executed multiple times&lt;/li&gt;&#10;&lt;li&gt;queries can be forced immediate execution via &lt;code&gt;Count()&lt;/code&gt;, &lt;code&gt;Max()&lt;/code&gt;, &lt;code&gt;ToList()&lt;/code&gt; or &lt;code&gt;ToArray()&lt;/code&gt; etc.&lt;/li&gt;&#10;&lt;li&gt;LINQ to DB libraries (like EntityFramework) usually are implemented via &lt;code&gt;Expression Trees&lt;/code&gt;&lt;/li&gt;&#10;&lt;/ul&gt;</description></item><item><title>Entity Framework: Change Tracking</title><link>https://internetexception.com/2022/10/24/entity-framework-change-tracking/</link><pubDate>Mon, 24 Oct 2022 15:02:09 +0200</pubDate><guid>https://internetexception.com/2022/10/24/entity-framework-change-tracking/</guid><description>&lt;ul&gt;&#10;&lt;li&gt;tracked entities are saved during &lt;code&gt;SaveChanges()&lt;/code&gt; call&lt;/li&gt;&#10;&lt;li&gt;entities being tracked when they are:&#10;&lt;ul&gt;&#10;&lt;li&gt;returned from DB&lt;/li&gt;&#10;&lt;li&gt;attached to context&lt;/li&gt;&#10;&lt;li&gt;added as subentity&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;/li&gt;&#10;&lt;li&gt;tracking can be disabled (&lt;code&gt;AsNoTracking()&lt;/code&gt; i.e.)&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p&gt;Further read:&lt;/p&gt;&#10;&lt;p&gt;&lt;a href="https://learn.microsoft.com/en-us/ef/core/change-tracking/" target="_blank" rel="noopener noreferrer"&gt;https://learn.microsoft.com/en-us/ef/core/change-tracking/&lt;/a&gt;&#10;&lt;/p&gt;</description></item><item><title>Entity Framework: eager and lazy loading</title><link>https://internetexception.com/2022/10/24/entity-framework-eager-and-lazy-loading/</link><pubDate>Mon, 24 Oct 2022 14:57:56 +0200</pubDate><guid>https://internetexception.com/2022/10/24/entity-framework-eager-and-lazy-loading/</guid><description>&lt;ul&gt;&#10;&lt;li&gt;&#10;&lt;p&gt;lazy loading:&lt;/p&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;delaying load of data until we specifically request for it&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;!-- --&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;i.e. accessing &lt;code&gt;customer.Address&lt;/code&gt; loads Address of a customer in the background via separate SQL query&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;!-- --&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;property needs to be public, virtual&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;!-- --&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;context.Configuration.ProxyCreationEnabled should be true&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;!-- --&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;context.Configuration.LazyLoadingEnabled should be true&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;!-- --&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;to disable lazy loading completely &lt;code&gt;Context.Configuration.LazyLoadingEnabled = false;&lt;/code&gt;&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;/li&gt;&#10;&lt;li&gt;&#10;&lt;p&gt;eager loading&lt;/p&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;opposite of lazy loading&lt;/li&gt;&#10;&lt;li&gt;loads related entities as part of the query&lt;/li&gt;&#10;&lt;li&gt;done via &lt;code&gt;.Include()&lt;/code&gt; query&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p&gt;Further read:&lt;/p&gt;</description></item><item><title>Pattern matching</title><link>https://internetexception.com/2022/10/24/pattern-matching/</link><pubDate>Mon, 24 Oct 2022 14:50:08 +0200</pubDate><guid>https://internetexception.com/2022/10/24/pattern-matching/</guid><description>&lt;p&gt;Pattern matching is used for:&lt;/p&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;testing expression to check if some value have certain characteristics&lt;/li&gt;&#10;&lt;li&gt;safer compare because &amp;lsquo;==&amp;rsquo; and &amp;lsquo;!=&amp;rsquo; can be overloaded&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p&gt;Examples:&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-csharp" data-lang="csharp"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="k"&gt;is&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;number&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-csharp" data-lang="csharp"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;sequence&lt;/span&gt; &lt;span class="k"&gt;is&lt;/span&gt; &lt;span class="n"&gt;IList&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;T&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;list&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;switch statement:&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-csharp" data-lang="csharp"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;command&lt;/span&gt; &lt;span class="k"&gt;switch&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;{&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;Operation&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;SystemTest&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;RunDiagnostics&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;Operation&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Start&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;StartSystem&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;Operation&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Stop&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;StopSystem&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;Operation&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Reset&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;ResetToReady&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;ArgumentException&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;&amp;#34;Invalid enum value for command&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;nameof&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;command&lt;/span&gt;&lt;span class="p"&gt;)),&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;};&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;switch with ranges:&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-csharp" data-lang="csharp"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;tempInFahrenheit&lt;/span&gt; &lt;span class="k"&gt;switch&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;{&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="p"&gt;(&amp;gt;&lt;/span&gt; &lt;span class="m"&gt;32&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;and&lt;/span&gt; &lt;span class="p"&gt;(&amp;lt;&lt;/span&gt; &lt;span class="m"&gt;212&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s"&gt;&amp;#34;liquid&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt; &lt;span class="m"&gt;32&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s"&gt;&amp;#34;solid&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="m"&gt;212&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s"&gt;&amp;#34;gas&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="m"&gt;32&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s"&gt;&amp;#34;solid/liquid transition&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="m"&gt;212&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s"&gt;&amp;#34;liquid / gas transition&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;};&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;collection pattern matching:&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-csharp" data-lang="csharp"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;array&lt;/span&gt; &lt;span class="k"&gt;is&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="m"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="m"&gt;8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;..]&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Further read:&lt;/p&gt;&#10;&lt;p&gt;&lt;a href="https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals/functional/pattern-matching" target="_blank" rel="noopener noreferrer"&gt;https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals/functional/pattern-matching&lt;/a&gt;&#10;&lt;/p&gt;</description></item><item><title>Reflection</title><link>https://internetexception.com/2022/10/19/reflection/</link><pubDate>Wed, 19 Oct 2022 16:44:33 +0200</pubDate><guid>https://internetexception.com/2022/10/19/reflection/</guid><description>&lt;ul&gt;&#10;&lt;li&gt;obtain information about types and members at runtime&lt;/li&gt;&#10;&lt;li&gt;create instances, invoke or access them&lt;/li&gt;&#10;&lt;li&gt;dynamic code generation&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p&gt;Further read:&lt;/p&gt;&#10;&lt;p&gt;&lt;a href="https://learn.microsoft.com/en-us/dotnet/framework/reflection-and-codedom/reflection" target="_blank" rel="noopener noreferrer"&gt;https://learn.microsoft.com/en-us/dotnet/framework/reflection-and-codedom/reflection&lt;/a&gt;&#10;&lt;/p&gt;</description></item><item><title>Deployment models</title><link>https://internetexception.com/2022/10/19/deployment-models/</link><pubDate>Wed, 19 Oct 2022 16:42:01 +0200</pubDate><guid>https://internetexception.com/2022/10/19/deployment-models/</guid><description>&lt;table&gt;&#10;&lt;thead&gt;&#10;&lt;tr&gt;&#10;&lt;th&gt;Type&lt;/th&gt;&#10;&lt;th&gt;Command&lt;/th&gt;&#10;&lt;/tr&gt;&#10;&lt;/thead&gt;&#10;&lt;tbody&gt;&#10;&lt;tr&gt;&#10;&lt;td&gt;&lt;a href="https://learn.microsoft.com/en-us/dotnet/core/deploying/#publish-framework-dependent"&gt;framework-dependent executable&lt;/a&gt; for the current platform.&lt;/td&gt;&#10;&lt;td&gt;&lt;a href="https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-publish"&gt;&lt;code&gt;dotnet publish&lt;/code&gt;&lt;/a&gt;&lt;/td&gt;&#10;&lt;/tr&gt;&#10;&lt;tr&gt;&#10;&lt;td&gt;&lt;a href="https://learn.microsoft.com/en-us/dotnet/core/deploying/#publish-framework-dependent"&gt;framework-dependent executable&lt;/a&gt; for a specific platform.&lt;/td&gt;&#10;&lt;td&gt;&lt;a href="https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-publish"&gt;&lt;code&gt;dotnet publish -r &amp;lt;RID&amp;gt; --self-contained false&lt;/code&gt;&lt;/a&gt;&lt;/td&gt;&#10;&lt;/tr&gt;&#10;&lt;tr&gt;&#10;&lt;td&gt;&lt;a href="https://learn.microsoft.com/en-us/dotnet/core/deploying/#publish-framework-dependent"&gt;framework-dependent binary&lt;/a&gt;.&lt;/td&gt;&#10;&lt;td&gt;&lt;a href="https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-publish"&gt;&lt;code&gt;dotnet publish&lt;/code&gt;&lt;/a&gt;&lt;/td&gt;&#10;&lt;/tr&gt;&#10;&lt;tr&gt;&#10;&lt;td&gt;&lt;a href="https://learn.microsoft.com/en-us/dotnet/core/deploying/#publish-self-contained"&gt;self-contained executable&lt;/a&gt;.&lt;/td&gt;&#10;&lt;td&gt;&lt;a href="https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-publish"&gt;&lt;code&gt;dotnet publish -r &amp;lt;RID&amp;gt;&lt;/code&gt;&lt;/a&gt;&lt;/td&gt;&#10;&lt;/tr&gt;&#10;&lt;/tbody&gt;&#10;&lt;/table&gt;&#10;&lt;p&gt;Further read:&lt;/p&gt;&#10;&lt;p&gt;&lt;a href="https://learn.microsoft.com/en-us/dotnet/core/deploying/#publish-framework-dependent" data-type="URL" data-id="https://learn.microsoft.com/en-us/dotnet/core/deploying/#publish-framework-dependent"&gt;&lt;a href="https://learn.microsoft.com/en-us/dotnet/core/deploying/#publish-framework-dependent" target="_blank" rel="noopener noreferrer"&gt;https://learn.microsoft.com/en-us/dotnet/core/deploying/#publish-framework-dependent&lt;/a&gt;&#10;&lt;/a&gt;&lt;/p&gt;</description></item><item><title>.NET AOT</title><link>https://internetexception.com/2022/10/19/net-aot/</link><pubDate>Wed, 19 Oct 2022 16:39:08 +0200</pubDate><guid>https://internetexception.com/2022/10/19/net-aot/</guid><description>&lt;p&gt;&lt;strong&gt;Ahead of the time&lt;/strong&gt; compilation to machine code&lt;/p&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;produces self-contained application which:&#10;&lt;ul&gt;&#10;&lt;li&gt;starts quicker&lt;/li&gt;&#10;&lt;li&gt;uses less memory&lt;/li&gt;&#10;&lt;li&gt;does not require .NET runtime installed&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;/li&gt;&#10;&lt;li&gt;it is better for workloads with high deployment instances (clouds)&lt;/li&gt;&#10;&lt;li&gt;makes runtime code generation impossible&lt;/li&gt;&#10;&lt;li&gt;not all libraries are compatible&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p&gt;Further read:&lt;/p&gt;&#10;&lt;p&gt;&lt;a href="https://learn.microsoft.com/en-us/dotnet/core/deploying/native-aot/" target="_blank" rel="noopener noreferrer"&gt;https://learn.microsoft.com/en-us/dotnet/core/deploying/native-aot/&lt;/a&gt;&#10;&lt;/p&gt;</description></item><item><title>.NET Jit</title><link>https://internetexception.com/2022/10/19/net-jit/</link><pubDate>Wed, 19 Oct 2022 16:36:28 +0200</pubDate><guid>https://internetexception.com/2022/10/19/net-jit/</guid><description>&lt;p&gt;&lt;strong&gt;Just - in - time&lt;/strong&gt; compiler.&lt;/p&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;part of CLR&lt;/li&gt;&#10;&lt;li&gt;for all .net programs for all .net languages&lt;/li&gt;&#10;&lt;li&gt;converts &lt;strong&gt;MSIL&lt;/strong&gt; to native machine code&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;compiles&lt;/strong&gt; code when it is necessary at &lt;strong&gt;runtime&lt;/strong&gt;&lt;/li&gt;&#10;&lt;li&gt;also it is possible to &lt;strong&gt;pre-compile to native code&lt;/strong&gt; at compile time instead&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p&gt;Further read:&lt;/p&gt;&#10;&lt;p&gt;&lt;a href="https://www.geeksforgeeks.org/what-is-just-in-time-jit-compiler-in-dot-net/" target="_blank" rel="noopener noreferrer"&gt;https://www.geeksforgeeks.org/what-is-just-in-time-jit-compiler-in-dot-net/&lt;/a&gt;&#10;&lt;/p&gt;</description></item><item><title>Records</title><link>https://internetexception.com/2022/10/19/records/</link><pubDate>Wed, 19 Oct 2022 16:33:51 +0200</pubDate><guid>https://internetexception.com/2022/10/19/records/</guid><description>&lt;ul&gt;&#10;&lt;li&gt;can be class or struct&lt;/li&gt;&#10;&lt;li&gt;creates methods overrides for enforcing value equality instead of reference equality:&#10;&lt;ul&gt;&#10;&lt;li&gt;&lt;code&gt;Object.Equals&lt;/code&gt;&lt;/li&gt;&#10;&lt;li&gt;&lt;code&gt;Object.GetHashCode&lt;/code&gt;&lt;/li&gt;&#10;&lt;li&gt;operators&#10;&lt;ul&gt;&#10;&lt;li&gt;&lt;code&gt;==&lt;/code&gt;&lt;/li&gt;&#10;&lt;li&gt;&lt;code&gt;!=&lt;/code&gt;&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;/li&gt;&#10;&lt;li&gt;implements &lt;code&gt;IEquatable&amp;lt;&amp;gt;&lt;/code&gt; parameter&lt;/li&gt;&#10;&lt;li&gt;implements &lt;code&gt;ToString&lt;/code&gt;&lt;/li&gt;&#10;&lt;li&gt;supports deconstruction&lt;/li&gt;&#10;&lt;li&gt;supports &lt;code&gt;with&lt;/code&gt; expression&lt;/li&gt;&#10;&lt;li&gt;meant to be &lt;strong&gt;immutable&lt;/strong&gt;&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p&gt;&lt;code&gt;Positional records&lt;/code&gt; is a more concise syntax for record:&lt;/p&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;primary constructor parameters match the positional parameters of the record declaration&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;public&lt;/strong&gt; &lt;strong&gt;init-only&lt;/strong&gt; properties for each parameter&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p&gt;Further read:&lt;/p&gt;&#10;&lt;p&gt;&lt;a href="https://learn.microsoft.com/en-us/dotnet/csharp/whats-new/tutorials/records#characteristics-of-records" target="_blank" rel="noopener noreferrer"&gt;https://learn.microsoft.com/en-us/dotnet/csharp/whats-new/tutorials/records#characteristics-of-records&lt;/a&gt;&#10;&lt;/p&gt;</description></item><item><title>Is it possible to block GC?</title><link>https://internetexception.com/2022/10/19/is-it-possible-to-block-gc/</link><pubDate>Wed, 19 Oct 2022 16:28:54 +0200</pubDate><guid>https://internetexception.com/2022/10/19/is-it-possible-to-block-gc/</guid><description>&lt;p&gt;We can.&lt;/p&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;for some critical part of application code using &lt;code&gt;GC.TryStartNoGCRegion&lt;/code&gt; method.&lt;/li&gt;&#10;&lt;li&gt;using &lt;code&gt;CER&lt;/code&gt; (Constrained Execution Regions) (obsolete)&lt;/li&gt;&#10;&lt;li&gt;with &lt;code&gt;GC LatencyModes&lt;/code&gt;&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p&gt;Further read:&lt;/p&gt;&#10;&lt;p&gt;&lt;a href="https://learn.microsoft.com/en-us/dotnet/api/system.gc.trystartnogcregion?redirectedfrom=MSDN&amp;amp;view=net-7.0#overloads" target="_blank" rel="noopener noreferrer"&gt;https://learn.microsoft.com/en-us/dotnet/api/system.gc.trystartnogcregion?redirectedfrom=MSDN&amp;view=net-7.0#overloads&lt;/a&gt;&#10;&lt;/p&gt;&#10;&lt;p&gt;&lt;a href="https://learn.microsoft.com/en-us/dotnet/framework/performance/constrained-execution-regions?redirectedfrom=MSDN" target="_blank" rel="noopener noreferrer"&gt;https://learn.microsoft.com/en-us/dotnet/framework/performance/constrained-execution-regions?redirectedfrom=MSDN&lt;/a&gt;&#10;&lt;/p&gt;&#10;&lt;p&gt;&lt;a href="https://learn.microsoft.com/en-us/dotnet/standard/garbage-collection/latency" target="_blank" rel="noopener noreferrer"&gt;https://learn.microsoft.com/en-us/dotnet/standard/garbage-collection/latency&lt;/a&gt;&#10;&lt;/p&gt;</description></item><item><title>Garbage Collector</title><link>https://internetexception.com/2022/10/19/garbage-collector/</link><pubDate>Wed, 19 Oct 2022 16:26:09 +0200</pubDate><guid>https://internetexception.com/2022/10/19/garbage-collector/</guid><description>&lt;ul&gt;&#10;&lt;li&gt;automatic memory management&lt;/li&gt;&#10;&lt;li&gt;allocates and releases memory&lt;/li&gt;&#10;&lt;li&gt;prevents memory leaks and accessing dead objects&lt;/li&gt;&#10;&lt;li&gt;provides memory safety&lt;/li&gt;&#10;&lt;li&gt;virtual memory space&lt;/li&gt;&#10;&lt;li&gt;defragments/compacts memory&lt;/li&gt;&#10;&lt;li&gt;heap have 3 generations&#10;&lt;ul&gt;&#10;&lt;li&gt;0 - for new objects;&lt;/li&gt;&#10;&lt;li&gt;1 - for objects that lives through GC from 0&lt;/li&gt;&#10;&lt;li&gt;2 - for long living objects from 1 and 0&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;/li&gt;&#10;&lt;li&gt;also Large Objects Heap (LOH) for big objects like arrays over 85,000 bytes&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p&gt;Further read:&lt;/p&gt;&#10;&lt;p&gt;&lt;a href="https://learn.microsoft.com/en-us/dotnet/standard/garbage-collection/fundamentals?source=recommendations" target="_blank" rel="noopener noreferrer"&gt;https://learn.microsoft.com/en-us/dotnet/standard/garbage-collection/fundamentals?source=recommendations&lt;/a&gt;&#10;&lt;/p&gt;</description></item><item><title>Covariance and Contravariance</title><link>https://internetexception.com/2022/10/19/covariance-and-contravariance/</link><pubDate>Wed, 19 Oct 2022 16:21:04 +0200</pubDate><guid>https://internetexception.com/2022/10/19/covariance-and-contravariance/</guid><description>&lt;ul&gt;&#10;&lt;li&gt;enables implicit reference conversions for&#10;&lt;ul&gt;&#10;&lt;li&gt;arrays&lt;/li&gt;&#10;&lt;li&gt;delegates&lt;/li&gt;&#10;&lt;li&gt;generic type arguments&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;Covariance&lt;/strong&gt; preserves assignment compatibility&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;Contravariance&lt;/strong&gt; reverses assignment compatibility&lt;/li&gt;&#10;&lt;li&gt;allows for matching signatures of delegates and method groups&#10;&lt;ul&gt;&#10;&lt;li&gt;to assign to delegates from method that returns more derived types - &lt;strong&gt;covariance&lt;/strong&gt;&lt;/li&gt;&#10;&lt;li&gt;to assign to delegates from method that returns less derived types - &lt;strong&gt;contravariance&lt;/strong&gt;&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;Covariance&lt;/strong&gt; and &lt;strong&gt;Contravariance&lt;/strong&gt; are supported in &lt;strong&gt;Generics&lt;/strong&gt; for implicit conversions for type parameters&#10;&lt;ul&gt;&#10;&lt;li&gt;allows method to have more derived return type than defined by generic type parameter of the interface&lt;/li&gt;&#10;&lt;li&gt;this allows implicit conversions from one generic interface to another (from &lt;code&gt;IEnumerable&amp;lt;string&amp;gt;&lt;/code&gt; to &lt;code&gt;IEnumerable&amp;lt;object&amp;gt;&lt;/code&gt; even if first does not inherits from second)&lt;/li&gt;&#10;&lt;li&gt;allows generic types to have less derived argument types than specified by the generic parameter of the interface (implementation of &lt;code&gt;IEqualityComparer&amp;lt;BaseClass&amp;gt;&lt;/code&gt; can be implicitly converted to &lt;code&gt;IEqualityComparer&amp;lt;DerivedClass&amp;gt;&lt;/code&gt; because &lt;code&gt;IEqualityComparer.Equals&lt;/code&gt; is contravariant)&lt;/li&gt;&#10;&lt;li&gt;implicit conversions works for interfaces but not classes that implement from those interfaces (i.e. this won&amp;rsquo;t work &lt;code&gt;List&amp;lt;Object&amp;gt; list = new List&amp;lt;String&amp;gt;()&lt;/code&gt;)&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p&gt;&lt;em&gt;Assignment compatibility&lt;/em&gt; is when object of a more derived type is assigned to an object of a less derived type.&lt;/p&gt;</description></item><item><title>.NET Generics</title><link>https://internetexception.com/2022/10/19/net-generics/</link><pubDate>Wed, 19 Oct 2022 15:48:04 +0200</pubDate><guid>https://internetexception.com/2022/10/19/net-generics/</guid><description>&lt;p&gt;Allow for:&lt;/p&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;generalization of logic based on available types&lt;/li&gt;&#10;&lt;li&gt;specify possible supported types&lt;/li&gt;&#10;&lt;li&gt;re-usability of code&lt;/li&gt;&#10;&lt;li&gt;type safety&lt;/li&gt;&#10;&lt;li&gt;defers the exact specification of logic until the class or method is declared and instantiated by user code with all type parameters specified&lt;/li&gt;&#10;&lt;li&gt;mostly used for collections (some non-generic versions of collection are not recommended like &lt;code&gt;ArrayList&lt;/code&gt; i.e.)&lt;/li&gt;&#10;&lt;li&gt;information of exact type parameters used in a generic can be obtained at runtime by reflection&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p&gt;Further read:&lt;/p&gt;</description></item><item><title>Data structures in .NET</title><link>https://internetexception.com/2022/10/19/data-structures-in-net/</link><pubDate>Wed, 19 Oct 2022 14:52:50 +0200</pubDate><guid>https://internetexception.com/2022/10/19/data-structures-in-net/</guid><description>&lt;p&gt;In table below official recommendations for choosing data structure for your needs:&lt;/p&gt;&#10;&lt;table&gt;&#10;&lt;tbody&gt;&#10;&lt;tr&gt;&#10;&lt;td class="has-text-align-center" data-align="center"&gt;Generic&lt;/td&gt;&#10;&lt;td class="has-text-align-center" data-align="center"&gt;Non-Generic&lt;/td&gt;&#10;&lt;td class="has-text-align-center" data-align="center"&gt;Thread safe&lt;/td&gt;&#10;&lt;td class="has-text-align-center" data-align="center"&gt;Purpose&lt;/td&gt;&#10;&lt;/tr&gt;&#10;&lt;tr&gt;&#10;&lt;td class="has-text-align-center" data-align="center"&gt;&lt;code&gt;Dictionary&lt;/code&gt;&lt;/td&gt;&#10;&lt;td class="has-text-align-center" data-align="center"&gt;&lt;code&gt;Hashtable&lt;/code&gt;&lt;/td&gt;&#10;&lt;td class="has-text-align-center" data-align="center"&gt;&lt;code&gt;ConcurrentDictionary&lt;/code&gt;&lt;/td&gt;&#10;&lt;td class="has-text-align-center" data-align="center"&gt;key value pairs, lookup&lt;/td&gt;&#10;&lt;/tr&gt;&#10;&lt;tr&gt;&#10;&lt;td class="has-text-align-center" data-align="center"&gt;&lt;code&gt;List&lt;/code&gt;&lt;/td&gt;&#10;&lt;td class="has-text-align-center" data-align="center"&gt;&lt;code&gt;Array&lt;/code&gt;&lt;/td&gt;&#10;&lt;td class="has-text-align-center" data-align="center"&gt;&lt;code&gt;ImmutableList&lt;/code&gt;&lt;/td&gt;&#10;&lt;td class="has-text-align-center" data-align="center"&gt;access items by index&lt;/td&gt;&#10;&lt;/tr&gt;&#10;&lt;tr&gt;&#10;&lt;td class="has-text-align-center" data-align="center"&gt;&lt;code&gt;Queue&lt;/code&gt;&lt;/td&gt;&#10;&lt;td class="has-text-align-center" data-align="center"&gt;-&lt;/td&gt;&#10;&lt;td class="has-text-align-center" data-align="center"&gt;&lt;code&gt;ConcurrentQueue&lt;/code&gt;&lt;/td&gt;&#10;&lt;td class="has-text-align-center" data-align="center"&gt;FIFO queue&lt;/td&gt;&#10;&lt;/tr&gt;&#10;&lt;tr&gt;&#10;&lt;td class="has-text-align-center" data-align="center"&gt;&lt;code&gt;Stack&lt;/code&gt;&lt;/td&gt;&#10;&lt;td class="has-text-align-center" data-align="center"&gt;-&lt;/td&gt;&#10;&lt;td class="has-text-align-center" data-align="center"&gt;&lt;code&gt;ConcurrentStack&lt;/code&gt;&lt;/td&gt;&#10;&lt;td class="has-text-align-center" data-align="center"&gt;LIFO queue&lt;/td&gt;&#10;&lt;/tr&gt;&#10;&lt;tr&gt;&#10;&lt;td class="has-text-align-center" data-align="center"&gt;&lt;code&gt;LinkedList&lt;/code&gt;&lt;/td&gt;&#10;&lt;td class="has-text-align-center" data-align="center"&gt;-&lt;/td&gt;&#10;&lt;td class="has-text-align-center" data-align="center"&gt;-&lt;/td&gt;&#10;&lt;td class="has-text-align-center" data-align="center"&gt;access items sequentially&lt;/td&gt;&#10;&lt;/tr&gt;&#10;&lt;tr&gt;&#10;&lt;td class="has-text-align-center" data-align="center"&gt;&lt;code&gt;ObservableCollection&lt;/code&gt;&lt;/td&gt;&#10;&lt;td class="has-text-align-center" data-align="center"&gt;-&lt;/td&gt;&#10;&lt;td class="has-text-align-center" data-align="center"&gt;-&lt;/td&gt;&#10;&lt;td class="has-text-align-center" data-align="center"&gt;notfications after modification&lt;/td&gt;&#10;&lt;/tr&gt;&#10;&lt;tr&gt;&#10;&lt;td class="has-text-align-center" data-align="center"&gt;&lt;code&gt;SortedList&lt;/code&gt;&lt;/td&gt;&#10;&lt;td class="has-text-align-center" data-align="center"&gt;&lt;/td&gt;&#10;&lt;td class="has-text-align-center" data-align="center"&gt;&lt;code&gt;ImmutableSortedSet&lt;/code&gt;&lt;/td&gt;&#10;&lt;td class="has-text-align-center" data-align="center"&gt;auto sorted collection&lt;/td&gt;&#10;&lt;/tr&gt;&#10;&lt;tr&gt;&#10;&lt;td class="has-text-align-center" data-align="center"&gt;&lt;code&gt;HashSet&lt;/code&gt;&lt;/td&gt;&#10;&lt;td class="has-text-align-center" data-align="center"&gt;&lt;/td&gt;&#10;&lt;td class="has-text-align-center" data-align="center"&gt;&lt;code&gt;ImmutableHashSet&lt;/code&gt;&lt;/td&gt;&#10;&lt;td class="has-text-align-center" data-align="center"&gt;dictionary of just keys (high performance set operations)&lt;/td&gt;&#10;&lt;/tr&gt;&#10;&lt;/tbody&gt;&#10;&lt;/table&gt;&#10;&lt;p&gt;Further read:&lt;/p&gt;</description></item><item><title>Strings in .NET</title><link>https://internetexception.com/2022/10/19/strings-in-net/</link><pubDate>Wed, 19 Oct 2022 14:44:37 +0200</pubDate><guid>https://internetexception.com/2022/10/19/strings-in-net/</guid><description>&lt;ul&gt;&#10;&lt;li&gt;sequential collection of chars&lt;/li&gt;&#10;&lt;li&gt;immutable&lt;/li&gt;&#10;&lt;li&gt;max 2GB or about 1 billion characters&lt;/li&gt;&#10;&lt;li&gt;reference type&lt;/li&gt;&#10;&lt;li&gt;are interned - CLR saves memory by maintaining a table, called the &amp;ldquo;intern pool&amp;rdquo;, that contains a single reference to each unique literal string declared or created programmatically in your program.&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p&gt;Further read:&lt;/p&gt;&#10;&lt;p&gt;&lt;a href="https://learn.microsoft.com/en-us/dotnet/api/system.string?view=net-7.0" target="_blank" rel="noopener noreferrer"&gt;https://learn.microsoft.com/en-us/dotnet/api/system.string?view=net-7.0&lt;/a&gt;&#10;&lt;/p&gt;&#10;&lt;p&gt;&lt;a href="https://learn.microsoft.com/en-us/dotnet/api/system.string.intern?view=net-6.0#remarks" target="_blank" rel="noopener noreferrer"&gt;https://learn.microsoft.com/en-us/dotnet/api/system.string.intern?view=net-6.0#remarks&lt;/a&gt;&#10;&lt;/p&gt;</description></item><item><title>What type can not be object field?</title><link>https://internetexception.com/2022/10/19/what-type-can-not-be-object-field/</link><pubDate>Wed, 19 Oct 2022 14:33:00 +0200</pubDate><guid>https://internetexception.com/2022/10/19/what-type-can-not-be-object-field/</guid><description>&lt;p&gt;&lt;code&gt;ref struct&lt;/code&gt; type can not be used as object field.&lt;/p&gt;&#10;&lt;p&gt;Further read:&lt;/p&gt;&#10;&lt;p&gt;&lt;a href="http://2022/10/19/ref-struct-types/" target="_blank" rel="noopener noreferrer"&gt;`ref struct` types&lt;/a&gt;&#10;&lt;/p&gt;&#10;&lt;p&gt;&lt;a href="https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/ref-struct" target="_blank" rel="noopener noreferrer"&gt;https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/ref-struct&lt;/a&gt;&#10;&lt;/p&gt;</description></item><item><title>`ref struct` types</title><link>https://internetexception.com/2022/10/19/ref-struct-types/</link><pubDate>Wed, 19 Oct 2022 14:28:48 +0200</pubDate><guid>https://internetexception.com/2022/10/19/ref-struct-types/</guid><description>&lt;ul&gt;&#10;&lt;li&gt;added as part of C# 7.2.&lt;/li&gt;&#10;&lt;li&gt;defined with &lt;code&gt;ref struct StructName&lt;/code&gt;&lt;/li&gt;&#10;&lt;li&gt;always on the stack&lt;/li&gt;&#10;&lt;li&gt;never part of heap&lt;/li&gt;&#10;&lt;li&gt;cannot be element of an array&lt;/li&gt;&#10;&lt;li&gt;cannot be field type of reference type&lt;/li&gt;&#10;&lt;li&gt;can&amp;rsquo;t implement interfaces&lt;/li&gt;&#10;&lt;li&gt;can&amp;rsquo;t be boxed&lt;/li&gt;&#10;&lt;li&gt;can&amp;rsquo;t be type argument&lt;/li&gt;&#10;&lt;li&gt;can&amp;rsquo;t be captured by closure of lambda or local function&lt;/li&gt;&#10;&lt;li&gt;can&amp;rsquo;t be used in async methods&lt;/li&gt;&#10;&lt;li&gt;can&amp;rsquo;t be used in iterators&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p&gt;Further read:&lt;/p&gt;&#10;&lt;p&gt;&lt;a href="https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/ref-struct" target="_blank" rel="noopener noreferrer"&gt;https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/ref-struct&lt;/a&gt;&#10;&lt;/p&gt;</description></item><item><title>Value types as fields in objects</title><link>https://internetexception.com/2022/10/19/value-types-as-fields-in-objects/</link><pubDate>Wed, 19 Oct 2022 14:26:29 +0200</pubDate><guid>https://internetexception.com/2022/10/19/value-types-as-fields-in-objects/</guid><description>&lt;p&gt;Value types are stored in the &lt;strong&gt;heap&lt;/strong&gt; when they are part of the reference type.&lt;/p&gt;</description></item><item><title>Reference types vs Value types</title><link>https://internetexception.com/2022/10/19/reference-types-vs-value-types/</link><pubDate>Wed, 19 Oct 2022 14:17:17 +0200</pubDate><guid>https://internetexception.com/2022/10/19/reference-types-vs-value-types/</guid><description>&lt;p&gt;&lt;strong&gt;Reference types:&lt;/strong&gt;&lt;/p&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;passed via reference&lt;/li&gt;&#10;&lt;li&gt;reside on the heap&lt;/li&gt;&#10;&lt;li&gt;subject to GC&lt;/li&gt;&#10;&lt;li&gt;inherits from &lt;code&gt;System.Object&lt;/code&gt;&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p&gt;&lt;strong&gt;Value types:&lt;/strong&gt;&lt;/p&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;passed via value&lt;/li&gt;&#10;&lt;li&gt;reside on the stack, CPU registers or the heap&lt;/li&gt;&#10;&lt;li&gt;no subject to GC&lt;/li&gt;&#10;&lt;li&gt;inherits from &lt;code&gt;System.ValueType&lt;/code&gt;&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p&gt;Further read:&lt;/p&gt;&#10;&lt;p&gt;&lt;a href="https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/reference-types" target="_blank" rel="noopener noreferrer"&gt;https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/reference-types&lt;/a&gt;&#10;&lt;/p&gt;&#10;&lt;p&gt;&lt;a href="https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/value-types" target="_blank" rel="noopener noreferrer"&gt;https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/value-types&lt;/a&gt;&#10;&lt;/p&gt;&#10;&lt;p&gt;&lt;a href="https://www.infoworld.com/article/3043992/a-deep-dive-value-and-reference-types-in-net.html" target="_blank" rel="noopener noreferrer"&gt;https://www.infoworld.com/article/3043992/a-deep-dive-value-and-reference-types-in-net.html&lt;/a&gt;&#10;&lt;/p&gt;</description></item><item><title>.NET Type System</title><link>https://internetexception.com/2022/10/19/net-type-system/</link><pubDate>Wed, 19 Oct 2022 13:59:44 +0200</pubDate><guid>https://internetexception.com/2022/10/19/net-type-system/</guid><description>&lt;ul&gt;&#10;&lt;li&gt;shared type system across all .net languages&lt;/li&gt;&#10;&lt;li&gt;primitives data types library&lt;/li&gt;&#10;&lt;li&gt;5 kind of types:&#10;&lt;ul&gt;&#10;&lt;li&gt;classes&lt;/li&gt;&#10;&lt;li&gt;structures&lt;/li&gt;&#10;&lt;li&gt;enumerations&lt;/li&gt;&#10;&lt;li&gt;interfaces&lt;/li&gt;&#10;&lt;li&gt;delegates&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p&gt;Further read:&lt;/p&gt;&#10;&lt;p&gt;&lt;a href="https://learn.microsoft.com/en-us/dotnet/standard/base-types/common-type-system" target="_blank" rel="noopener noreferrer"&gt;https://learn.microsoft.com/en-us/dotnet/standard/base-types/common-type-system&lt;/a&gt;&#10;&lt;/p&gt;</description></item><item><title>ThreadPool</title><link>https://internetexception.com/2022/10/19/threadpool/</link><pubDate>Wed, 19 Oct 2022 13:53:37 +0200</pubDate><guid>https://internetexception.com/2022/10/19/threadpool/</guid><description>&lt;ul&gt;&#10;&lt;li&gt;provides a pool of threads&lt;/li&gt;&#10;&lt;li&gt;can be used to execute tasks&lt;/li&gt;&#10;&lt;li&gt;post work items&lt;/li&gt;&#10;&lt;li&gt;process asynchronous I/O&lt;/li&gt;&#10;&lt;li&gt;process timers&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p&gt;Further read:&lt;/p&gt;&#10;&lt;p&gt;&lt;a href="https://learn.microsoft.com/en-us/dotnet/api/system.threading.threadpool?view=net-6.0" target="_blank" rel="noopener noreferrer"&gt;https://learn.microsoft.com/en-us/dotnet/api/system.threading.threadpool?view=net-6.0&lt;/a&gt;&#10;&lt;/p&gt;</description></item><item><title>Task Parallel Library (TPL)</title><link>https://internetexception.com/2022/10/19/task-parallel-library-tpl/</link><pubDate>Wed, 19 Oct 2022 13:51:20 +0200</pubDate><guid>https://internetexception.com/2022/10/19/task-parallel-library-tpl/</guid><description>&lt;ul&gt;&#10;&lt;li&gt;simplify process of adding parallelism and concurrency to application&lt;/li&gt;&#10;&lt;li&gt;scales concurrency automatically&lt;/li&gt;&#10;&lt;li&gt;data parallelism&lt;/li&gt;&#10;&lt;li&gt;task based &lt;code&gt;async&lt;/code&gt; programming&lt;/li&gt;&#10;&lt;li&gt;data flow&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p&gt;Further read:&lt;/p&gt;&#10;&lt;p&gt;&lt;a href="https://learn.microsoft.com/en-us/dotnet/standard/parallel-programming/task-parallel-library-tpl" target="_blank" rel="noopener noreferrer"&gt;https://learn.microsoft.com/en-us/dotnet/standard/parallel-programming/task-parallel-library-tpl&lt;/a&gt;&#10;&lt;/p&gt;</description></item><item><title>Locking with integer</title><link>https://internetexception.com/2022/10/19/locking-with-integer/</link><pubDate>Wed, 19 Oct 2022 13:44:02 +0200</pubDate><guid>https://internetexception.com/2022/10/19/locking-with-integer/</guid><description>&lt;p&gt;In short:&lt;/p&gt;&#10;&lt;p&gt;it will not work because it requires boxing and boxing will create new object for reference in &lt;code&gt;lock&lt;/code&gt; every time code is executed so lock statement will not prevent anything.&lt;/p&gt;&#10;&lt;p&gt;Further read:&lt;/p&gt;&#10;&lt;p&gt;&lt;a href="https://intellitect.com/blog/locking-a-block-of-code-with-an-integer/" target="_blank" rel="noopener noreferrer"&gt;https://intellitect.com/blog/locking-a-block-of-code-with-an-integer/&lt;/a&gt;&#10;&lt;/p&gt;</description></item><item><title>Locking in .NET</title><link>https://internetexception.com/2022/10/19/locking-in-net/</link><pubDate>Wed, 19 Oct 2022 13:27:01 +0200</pubDate><guid>https://internetexception.com/2022/10/19/locking-in-net/</guid><description>&lt;ul&gt;&#10;&lt;li&gt;&lt;code&gt;lock&lt;/code&gt; statement blocks execution of a code block for single thread that hold lock&lt;/li&gt;&#10;&lt;li&gt;the same thread can acquire and release lock again&lt;/li&gt;&#10;&lt;li&gt;any other thread is blocked from the statement&lt;/li&gt;&#10;&lt;li&gt;lock on dedicated instance only&lt;/li&gt;&#10;&lt;li&gt;using the same instance on multiple &lt;code&gt;lock&lt;/code&gt; statements may lead to deadlock&lt;/li&gt;&#10;&lt;li&gt;avoid using as lock&#10;&lt;ul&gt;&#10;&lt;li&gt;&lt;code&gt;this&lt;/code&gt;, as it might be used by the callers as a lock&lt;/li&gt;&#10;&lt;li&gt;&lt;a href="https://learn.microsoft.com/en-us/dotnet/api/system.type" target="_blank" rel="noopener noreferrer"&gt;Type&lt;/a&gt;&#10; instances, as those might be obtained by the &lt;a href="https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/type-testing-and-cast#typeof-operator" target="_blank" rel="noopener noreferrer"&gt;typeof&lt;/a&gt;&#10; operator or reflection&lt;/li&gt;&#10;&lt;li&gt;string instances, including string literals, as those might be &lt;a href="https://learn.microsoft.com/en-us/dotnet/api/system.string.intern#remarks" target="_blank" rel="noopener noreferrer"&gt;interned&lt;/a&gt;&#10;&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;/li&gt;&#10;&lt;li&gt;Hold a lock for as short time as possible to reduce lock contention.&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p&gt;Below code block is translated by compiler&lt;/p&gt;</description></item><item><title>Thread vs task in . NET</title><link>https://internetexception.com/2022/10/19/thread-vs-task-in-net/</link><pubDate>Wed, 19 Oct 2022 13:12:33 +0200</pubDate><guid>https://internetexception.com/2022/10/19/thread-vs-task-in-net/</guid><description>&lt;ul&gt;&#10;&lt;li&gt;task is asynchronous operation&lt;/li&gt;&#10;&lt;li&gt;thread is abstraction on OS thread&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p&gt;Further read:&lt;/p&gt;&#10;&lt;p&gt;&lt;a href="https://www.c-sharpcorner.com/article/task-and-thread-in-c-sharp/" target="_blank" rel="noopener noreferrer"&gt;https://www.c-sharpcorner.com/article/task-and-thread-in-c-sharp/&lt;/a&gt;&#10;&lt;/p&gt;</description></item><item><title>What is SynchronizationContext in .NET</title><link>https://internetexception.com/2022/10/19/what-is-synchronizationcontext-in-net/</link><pubDate>Wed, 19 Oct 2022 13:08:18 +0200</pubDate><guid>https://internetexception.com/2022/10/19/what-is-synchronizationcontext-in-net/</guid><description>&lt;ul&gt;&#10;&lt;li&gt;multi threaded programs usually uses one of the threads as means of synchronization&lt;/li&gt;&#10;&lt;li&gt;there are message loops to pass unit of works (like Windows message queue)&lt;/li&gt;&#10;&lt;li&gt;message queues require messages formats and convention for handling it&lt;/li&gt;&#10;&lt;li&gt;single thread to handle ASP.NET request is waste of the resources (before .NET 2)&lt;/li&gt;&#10;&lt;li&gt;thread pool was better but inconvenient to work with&lt;/li&gt;&#10;&lt;li&gt;instead &lt;strong&gt;SynchronizationContext&lt;/strong&gt; queues work for given &lt;em&gt;context&lt;/em&gt; not thread&lt;/li&gt;&#10;&lt;li&gt;thread have &lt;em&gt;current&lt;/em&gt; context&lt;/li&gt;&#10;&lt;li&gt;context does not have to be &lt;em&gt;unique&lt;/em&gt; but can be shared between &lt;em&gt;multiple threads&lt;/em&gt;&lt;/li&gt;&#10;&lt;li&gt;thread can &lt;em&gt;change context&lt;/em&gt; but this is &lt;em&gt;rare&lt;/em&gt;&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;SynchronizationContext&lt;/strong&gt; keeps count of all asynchronous operations&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;Windows Forms&lt;/strong&gt; uses &lt;strong&gt;WindowsFormsSynchronizationContext&lt;/strong&gt;&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;WPF and Silverlight&lt;/strong&gt; uses &lt;strong&gt;DispatcherSynchronizationContext&lt;/strong&gt;&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;Console app and WindowsServices and ThreadPool threads&lt;/strong&gt; uses &lt;strong&gt;default SynchronizationContext&lt;/strong&gt;&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;ASP.NET&lt;/strong&gt; uses &lt;strong&gt;AspNetSynchronizationContext&lt;/strong&gt;&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p&gt;Further read:&lt;/p&gt;</description></item><item><title>Does async/await creates new thread?</title><link>https://internetexception.com/2022/10/19/does-async-await-creates-new-thread/</link><pubDate>Wed, 19 Oct 2022 12:58:00 +0200</pubDate><guid>https://internetexception.com/2022/10/19/does-async-await-creates-new-thread/</guid><description>&lt;p&gt;In short: &lt;strong&gt;no&lt;/strong&gt;.&lt;/p&gt;&#10;&lt;p&gt;Longer explanation:&lt;/p&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;task that want to do I/O write call to driver write&lt;/li&gt;&#10;&lt;li&gt;driver operations are performed asynchronously&lt;/li&gt;&#10;&lt;li&gt;write operations on devices is done without CPU involved&lt;/li&gt;&#10;&lt;li&gt;finish of writing is done via interrupt&lt;/li&gt;&#10;&lt;li&gt;interrupt, schedules &lt;code&gt;Deferred Procedure Call&lt;/code&gt;&lt;/li&gt;&#10;&lt;li&gt;&lt;code&gt;DPC&lt;/code&gt; schedules &lt;code&gt;Asynchronous Procedure Call&lt;/code&gt;&lt;/li&gt;&#10;&lt;li&gt;&lt;code&gt;APC&lt;/code&gt; notifies thread that I/O write is done&lt;/li&gt;&#10;&lt;li&gt;task that was doing I/O is scheduled with continuation of its method after I/O is done.&lt;/li&gt;&#10;&lt;li&gt;some threads might need to be borrowed for handling APC and such but &lt;em&gt;no thread is spawn to handle I/O&lt;/em&gt;&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p&gt;I recommend reading this post: &lt;a href="https://blog.stephencleary.com/2013/11/there-is-no-thread.html" data-type="URL" data-id="https://blog.stephencleary.com/2013/11/there-is-no-thread.html"&gt;&lt;a href="https://blog.stephencleary.com/2013/11/there-is-no-thread.html" target="_blank" rel="noopener noreferrer"&gt;https://blog.stephencleary.com/2013/11/there-is-no-thread.html&lt;/a&gt;&#10;&lt;/a&gt;. This will explain the topic much better than I can.&lt;/p&gt;</description></item><item><title>Avoid deadlock with asynchronous methods</title><link>https://internetexception.com/2022/10/19/avoid-deadlock-with-asynchronous-methods/</link><pubDate>Wed, 19 Oct 2022 12:52:45 +0200</pubDate><guid>https://internetexception.com/2022/10/19/avoid-deadlock-with-asynchronous-methods/</guid><description>&lt;ul&gt;&#10;&lt;li&gt;avoid doing &lt;code&gt;AsyncOperation.Result&lt;/code&gt;&lt;/li&gt;&#10;&lt;li&gt;parent method waits for &lt;code&gt;Result&lt;/code&gt; while child method waits for parent thread to take control, after being done with async I/O&lt;/li&gt;&#10;&lt;li&gt;both waits&lt;/li&gt;&#10;&lt;li&gt;deadlock&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p&gt;Further read:&lt;/p&gt;&#10;&lt;p&gt;&lt;a href="https://medium.com/rubrikkgroup/understanding-async-avoiding-deadlocks-e41f8f2c6f5d" target="_blank" rel="noopener noreferrer"&gt;https://medium.com/rubrikkgroup/understanding-async-avoiding-deadlocks-e41f8f2c6f5d&lt;/a&gt;&#10;&lt;/p&gt;&#10;&lt;p&gt;&lt;a href="https://stackoverflow.com/questions/15021304/an-async-await-example-that-causes-a-deadlock" target="_blank" rel="noopener noreferrer"&gt;https://stackoverflow.com/questions/15021304/an-async-await-example-that-causes-a-deadlock&lt;/a&gt;&#10;&lt;/p&gt;</description></item><item><title>Asynchronous programming in .NET</title><link>https://internetexception.com/2022/10/19/asynchronous-programming-in-net/</link><pubDate>Wed, 19 Oct 2022 09:52:30 +0200</pubDate><guid>https://internetexception.com/2022/10/19/asynchronous-programming-in-net/</guid><description>&lt;p&gt;Asynchronous programming patterns in .NET:&lt;/p&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;&lt;a href="https://learn.microsoft.com/en-us/dotnet/standard/asynchronous-programming-patterns/asynchronous-programming-model-apm" data-type="URL" data-id="https://learn.microsoft.com/en-us/dotnet/standard/asynchronous-programming-patterns/asynchronous-programming-model-apm"&gt;Asynchronous Programming Model&lt;/a&gt; (BeginOperation/EndOperation)&lt;/li&gt;&#10;&lt;li&gt;&lt;a href="https://learn.microsoft.com/en-us/dotnet/standard/asynchronous-programming-patterns/event-based-asynchronous-pattern-overview" data-type="URL" data-id="https://learn.microsoft.com/en-us/dotnet/standard/asynchronous-programming-patterns/event-based-asynchronous-pattern-overview"&gt;Event-based Asynchronous Pattern&lt;/a&gt; (invoke event with result from async job)&lt;/li&gt;&#10;&lt;li&gt;&lt;a href="https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/async/task-asynchronous-programming-model" target="_blank" rel="noopener noreferrer"&gt;Task-based Asynchronous Pattern&lt;/a&gt;&#10; (Task&amp;lt;&amp;gt;)&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p&gt;Ways of achieving asynchronous code in .NET&lt;/p&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;async, await&lt;/li&gt;&#10;&lt;li&gt;&lt;code&gt;Task&lt;/code&gt; class API (&lt;code&gt;Run&lt;/code&gt;, &lt;code&gt;WhenAll&lt;/code&gt;, &lt;code&gt;WhenAny&lt;/code&gt;, etc.)&lt;/li&gt;&#10;&lt;li&gt;&lt;code&gt;ThreadPool.QueueUserWorkItem(ThreadProc);&lt;/code&gt;&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p&gt;Further read:&lt;/p&gt;&#10;&lt;p&gt;&lt;a href="https://internetexception.com/2022/10/19/async-await-in-c/" data-type="URL" data-id="/2022/10/19/async-await-in-c/"&gt;async/await in .NET&lt;/a&gt;&lt;/p&gt;&#10;&lt;p&gt;&lt;a href="https://learn.microsoft.com/en-us/dotnet/standard/asynchronous-programming-patterns/" target="_blank" rel="noopener noreferrer"&gt;https://learn.microsoft.com/en-us/dotnet/standard/asynchronous-programming-patterns/&lt;/a&gt;&#10;&lt;/p&gt;</description></item><item><title>async/await in C#</title><link>https://internetexception.com/2022/10/19/async-await-in-c/</link><pubDate>Wed, 19 Oct 2022 09:51:34 +0200</pubDate><guid>https://internetexception.com/2022/10/19/async-await-in-c/</guid><description>&lt;p&gt;&lt;code&gt;async&lt;/code&gt;/&lt;code&gt;await&lt;/code&gt; syntax should be used for &lt;a href="https://internetexception.com/2022/10/19/async-await-in-c/" data-type="post" data-id="491"&gt;I/O bound&lt;/a&gt; asynchronous operations only.&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-csharp" data-lang="csharp"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;async&lt;/span&gt; &lt;span class="n"&gt;Task&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;GetUrlContentLengthAsync&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;{&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;HttpClient&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;Task&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;getStringTask&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;GetStringAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;&amp;#34;https://docs.microsoft.com/dotnet&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;DoIndependentWork&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;contents&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;getStringTask&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;contents&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;}&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Compiler transforms code into a state machine that to track yielding execution for &lt;code&gt;await&lt;/code&gt; and resuming execution when a background job is finished.&lt;/p&gt;&#10;&lt;p&gt;Things to keep in mind:&lt;/p&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;&lt;code&gt;async&lt;/code&gt; method needs await&lt;/li&gt;&#10;&lt;li&gt;add &lt;code&gt;Async&lt;/code&gt; suffix to asynchronous methods&lt;/li&gt;&#10;&lt;li&gt;&lt;code&gt;async void&lt;/code&gt; for &amp;lsquo;Fire and Forget&amp;rsquo; work i.e. event Handlers&lt;/li&gt;&#10;&lt;li&gt;be aware of mixing LINQ with &lt;code&gt;async&lt;/code&gt; lambdas&lt;/li&gt;&#10;&lt;li&gt;wait for tasks in a non-blocking manner (do not use &lt;code&gt;Task.Result&lt;/code&gt; i.e.)&lt;/li&gt;&#10;&lt;li&gt;for tight loops use &lt;code&gt;ValueTasks&lt;/code&gt;&lt;/li&gt;&#10;&lt;li&gt;Consider using &lt;code&gt;ConfigureAwait(false)&lt;/code&gt; for performance and for avoiding deadlocks&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p&gt;Further read:&lt;/p&gt;</description></item><item><title>CPU bound vs I/O bound</title><link>https://internetexception.com/2022/10/19/cpu-bound-vs-i-o-bound/</link><pubDate>Wed, 19 Oct 2022 09:35:37 +0200</pubDate><guid>https://internetexception.com/2022/10/19/cpu-bound-vs-i-o-bound/</guid><description>&lt;p&gt;There are two types of asynchronous operations in .NET.&lt;/p&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;I/O bound&lt;/li&gt;&#10;&lt;li&gt;CPU bound&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p&gt;For I/O bound &lt;code&gt;async&lt;/code&gt;/&lt;code&gt;await&lt;/code&gt; syntax should be used. TPL should not be used for this. &lt;code&gt;async&lt;/code&gt; methods does not spawns new thread to hand le I/O work asynchronously.&lt;/p&gt;&#10;&lt;p&gt;For CPU bound operations TPL should be used (&lt;code&gt;Task.Run&lt;/code&gt;). This spawns new thread. Performance testing should be done to check if overhead of new thread and context switching is not greater than actual work to be done.&lt;/p&gt;</description></item><item><title>SupressFinalize in IDisposable interface</title><link>https://internetexception.com/2022/10/18/supressfinalize-in-idisposable-interface/</link><pubDate>Tue, 18 Oct 2022 14:24:06 +0200</pubDate><guid>https://internetexception.com/2022/10/18/supressfinalize-in-idisposable-interface/</guid><description>&lt;ul&gt;&#10;&lt;li&gt;informs GC that object does not need to be added to finalizer queue&lt;/li&gt;&#10;&lt;li&gt;finalizer execution is not deterministic and objects can live for long time in queue - this is optimization technique&lt;/li&gt;&#10;&lt;li&gt;to make sure that object disposes of any unamanaged resources even if &lt;code&gt;Dispose&lt;/code&gt; will be not called we need to implement finalizer&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p&gt;Basically finalizer execution time is not deterministic. We cannot predict when this will be called and till that time - object is existing and still taking memory space. Since we are controlling creation and disposal of those resources we can say to GC: &amp;lsquo;Do not worry about that! It already had been taken care of!&amp;rsquo;. So this way object will be destroyed sooner, leaving this space to be used by something else possibly.&lt;/p&gt;</description></item><item><title>IDisposable interface pattern</title><link>https://internetexception.com/2022/10/18/idisposable-interface-pattern/</link><pubDate>Tue, 18 Oct 2022 14:16:21 +0200</pubDate><guid>https://internetexception.com/2022/10/18/idisposable-interface-pattern/</guid><description>&lt;p&gt;Example implementation of &lt;code&gt;IDisposable&lt;/code&gt;&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-csharp" data-lang="csharp"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;MyResource&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;IDisposable&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;{&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="n"&gt;MyResource&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;IntPtr&lt;/span&gt; &lt;span class="n"&gt;handle&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="p"&gt;{&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;handle&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;handle&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="p"&gt;}&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="n"&gt;Dispose&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="p"&gt;{&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;Dispose&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;disposing&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;GC&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;SuppressFinalize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="p"&gt;}&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="kd"&gt;protected&lt;/span&gt; &lt;span class="k"&gt;virtual&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="n"&gt;Dispose&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="n"&gt;disposing&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="p"&gt;{&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(!&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;disposed&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="p"&gt;{&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;disposing&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="p"&gt;{&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;component&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Dispose&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="p"&gt;}&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;CloseHandle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;handle&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;handle&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;IntPtr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Zero&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;disposed&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="p"&gt;}&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="p"&gt;}&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="p"&gt;~&lt;/span&gt;&lt;span class="n"&gt;MyResource&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="p"&gt;{&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;Dispose&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;disposing&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="p"&gt;}&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;}&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;code&gt;MyResource&lt;/code&gt; object have pointer which is unmanaged. This is why this class should implement &lt;code&gt;IDisposable&lt;/code&gt; interface. Implementation should be correct according to recommended pattern (see below for documentation).&lt;/p&gt;&#10;&lt;p&gt;There a re few points to highlight here:&lt;/p&gt;</description></item><item><title>Dynamic runtime delegates conversion</title><link>https://internetexception.com/2017/05/07/dynamic-runtime-delegates-conversion/</link><pubDate>Sun, 07 May 2017 11:53:00 +0200</pubDate><guid>https://internetexception.com/2017/05/07/dynamic-runtime-delegates-conversion/</guid><description>&lt;h3 id="introduction"&gt;Introduction&lt;/h3&gt;&#10;&lt;p&gt;Delegates can be converted easily to another type if you know types of those delegates. But if you do not know it is impossible without really complicated code.&lt;/p&gt;</description></item><item><title>Automatic scrolling to edited text box in Xamarin Android.</title><link>https://internetexception.com/2017/02/25/automatic-scrolling-to-edited-text-box-in-xamarin-android/</link><pubDate>Sat, 25 Feb 2017 14:48:00 +0100</pubDate><guid>https://internetexception.com/2017/02/25/automatic-scrolling-to-edited-text-box-in-xamarin-android/</guid><description>&lt;p&gt;&lt;strong&gt;Important note: this should work well with newer version of Xamarin (2.3.3). If you cannot update for some reason this article will explain workaround.&lt;/strong&gt;&lt;/p&gt;&#10;&lt;h3 id="introduction"&gt;Introduction&lt;/h3&gt;&#10;&lt;p&gt;In previous article I explained how to detect show and hide events of software keyboard in Xamarin Android. I did it in my project because of the fact that some of text boxes was hidden by software keyboard that suppose to edit contents of those text boxes. In this article I will explain how to work around this issue in some older versions of Xamarin.&lt;/p&gt;</description></item><item><title>Xamarin with TinyIoC</title><link>https://internetexception.com/2016/12/10/xamarin-with-tinyioc/</link><pubDate>Sat, 10 Dec 2016 09:48:00 +0100</pubDate><guid>https://internetexception.com/2016/12/10/xamarin-with-tinyioc/</guid><description>&lt;h3 id="introduction"&gt;Introduction&lt;/h3&gt;&#10;&lt;p&gt;This article is builds on topics and solutions introduces in &lt;a href="https://internetexception.com/2016/07/09/viewfactory-for-xamarin-application/"&gt;ViewFactory for Xamarin application&lt;/a&gt;&#10; and &lt;a href="https://internetexception.com/2016/04/24/xamarin-master-detail-page/"&gt;Xamarin Master-Detail Page&lt;/a&gt;&#10; articles. It shows method for easier navigation and use of services via IoC in Xamarin application. Knowledge from previous examples is not necessary, but makes this article bit easier to understand.&lt;/p&gt;</description></item><item><title>Genereting proxies during runtime using Reflection.Emit</title><link>https://internetexception.com/2016/10/07/genereting-proxies-during-runtime-using-reflection-emit/</link><pubDate>Fri, 07 Oct 2016 12:29:00 +0200</pubDate><guid>https://internetexception.com/2016/10/07/genereting-proxies-during-runtime-using-reflection-emit/</guid><description>&lt;p&gt;&lt;em&gt;Reflection.Emit&lt;/em&gt; is very powerful tool. It creates IL code and since C# is converted into IL too, we have the same functionality as in C# and even more. It is very powerful and at the same time very complicated. Because of that it is worth to discuss how and for what it should be used. One idea is to create dynamic code with automatic implementations of interfaces - proxy types.&lt;/p&gt;</description></item><item><title>Faster than Reflection: Delegates. Part 3.</title><link>https://internetexception.com/2016/09/02/faster-than-reflection-delegates-part-3/</link><pubDate>Fri, 02 Sep 2016 13:15:00 +0200</pubDate><guid>https://internetexception.com/2016/09/02/faster-than-reflection-delegates-part-3/</guid><description>&lt;p&gt;&lt;strong&gt;This is third article in series, that explains how to create delegates for public and non-public members of public, non-public or not known in compile-time types. If you are not familiar with previous articles and looking for detailed explanation of how delegates works, how they are created and why, I strongly encourage you to read first two. If you are just looking for a way to create delegates for methods or constructors it is not necessary.&lt;/strong&gt; Code with new features and with bug fixes is available on &lt;a href="https://github.com/npodbielski/Delegates" target="_blank" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;&#10; and as &lt;a href="https://www.nuget.org/packages/DelegatesFactory/1.0.0" target="_blank" rel="noopener noreferrer"&gt;Nuget&lt;/a&gt;&#10; package.&lt;/p&gt;</description></item><item><title>Faster than Reflection: Delegates. Part 2.</title><link>https://internetexception.com/2016/08/16/faster-than-reflection-delegates-part-2/</link><pubDate>Tue, 16 Aug 2016 12:59:00 +0200</pubDate><guid>https://internetexception.com/2016/08/16/faster-than-reflection-delegates-part-2/</guid><description>&lt;p&gt;&lt;strong&gt;This is second article in series, that explains how to create delegates for public and non-public members of public, non-public or not known in compile-time types. If you are not familiar with previous article and looking for detailed explanation of how delegates works, how they are created and why, I strongly encourage you to read it first. If you are just looking for a way to create delegates for methods or constructors it is not necessary.&lt;/strong&gt; Last article in series you can find &lt;a href="https://internetexception.com/2016/09/02/faster-than-reflection-delegates-part-3/" title="Third part"&gt;here&lt;/a&gt;&#10;. Code with new features and with bug fixes is available on &lt;a href="https://github.com/npodbielski/Delegates" target="_blank" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;&#10; and as &lt;a href="https://www.nuget.org/packages/DelegatesFactory/1.0.0" target="_blank" rel="noopener noreferrer"&gt;Nuget&lt;/a&gt;&#10; package. In previous &lt;a href="https://internetexception.com/2016/08/05/faster-than-reflection-delegates-part-1/"&gt;article&lt;/a&gt;&#10; and first one in series, we covered:&lt;/p&gt;&#10;&lt;ol&gt;&#10;&lt;li&gt;Static&#10;&lt;ol&gt;&#10;&lt;li&gt;Properties&lt;/li&gt;&#10;&lt;li&gt;Fields&lt;/li&gt;&#10;&lt;/ol&gt;&#10;&lt;/li&gt;&#10;&lt;li&gt;Instance&#10;&lt;ol&gt;&#10;&lt;li&gt;Properties&lt;/li&gt;&#10;&lt;li&gt;Fields&lt;/li&gt;&#10;&lt;li&gt;Indexers&lt;/li&gt;&#10;&lt;/ol&gt;&#10;&lt;/li&gt;&#10;&lt;/ol&gt;&#10;&lt;p&gt;Now it is time to cover following members.&lt;/p&gt;&#10;&lt;ol&gt;&#10;&lt;li&gt;Static&#10;&lt;ol&gt;&#10;&lt;li&gt;Methods&lt;/li&gt;&#10;&lt;/ol&gt;&#10;&lt;/li&gt;&#10;&lt;li&gt;Instance&#10;&lt;ol&gt;&#10;&lt;li&gt;Methods&lt;/li&gt;&#10;&lt;li&gt;Constructors&lt;/li&gt;&#10;&lt;/ol&gt;&#10;&lt;/li&gt;&#10;&lt;/ol&gt;</description></item><item><title>Faster than Reflection: Delegates. Part 1.</title><link>https://internetexception.com/2016/08/05/faster-than-reflection-delegates-part-1/</link><pubDate>Fri, 05 Aug 2016 09:58:00 +0200</pubDate><guid>https://internetexception.com/2016/08/05/faster-than-reflection-delegates-part-1/</guid><description>&lt;p&gt;This article is first part of the series of three. Next ones you can find &lt;a href="https://internetexception.com/2016/08/16/faster-than-reflection-delegates-part-2/" title="Second part"&gt;here&lt;/a&gt;&#10; and &lt;a href="https://internetexception.com/2016/09/02/faster-than-reflection-delegates-part-3/" title="Third part"&gt;here&lt;/a&gt;&#10;. Code for all three articles, with new features and bug fixes is available on &lt;a href="https://github.com/npodbielski/Delegates" target="_blank" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;&#10; and as &lt;a href="https://www.nuget.org/packages/DelegatesFactory/1.0.0" target="_blank" rel="noopener noreferrer"&gt;Nuget&lt;/a&gt;&#10; package.&lt;/p&gt;&#10;&lt;h3 id="why-not-reflection"&gt;Why not Reflection?&lt;/h3&gt;&#10;&lt;p&gt;If you working with .NET and C# (probably other languages too), at some point, you will have to write more advanced and generic code, that i.e. reads all properties of a type, searches for attributes, etc. Or maybe you want to call some private method or property? It is not that rare to use some internal mechanism of framework or library. Usually, the first solution involves Reflection. But the thing is: Reflection is slow. Of course, it is sufficient if you need to use Reflection rarely and it is not the main code of the application. If it is used more often at some point, you will probably try to optimize it. And now is the fun part: how to do it?&lt;/p&gt;</description></item><item><title>ViewFactory for Xamarin application</title><link>https://internetexception.com/2016/07/09/viewfactory-for-xamarin-application/</link><pubDate>Sat, 09 Jul 2016 12:37:00 +0200</pubDate><guid>https://internetexception.com/2016/07/09/viewfactory-for-xamarin-application/</guid><description>&lt;h2 id="first-things-first---why"&gt;First things first - Why?&lt;/h2&gt;&#10;&lt;p&gt;First of all I do not like how creating of views and navigation works in Xamarin. There is much boilerplate needed to just navigate from one page to another. Typically like in &lt;a href="https://developer.xamarin.com/guides/xamarin-forms/getting-started/introduction-to-xamarin-forms/#Navigation" target="_blank" rel="noopener noreferrer"&gt;Xamarin documentation&lt;/a&gt;&#10; we have to obtain &lt;code&gt;INavigation&lt;/code&gt; interface instance, create instance of a new page, create instance of view model and all dependencies it requires. When you page do not require view model things are real easy and Xamarin sample is just enough.&lt;/p&gt;</description></item><item><title>Xamarin Master-Detail Page</title><link>https://internetexception.com/2016/04/24/xamarin-master-detail-page/</link><pubDate>Sun, 24 Apr 2016 07:41:00 +0200</pubDate><guid>https://internetexception.com/2016/04/24/xamarin-master-detail-page/</guid><description>&lt;p&gt;This article as previous ones (&lt;a href="https://internetexception.com/2016/04/22/xamarin-frame-and-style-with-padding/"&gt;Frame With Padding&lt;/a&gt;&#10;, &lt;a href="https://internetexception.com/2016/04/22/xamarin-frame-and-disappearing-outline/"&gt;Frame Outline Problem&lt;/a&gt;&#10;, &lt;a href="https://internetexception.com/2016/04/22/xamarin-frame-and-disappearing-outline/"&gt;Inheritance from Implicit Styles&lt;/a&gt;&#10;) also will be about Xamarin. This time we will inspect Master-Detail page control/mechanism. You can find official documentation for this control &lt;a href="https://developer.xamarin.com/guides/xamarin-forms/user-interface/navigation/master-detail-page/" target="_blank" rel="noopener noreferrer"&gt;here&lt;/a&gt;&#10;. Quick spoiler: I never used this in any production application. Why? I will explain. Whole article will be to explain why this is just not worth your time. In this and subsequent articles I will introduce much better solution.&lt;/p&gt;</description></item><item><title>Xamarin Style based on implicit Style</title><link>https://internetexception.com/2016/04/22/xamarin-style-based-on-implicit-style/</link><pubDate>Fri, 22 Apr 2016 23:17:00 +0200</pubDate><guid>https://internetexception.com/2016/04/22/xamarin-style-based-on-implicit-style/</guid><description>&lt;p&gt;Next article about bugs in Xamarin will touch topic of Styles. Styles for all of controls not only Frame (and if you wondering why Frame you should check first two articles about Xamarin &lt;a href="https://internetexception.com/2016/04/22/xamarin-frame-and-style-with-padding/" title="Xamarin Frame and Style with Padding"&gt;here&lt;/a&gt;&#10; and &lt;a href="https://internetexception.com/2016/04/22/xamarin-frame-and-disappearing-outline/" title="Xamarin Frame and disappearing Outline"&gt;here)&lt;/a&gt;&#10;. First of all if you are using Styles in Xamarin you probably know how to define implicit styles. If not here is a sample:&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-xml" data-lang="xml"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nt"&gt;&amp;lt;Application.Resources&amp;gt;&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;lt;ResourceDictionary&amp;gt;&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;lt;Style&lt;/span&gt; &lt;span class="na"&gt;TargetType=&lt;/span&gt;&lt;span class="s"&gt;&amp;#34;Label&amp;#34;&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;lt;Setter&lt;/span&gt; &lt;span class="na"&gt;Property=&lt;/span&gt;&lt;span class="s"&gt;&amp;#34;FontSize&amp;#34;&lt;/span&gt; &lt;span class="na"&gt;Value=&lt;/span&gt;&lt;span class="s"&gt;&amp;#34;45&amp;#34;&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;lt;/Style&amp;gt;&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;lt;/ResourceDictionary&amp;gt;&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nt"&gt;&amp;lt;/Application.Resources&amp;gt;&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;</description></item><item><title>Xamarin Frame and disappearing Outline</title><link>https://internetexception.com/2016/04/22/xamarin-frame-and-disappearing-outline/</link><pubDate>Fri, 22 Apr 2016 13:00:00 +0200</pubDate><guid>https://internetexception.com/2016/04/22/xamarin-frame-and-disappearing-outline/</guid><description>&lt;p&gt;This is another article in mini series of Xamarin bugs and workarounds for them :) Previous one you can find &lt;a href="https://internetexception.com/2016/04/22/xamarin-frame-and-style-with-padding/" title="Xamarin Frame and Style with Padding"&gt;here&lt;/a&gt;&#10;. This one is again about Frame control. I promise that another one will be about something else B) Issue can be observed when you bind BackgroundColor property of Frame control and something will trigger change of view model source property binded to background color.&lt;/p&gt;</description></item><item><title>Xamarin Frame and Style with Padding</title><link>https://internetexception.com/2016/04/22/xamarin-frame-and-style-with-padding/</link><pubDate>Fri, 22 Apr 2016 05:10:00 +0200</pubDate><guid>https://internetexception.com/2016/04/22/xamarin-frame-and-style-with-padding/</guid><description>&lt;p&gt;If you are a bit advanced with Xamarin you should already now that there is possibility of styling your controls almost like in WPF. Almost, because there is a few strange bugs involving this. For example there is a problem with styling a Padding property in Frame. Consider following Xaml of Xamarin application (I tested it in Android):&lt;/p&gt;</description></item><item><title>Safe cast string to enum</title><link>https://internetexception.com/2014/02/25/safe-cast-string-to-enum-2/</link><pubDate>Tue, 25 Feb 2014 23:49:00 +0100</pubDate><guid>https://internetexception.com/2014/02/25/safe-cast-string-to-enum-2/</guid><description>&lt;p&gt;In on of my projects I had make an interface between database and web service in C# code. One of problem I had to face was need to cast strings to enumerable types, because of simple fact that database have no idea what is an &amp;rsquo;enum&amp;rsquo;. Yes simplest mapping between an enumeration and database type is integer. It is simplest but in my idea not best. For example I really do not remember (or do not WANT to remember) what is the meaning of 4 integer value in case of package shipment status.&lt;/p&gt;</description></item><item><title>Smart string builder</title><link>https://internetexception.com/2014/02/22/smart-string-builder/</link><pubDate>Sat, 22 Feb 2014 03:16:00 +0100</pubDate><guid>https://internetexception.com/2014/02/22/smart-string-builder/</guid><description>&lt;p&gt;In this rare times when I was writing code that suppose to create large string from smaller chunks and with some non string parameters I was using &lt;strong&gt;StringBuilder&lt;/strong&gt; class of course. Of course because string adding, or string concatenation is very costly when talking about memory utilization. It is because every time you do this:&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-csharp" data-lang="csharp"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;&amp;#34;Hello world!&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;+&lt;/span&gt; &lt;span class="s"&gt;&amp;#34;n&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;+&lt;/span&gt; &lt;span class="s"&gt;&amp;#34;How are you?&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;new string is created for every &amp;lsquo;+&amp;rsquo; operation in memory. Not a best way of doing strings creations. &lt;code&gt;StringBuilder&lt;/code&gt; is better because it do not creates strings until you call &lt;strong&gt;.&lt;/strong&gt;&lt;code&gt;ToString&lt;/code&gt; method of &lt;code&gt;StringBuilder&lt;/code&gt; class.&lt;/p&gt;</description></item><item><title>Expression parsing and nested properties</title><link>https://internetexception.com/2014/02/22/expression-parsing-and-nested-properties/</link><pubDate>Sat, 22 Feb 2014 03:00:00 +0100</pubDate><guid>https://internetexception.com/2014/02/22/expression-parsing-and-nested-properties/</guid><description>&lt;p&gt;In one of projects I was working on, I needed to get property value from property path and property path from expression. First, lets cover second case. With expression in form of nested property value:&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-csharp" data-lang="csharp"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;()=&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;object1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;object2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;object3&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;object4&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;we cannot take simple value of some property, because we have only root object, &lt;code&gt;object1&lt;/code&gt;.&lt;/p&gt;</description></item><item><title>WebSocket libraries comparison</title><link>https://internetexception.com/2014/02/21/websocket-libraries-comparison/</link><pubDate>Fri, 21 Feb 2014 14:38:00 +0100</pubDate><guid>https://internetexception.com/2014/02/21/websocket-libraries-comparison/</guid><description>&lt;p&gt;Web project often requires to push data to clients as fast as possible, whenever it is necessary without waiting for client request. It is perfect for website with real time communication between users, like with online communicators for example. Or document collaboration tools. Or maybe system status updates on long running calculation/tasks performed by server. In every case two way communication mechanism is ideal.&lt;/p&gt;</description></item><item><title>Ninject and WCF</title><link>https://internetexception.com/2013/05/26/ninject-and-wcf/</link><pubDate>Sun, 26 May 2013 12:01:00 +0200</pubDate><guid>https://internetexception.com/2013/05/26/ninject-and-wcf/</guid><description>&lt;p&gt;Ninject is very simple and in the same time powerful IoC container. I used it in few project and had very little or none problems. Most of the time getting instances from Ninject kernel requires simple line with binding expression, or even this is sometime unnecessary if type is self bind able (i.e. if it is concrete class with parameterless constructor). Little harder is getting Ninject to work with WCF. You cannot just bind interfaces types because proxies which implements them are created through .NET mechanism. Luckily WCF system is very flexible and mostly can be changed/extended with custom functionality.&lt;/p&gt;</description></item><item><title>Mapping collection of entities in EF with AutoMapper</title><link>https://internetexception.com/2013/05/25/mapping-collection-of-entities-in-ef-with-automapper/</link><pubDate>Sat, 25 May 2013 11:38:00 +0200</pubDate><guid>https://internetexception.com/2013/05/25/mapping-collection-of-entities-in-ef-with-automapper/</guid><description>&lt;p&gt;In my &lt;a href="https://internetexception.com/2013/05/16/entity-framework-and-base-entity-class/"&gt;last post&lt;/a&gt;&#10; I explained why is useful to add base entity class in EF. Today I will write how with use of this base class an AutoMapped map collection of data objects (i.e. DTOs to existing collection of entities).&lt;/p&gt;</description></item><item><title>Entity Framework and Base Entity class</title><link>https://internetexception.com/2013/05/16/entity-framework-and-base-entity-class/</link><pubDate>Thu, 16 May 2013 14:32:00 +0200</pubDate><guid>https://internetexception.com/2013/05/16/entity-framework-and-base-entity-class/</guid><description>&lt;p&gt;Entity Framework does great job with taking care of entities changes and entities collection internally. And its uses almost plain POCO objects. Almost because collections of dependents data like in 1 to many tables relationship needs virtual keyword. Its understandable since EF needs to track what happens to collection. For instance lets have 2 tables: Customer and dependent Order. &lt;a class="img-zoom" href="https://internetexception.com/wp-content/uploads/2013/05/customer_order.png"&gt;&lt;img&#10; src="https://internetexception.com/wp-content/uploads/2013/05/customer_order.png"&#10; alt=""&#10; &#10; loading="lazy" decoding="async"&gt;&lt;/a&gt;&lt;/p&gt;</description></item><item><title>Ninject and Entity Framework</title><link>https://internetexception.com/2013/05/03/ninject-and-entity-framework/</link><pubDate>Fri, 03 May 2013 03:50:00 +0200</pubDate><guid>https://internetexception.com/2013/05/03/ninject-and-entity-framework/</guid><description>&lt;p&gt;&lt;a href="https://internetexception.com/2013/04/23/entity-framework-patterns-extension-and-unit-test-in-visual-studio-2012/" target="_blank" rel="noopener noreferrer"&gt;Last time&lt;/a&gt; I wrote about problem with testing Entity Framework in Visual Studio 2012. During working on this project I also encounter problems with configuration of Ninject to allow injecting Entity Framework classes from its Patterns extension. To be frankly this was not much a problem then lack of documentation. I just was forced to experiment with Ninject and new-thing-for-me Entity Framework Patterns extension.&lt;/p&gt;</description></item><item><title>Curious Case of Visual Studio project compatibility.</title><link>https://internetexception.com/2013/02/12/curious-case-of-visual-studio-project-compatibility/</link><pubDate>Tue, 12 Feb 2013 08:06:00 +0100</pubDate><guid>https://internetexception.com/2013/02/12/curious-case-of-visual-studio-project-compatibility/</guid><description>&lt;p&gt;Recently I was asked at work for quick review of small project. It was created (or updated) in newest version of Visual Studio - 2012. I don&amp;rsquo;t have installed VS 2012. I could install it, yes, but it would be just waste of time since browsing through code in that project took me only few hours. So I decided to try to open that in VS 2010.&lt;/p&gt;</description></item><item><title>Using Matlab from C# application.</title><link>https://internetexception.com/2013/01/20/using-matlab-from-c-application/</link><pubDate>Sun, 20 Jan 2013 11:25:00 +0100</pubDate><guid>https://internetexception.com/2013/01/20/using-matlab-from-c-application/</guid><description>&lt;p&gt;While writing an application for my Masters degree diploma, I wrote a simple application that was using COM Matlab server. I have found it hard to use it mainly due to lack of documentation, which is really basic with only few code examples for C#. I guess writing programs that use Matlab for calculating is not encouraged by MathWorks, you would became competition that way :) Nonetheless, I accomplished why I was required to do, so I decided to share this with the rest of the world.&lt;/p&gt;</description></item><item><title>Server controls in separete assembly part 2</title><link>https://internetexception.com/2012/12/24/server-controls-in-separete-assembly-part-2/</link><pubDate>Mon, 24 Dec 2012 05:14:00 +0100</pubDate><guid>https://internetexception.com/2012/12/24/server-controls-in-separete-assembly-part-2/</guid><description>&lt;p&gt;&lt;a href="https://internetexception.com/2012/12/22/server-controls-in-separate-assembly/"&gt;Yesterday I was writing about creating server controls in separate assembly&lt;/a&gt;&#10;. Today I will cover more complicated example then simple &amp;ldquo;Hello World!&amp;rdquo; control. My goal was to create text box that will take handler method to run when validation event will be triggered, and when validation fail will show appropriate message. Text box with builtin validation would be nice, since &lt;a href="http://searchsoftwarequality.techtarget.com/tip/The-importance-of-input-validation" target="_blank" rel="noopener noreferrer"&gt;you always&lt;/a&gt;&#10; &lt;a href="http://www.ibm.com/developerworks/library/l-sp2/index.html" target="_blank" rel="noopener noreferrer"&gt;should&lt;/a&gt;&#10; &lt;a href="http://web.securityinnovation.com/appsec-weekly/blog/?Tag=Input%20and%20Data%20Validation" target="_blank" rel="noopener noreferrer"&gt;validate&lt;/a&gt;&#10; &lt;a href="http://www.securityninja.co.uk/secure-development/input-validation/" target="_blank" rel="noopener noreferrer"&gt;user input&lt;/a&gt;&#10;, right? But lets start creating our control.&lt;/p&gt;</description></item><item><title>Server controls in separate assembly</title><link>https://internetexception.com/2012/12/22/server-controls-in-separate-assembly/</link><pubDate>Sat, 22 Dec 2012 14:52:00 +0100</pubDate><guid>https://internetexception.com/2012/12/22/server-controls-in-separate-assembly/</guid><description>&lt;p&gt;In my project I wanted to create text box control with builtin configurable validation. ASP.NET definition in &lt;code&gt;.aspx&lt;/code&gt; or &lt;code&gt;.ascx&lt;/code&gt; file would get validation function by name. But I do not wanted to create just &lt;code&gt;.ascx&lt;/code&gt; file with text box. I could not then reuse that control in other projects and it certainly would be nice, right? Creating such server control from code is not hard, but maintainability of HTML code in C# (it cannot be done other way) is not good. It&amp;rsquo;s pain really. Why Microsoft would create way to automatically create C# code from &lt;code&gt;.ascx&lt;/code&gt;, &lt;code&gt;.aspx&lt;/code&gt; files is mystery for me.&lt;/p&gt;</description></item><item><title>Handling Ajax errors in ASP.NET</title><link>https://internetexception.com/2012/12/22/handling-ajax-errors-in-asp-net/</link><pubDate>Sat, 22 Dec 2012 09:58:00 +0100</pubDate><guid>https://internetexception.com/2012/12/22/handling-ajax-errors-in-asp-net/</guid><description>&lt;p&gt;Yesterday I wrote about &lt;a href="https://internetexception.com/2012/12/21/global-updatepanel-loading-indicator-in-asp-net/"&gt;issue with Ajax postbacks&lt;/a&gt;&#10; in application I am working currently. Problem was with buttons that was triggering &lt;code&gt;UpdatePanels&lt;/code&gt; to update asynchronously. After adding loading indicator I wanted to add error handling at client side.&lt;/p&gt;</description></item><item><title>Global UpdatePanel loading indicator in ASP.NET</title><link>https://internetexception.com/2012/12/21/global-updatepanel-loading-indicator-in-asp-net/</link><pubDate>Fri, 21 Dec 2012 10:48:00 +0100</pubDate><guid>https://internetexception.com/2012/12/21/global-updatepanel-loading-indicator-in-asp-net/</guid><description>&lt;p&gt;When I started working on application I am working right now, one of first things I noticed, that was not entirely wrong but was inconvenient: when user clicked on some button that triggers update panel you was not entirely sure it worked or not. Why? Because of three things:&lt;/p&gt;</description></item><item><title>Better algorithm for finding UpdatePanel that will be updated during page request.</title><link>https://internetexception.com/2012/12/13/better-algorithm-for-finding-updatepanel-that-will-be-updated-during-page-request/</link><pubDate>Thu, 13 Dec 2012 15:50:00 +0100</pubDate><guid>https://internetexception.com/2012/12/13/better-algorithm-for-finding-updatepanel-that-will-be-updated-during-page-request/</guid><description>&lt;p&gt;Other day I was experimenting with finding which &lt;a href="https://internetexception.com/2012/12/10/display-message-on-client-from-anywhere-in-code-with-asp-net/"&gt;UpdatePanel will be updated during page post back.&lt;/a&gt;&#10; I found out that my solution was not working correctly for complex triggers, like user controls with custom events, which will trigger async postbacks and update of panel. Or for grids with buttons. It was big issue. Also it was not pointing to correct &lt;code&gt;UpdatePanel&lt;/code&gt; if name of control was not entirely unique (for example when you have multiple same custom controls on page). It would return first panel, even if it wasn&amp;rsquo;t updating.&lt;/p&gt;</description></item><item><title>Display message on client from anywhere in code with ASP.NET</title><link>https://internetexception.com/2012/12/10/display-message-on-client-from-anywhere-in-code-with-asp-net/</link><pubDate>Mon, 10 Dec 2012 09:20:00 +0100</pubDate><guid>https://internetexception.com/2012/12/10/display-message-on-client-from-anywhere-in-code-with-asp-net/</guid><description>&lt;p&gt;When I was working with WinForms application in previous work I have found one of most useful feature, ability to show some message to the client. For example user cannot edit some entity in particular time (it is being edited by someone else) or should change password because it will expire in x days. I wanted to do something similar in my web application.&lt;/p&gt;</description></item><item><title>Getting private field or property from object</title><link>https://internetexception.com/2012/12/09/getting-private-field-or-property-from-object/</link><pubDate>Sun, 09 Dec 2012 07:26:00 +0100</pubDate><guid>https://internetexception.com/2012/12/09/getting-private-field-or-property-from-object/</guid><description>&lt;p&gt;Yesterday I was playing with finding all &lt;code&gt;UpdatePanel&lt;/code&gt; controls on page during generating response in ASP.NET. Since object with this information is private itself and collection of panels is private in that object, I had to write some code to extract that data. I ended up with to extension methods for &lt;code&gt;Object&lt;/code&gt; type, for getting private field an private property. It&amp;rsquo;s pretty straightforward, besides one thing: since member is private. And we don&amp;rsquo;t know in witch type exactly (every type in base/descendant hierarchy have it&amp;rsquo;s one private members) we have to search them all. So this is final code:&lt;/p&gt;</description></item></channel></rss>