<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>C# on Andrew Walsh</title><link>https://www.awalsh128.com/tags/c%23/</link><description>Recent content in C# on Andrew Walsh</description><generator>Hugo -- gohugo.io</generator><language>en-US</language><copyright>© 2026 Andrew Walsh</copyright><lastBuildDate>Wed, 30 Mar 2016 23:52:15 -0700</lastBuildDate><atom:link href="https://www.awalsh128.com/tags/c%23/feed.xml" rel="self" type="application/rss+xml"/><item><title>Streaming UUEncoder in .NET.</title><link>https://www.awalsh128.com/streaming-uuencoder-in-net/</link><pubDate>Fri, 24 Apr 2015 00:00:00 -0700</pubDate><guid>https://www.awalsh128.com/streaming-uuencoder-in-net/</guid><description>&lt;h3 class="relative group"&gt;Flashback&#10; &lt;div id="flashback" class="anchor"&gt;&lt;/div&gt;&#10; &#10; &lt;span&#10; class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;&#10; &lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#flashback" aria-label="Anchor"&gt;#&lt;/a&gt;&#10; &lt;/span&gt;&#10; &#10;&lt;/h3&gt;&#10;&lt;p&gt;The last time I used Unix-to-Unix format (AKA &lt;a href="http://en.wikipedia.org/wiki/Uuencoding" target="_blank" rel="noreferrer"&gt;UUEncoding&lt;/a&gt;) was when&#10;&lt;a href="http://en.wikipedia.org/wiki/Usenet" target="_blank" rel="noreferrer"&gt;USENET&lt;/a&gt; was still the big thing and&#10;&lt;a href="http://en.wikipedia.org/wiki/Mosaic_%28web_browser%29" target="_blank" rel="noreferrer"&gt;Mosaic web browser&lt;/a&gt; was just coming out. That was&#10;until recently, when I had a requirement to encode and decode this file type.&lt;/p&gt;</description></item><item><title>Log per class pattern.</title><link>https://www.awalsh128.com/log-per-class-pattern/</link><pubDate>Sun, 29 Mar 2015 00:00:00 -0700</pubDate><guid>https://www.awalsh128.com/log-per-class-pattern/</guid><description>&lt;h3 class="relative group"&gt;Rookie Moves&#10; &lt;div id="rookie-moves" class="anchor"&gt;&lt;/div&gt;&#10; &#10; &lt;span&#10; class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;&#10; &lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#rookie-moves" aria-label="Anchor"&gt;#&lt;/a&gt;&#10; &lt;/span&gt;&#10; &#10;&lt;/h3&gt;&#10;&lt;p&gt;Awhile ago, I had originally created a single logger for each service and shared it statically across the&#10;application.&lt;/p&gt;</description></item><item><title>Creating XML based templates in log4net.</title><link>https://www.awalsh128.com/creating-xml-based-templates-in-log4net/</link><pubDate>Sat, 28 Mar 2015 00:00:00 -0700</pubDate><guid>https://www.awalsh128.com/creating-xml-based-templates-in-log4net/</guid><description>&lt;h3 class="relative group"&gt;Motivation&#10; &lt;div id="motivation" class="anchor"&gt;&lt;/div&gt;&#10; &#10; &lt;span&#10; class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;&#10; &lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#motivation" aria-label="Anchor"&gt;#&lt;/a&gt;&#10; &lt;/span&gt;&#10; &#10;&lt;/h3&gt;&#10;&lt;p&gt;I decided to use &lt;a href="https://logging.apache.org/log4net/" target="_blank" rel="noreferrer"&gt;log4net&lt;/a&gt; for a recent project I had been working on.&#10;There is a concept of &lt;a href="https://logging.apache.org/log4net/release/manual/configuration.html#loggers" target="_blank" rel="noreferrer"&gt;loggers&lt;/a&gt;&#10;and &lt;a href="https://logging.apache.org/log4net/release/manual/configuration.html#appenders" target="_blank" rel="noreferrer"&gt;appenders&lt;/a&gt;. Loggers are&#10;composed of appenders and a log threshold. Appenders are consumers of logging information and provide specific&#10;implementations (eg. file, email, event log, database). You can configure the loggers and appenders either in&#10;the &lt;a href="https://logging.apache.org/log4net/release/manual/configuration.html" target="_blank" rel="noreferrer"&gt;application configuration&lt;/a&gt; or&#10;&lt;a href="http://www.roelvanlisdonk.nl/?p=723" target="_blank" rel="noreferrer"&gt;at runtime&lt;/a&gt;.&lt;/p&gt;</description></item><item><title>Using type converters for JSON.NET.</title><link>https://www.awalsh128.com/using-type-converters-for-jsonnet/</link><pubDate>Sat, 28 Mar 2015 00:00:00 -0700</pubDate><guid>https://www.awalsh128.com/using-type-converters-for-jsonnet/</guid><description>&lt;h3 class="relative group"&gt;Motivation&#10; &lt;div id="motivation" class="anchor"&gt;&lt;/div&gt;&#10; &#10; &lt;span&#10; class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;&#10; &lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#motivation" aria-label="Anchor"&gt;#&lt;/a&gt;&#10; &lt;/span&gt;&#10; &#10;&lt;/h3&gt;&#10;&lt;p&gt;I had these &lt;a href="http://en.wikipedia.org/wiki/Flyweight_pattern" target="_blank" rel="noreferrer"&gt;flyweights&lt;/a&gt; that added a lot of overhead to the&#10;&lt;a href="http://en.wikipedia.org/wiki/Serialization" target="_blank" rel="noreferrer"&gt;serialization&lt;/a&gt; process. They weren't really needed in the&#10;serialized payload either. In fact, I could recreate the flyweight in memory from just a single property on&#10;the object.&lt;/p&gt;</description></item><item><title>Using CC.NET &amp; Gallio for priority based smoke testing.</title><link>https://www.awalsh128.com/using-ccnet-gallio-for-priority-based/</link><pubDate>Fri, 17 Oct 2014 00:00:00 -0700</pubDate><guid>https://www.awalsh128.com/using-ccnet-gallio-for-priority-based/</guid><description>&lt;h3 class="relative group"&gt;Pitfalls in Production&#10; &lt;div id="pitfalls-in-production" class="anchor"&gt;&lt;/div&gt;&#10; &#10; &lt;span&#10; class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;&#10; &lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#pitfalls-in-production" aria-label="Anchor"&gt;#&lt;/a&gt;&#10; &lt;/span&gt;&#10; &#10;&lt;/h3&gt;&#10;&lt;p&gt;Being able to monitor&#10;&lt;a href="http://en.wikipedia.org/wiki/Development_environment_%28software_development_process%29" target="_blank" rel="noreferrer"&gt;production&lt;/a&gt; services&#10;for potential errors is critical. Especially if the services are dependant on external resources which may&#10;become unavailable or exhibit unexpected behavior. Even if you follow good software development discipline,&#10;this is always a source of concern. Think network outages, unannounced third party API changes, hosted&#10;services becoming unavailable, etc.&lt;/p&gt;</description></item><item><title>State behavioral pattern to the rescue.</title><link>https://www.awalsh128.com/state-behavioral-pattern-to-rescue/</link><pubDate>Mon, 17 Mar 2014 00:00:00 -0700</pubDate><guid>https://www.awalsh128.com/state-behavioral-pattern-to-rescue/</guid><description>&lt;h3 class="relative group"&gt;The Creeping Problem&#10; &lt;div id="the-creeping-problem" class="anchor"&gt;&lt;/div&gt;&#10; &#10; &lt;span&#10; class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;&#10; &lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#the-creeping-problem" aria-label="Anchor"&gt;#&lt;/a&gt;&#10; &lt;/span&gt;&#10; &#10;&lt;/h3&gt;&#10;&lt;p&gt;I recently found myself developing a request-response style system, where the lifetime of a request could be&#10;interrupted at any moment. For most same process execution, like your average desktop application, this is a&#10;concern, but arises more often when dealing with multiple coordinated processes. My case ended up being the&#10;latter.&lt;/p&gt;</description></item><item><title>PCAP-NG reader for .NET.</title><link>https://www.awalsh128.com/pcap-ng-reader-for-net/</link><pubDate>Wed, 10 Apr 2013 00:00:00 -0700</pubDate><guid>https://www.awalsh128.com/pcap-ng-reader-for-net/</guid><description>&lt;h3 class="relative group"&gt;Introduction &amp;amp; Scope&#10; &lt;div id="introduction--scope" class="anchor"&gt;&lt;/div&gt;&#10; &#10; &lt;span&#10; class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;&#10; &lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#introduction--scope" aria-label="Anchor"&gt;#&lt;/a&gt;&#10; &lt;/span&gt;&#10; &#10;&lt;/h3&gt;&#10;&lt;p&gt;The PCAP-NG file format is used to store network captured data used by great programs like&#10;&lt;a href="http://www.wireshark.org/download.html" target="_blank" rel="noreferrer"&gt;Wireshark&lt;/a&gt;. There are several API's available for both&#10;&lt;a href="http://www.tcpdump.org/" target="_blank" rel="noreferrer"&gt;Linux&lt;/a&gt; and &lt;a href="http://www.winpcap.org/" target="_blank" rel="noreferrer"&gt;Windows&lt;/a&gt; but none that are ported to .NET. I&#10;decided to &lt;a href="https://github.com/awalsh128/PcapngFile/" target="_blank" rel="noreferrer"&gt;make one&lt;/a&gt; for my own use in building a network traffic&#10;replay agent.&lt;/p&gt;</description></item><item><title>Reading and writing large binary data in T-SQL and ADO.NET.</title><link>https://www.awalsh128.com/reading-and-writing-large-binary-data/</link><pubDate>Wed, 03 Oct 2012 00:00:00 -0700</pubDate><guid>https://www.awalsh128.com/reading-and-writing-large-binary-data/</guid><description>&lt;h3 class="relative group"&gt;Introduction&#10; &lt;div id="introduction" class="anchor"&gt;&lt;/div&gt;&#10; &#10; &lt;span&#10; class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;&#10; &lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#introduction" aria-label="Anchor"&gt;#&lt;/a&gt;&#10; &lt;/span&gt;&#10; &#10;&lt;/h3&gt;&#10;&lt;p&gt;In some cases, you may want to read/write binary data from/to your relational database. This can be a problem&#10;when the data set size exceeds the memory address size (eg. 32-bit processes) or the&#10;&lt;a href="http://msdn.microsoft.com/en-us/magazine/cc534993.aspx" target="_blank" rel="noreferrer"&gt;managed large object heap&lt;/a&gt; cannot load it all without&#10;throwing an &lt;a href="http://msdn.microsoft.com/en-us/library/system.outofmemoryexception.aspx" target="_blank" rel="noreferrer"&gt;OutOfMemoryException&lt;/a&gt;.&#10;In those cases, you will need to load the data into memory in chunks. Fortunately, the&#10;&lt;a href="http://en.wikipedia.org/wiki/Transact-SQL" target="_blank" rel="noreferrer"&gt;T-SQL&lt;/a&gt; syntax supports this operation.&lt;/p&gt;</description></item><item><title>IMAPI version 2 managed wrapper.</title><link>https://www.awalsh128.com/imapi-version-2-managed-wrapper/</link><pubDate>Tue, 18 Sep 2012 00:00:00 -0700</pubDate><guid>https://www.awalsh128.com/imapi-version-2-managed-wrapper/</guid><description>&lt;h3 class="relative group"&gt;Introduction&#10; &lt;div id="introduction" class="anchor"&gt;&lt;/div&gt;&#10; &#10; &lt;span&#10; class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;&#10; &lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#introduction" aria-label="Anchor"&gt;#&lt;/a&gt;&#10; &lt;/span&gt;&#10; &#10;&lt;/h3&gt;&#10;&lt;p&gt;Microsoft&#10;&lt;a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa366450%28v=vs.85%29.aspx" target="_blank" rel="noreferrer"&gt;introduced native image mastering&lt;/a&gt;&#10;support in Vista, going forward. The library itself is not too complex but the latest version of the&#10;&lt;a href="http://en.wikipedia.org/wiki/Image_Mastering_API" target="_blank" rel="noreferrer"&gt;image mastering API (IMAPI)&lt;/a&gt; has some quirks. This is well&#10;documented by &lt;a href="http://www.codeproject.com/script/Membership/View.aspx?mid=208197" target="_blank" rel="noreferrer"&gt;Eric Haddan&lt;/a&gt; in his&#10;&lt;a href="http://www.codeproject.com/Articles/24544/Burning-and-Erasing-CD-DVD-Blu-ray-Media-with-C-an" target="_blank" rel="noreferrer"&gt;article&lt;/a&gt;&#10;describing how to build an interop file and use it from .NET.&lt;/p&gt;</description></item><item><title>Licensing using XML digital signing.</title><link>https://www.awalsh128.com/licensing-using-xml-digital-signing/</link><pubDate>Tue, 14 Aug 2012 00:00:00 -0700</pubDate><guid>https://www.awalsh128.com/licensing-using-xml-digital-signing/</guid><description>&lt;h3 class="relative group"&gt;Motivation&#10; &lt;div id="motivation" class="anchor"&gt;&lt;/div&gt;&#10; &#10; &lt;span&#10; class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;&#10; &lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#motivation" aria-label="Anchor"&gt;#&lt;/a&gt;&#10; &lt;/span&gt;&#10; &#10;&lt;/h3&gt;&#10;&lt;p&gt;One of the main concerns in any licensing implementation is that authored license files are coming from the&#10;trusted authority (ie. your company) and not some third party. This can be accomplished in software by&#10;encrypting and decrypting the license with a&#10;&lt;a href="http://en.wikipedia.org/wiki/Symmetric-key_algorithm" target="_blank" rel="noreferrer"&gt;single key&lt;/a&gt;, but symmetric&#10;&lt;a href="http://en.wikipedia.org/wiki/Key_management" target="_blank" rel="noreferrer"&gt;key storage&lt;/a&gt; can be cumbersome and have added complexity.&lt;/p&gt;</description></item><item><title>Converting thermocouple voltages to temperature.</title><link>https://www.awalsh128.com/converting-thermocouple-voltages-to/</link><pubDate>Wed, 25 Jul 2012 00:00:00 -0700</pubDate><guid>https://www.awalsh128.com/converting-thermocouple-voltages-to/</guid><description>&lt;h3 class="relative group"&gt;Background&#10; &lt;div id="background" class="anchor"&gt;&lt;/div&gt;&#10; &#10; &lt;span&#10; class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;&#10; &lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#background" aria-label="Anchor"&gt;#&lt;/a&gt;&#10; &lt;/span&gt;&#10; &#10;&lt;/h3&gt;&#10;&lt;p&gt;Unlike most sensors used in data acquisition, thermocouples do not have a linear mapping between their voltage&#10;and celcius values. This means that instead of factoring some scalar value against the data, in order to scale&#10;it to engineering units (eg. volts to acceleration), an&#10;&lt;a href="http://en.wikipedia.org/wiki/Thermocouple#Voltage.E2.80.93temperature_relationship" target="_blank" rel="noreferrer"&gt;experimentally derived equation&lt;/a&gt;&#10;must be created to approximate the temperature at specific voltages. This non-linearity is primarily due to&#10;the materials being used to discover the temperature difference.&lt;/p&gt;</description></item><item><title>WPF and data multithreading deadlocks.</title><link>https://www.awalsh128.com/wpf-and-data-multithreading-deadlocks/</link><pubDate>Wed, 21 Dec 2011 00:00:00 -0800</pubDate><guid>https://www.awalsh128.com/wpf-and-data-multithreading-deadlocks/</guid><description>&lt;h2 class="relative group"&gt;WPF &amp;amp; Multithreading&#10; &lt;div id="wpf--multithreading" class="anchor"&gt;&lt;/div&gt;&#10; &#10; &lt;span&#10; class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;&#10; &lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#wpf--multithreading" aria-label="Anchor"&gt;#&lt;/a&gt;&#10; &lt;/span&gt;&#10; &#10;&lt;/h2&gt;&#10;&lt;p&gt;In designing applications, it may be advantageous to run data processing methods on a separate thread from the&#10;UI. This allows greater responsiveness in the application and takes advantage of concurrent computation.&lt;/p&gt;</description></item><item><title>EF 4.1 Code First: Many one-to-one properties for same class type on an object.</title><link>https://www.awalsh128.com/ef-41-code-first-many-one-to-one/</link><pubDate>Wed, 05 Oct 2011 00:00:00 -0700</pubDate><guid>https://www.awalsh128.com/ef-41-code-first-many-one-to-one/</guid><description>&lt;p&gt;I just started using the Entity Framework recently to employ persistence for an already established code base.&#10;Initially I was using the &amp;quot;Model &amp;amp; Database First&amp;quot; paradigm where a designer is used to layout the data&#10;model. Although, this ended up being tedious since my&#10;&lt;a href="http://en.wikipedia.org/wiki/Plain_Old_CLR_Object" target="_blank" rel="noreferrer"&gt;POCO&lt;/a&gt; instance had to exactly match the&#10;&lt;a href="http://msdn.microsoft.com/en-us/library/dd456853.aspx" target="_blank" rel="noreferrer"&gt;POCO proxy&lt;/a&gt; instance in my model designer view. After&#10;upgrading to EF 4.1, I realized the&#10;&lt;a href="http://blogs.msdn.com/b/adonet/archive/2011/09/13/ef-code-first-fluent-api-with-vb-net.aspx" target="_blank" rel="noreferrer"&gt;&amp;quot;Code First&amp;quot; paradigm&lt;/a&gt;&#10;was the way to go since I had to adapt the persistence model to my already existing code.&lt;br&gt;&#10;&lt;br&gt;&#10;One of the earliest problems that I ran into was having more than one property on a class that referenced the&#10;same class type. This example was taken from&#10;&lt;a href="http://weblogs.asp.net/manavi/archive/2011/03/28/associations-in-ef-4-1-code-first-part-2-complex-types.aspx" target="_blank" rel="noreferrer"&gt;a great site&lt;/a&gt;&#10;that explored the different EF properties.&lt;br&gt;&#10;[]{.Apple-style-span style=&amp;ldquo;background-color: #f8f8f8; color: #2e2e2e; font-family: &amp;lsquo;Courier New&amp;rsquo;, Courier,&#10;mono; font-size: 12px;&amp;rdquo;}\&lt;/p&gt;</description></item><item><title>Writing a TEDS (IEEE 1451.4) parser.</title><link>https://www.awalsh128.com/writing-teds-ieee-14514-parser/</link><pubDate>Wed, 17 Aug 2011 00:00:00 -0700</pubDate><guid>https://www.awalsh128.com/writing-teds-ieee-14514-parser/</guid><description>&lt;p&gt;I was tasked recently with writing a parser for TEDS bit stream data. There is an&#10;&lt;a href="http://standards.ieee.org/develop/regauth/tut/teds.pdf" target="_blank" rel="noreferrer"&gt;IEEE published paper&lt;/a&gt; with an overview of the&#10;standard but it doesn't give any examples for implementation. I was finally able to find a&#10;&lt;a href="http://standards.ieee.org/develop/regauth/tut/tdl.pdf" target="_blank" rel="noreferrer"&gt;paper&lt;/a&gt; that gave examples but still had trouble&#10;parsing the data. I finally realized there is not only 2 selector bits after the basic TEDS block but selector&#10;bits inside the standard template (2 in the case of template 25). Here are my main findings:&lt;br&gt;&#10;\&lt;/p&gt;</description></item><item><title>Reentrant lock acquires in CLR.</title><link>https://www.awalsh128.com/reentrant-lock-acquires-in-clr/</link><pubDate>Fri, 29 Jul 2011 00:00:00 -0700</pubDate><guid>https://www.awalsh128.com/reentrant-lock-acquires-in-clr/</guid><description>&lt;p&gt;I always like when a post gets to the point (especially after searching in Google). In short,&#10;&lt;em&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms741870.aspx" target="_blank" rel="noreferrer"&gt;if you perform an operation that waits to acquire a lock, the thread doesn't actually stop&lt;/a&gt;&lt;/em&gt;.&lt;br&gt;&#10;&lt;br&gt;&#10;In&#10;concrete terms of .NET coding, if you call the&#10;&lt;a href="http://msdn.microsoft.com/en-us/library/system.threading.waithandle.waitone.aspx" target="_blank" rel="noreferrer"&gt;WaitOne&lt;/a&gt; method on a&#10;thread, it may still process events that the CLR deems &amp;quot;high priority&amp;quot;. This can be a big problem if the&#10;event handlers go into the critical region you are trying to protect.&lt;br&gt;&#10;\&lt;/p&gt;</description></item></channel></rss>