<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Marcin Mikołajczak a.k.a. TripleEmcoder</title>
	<atom:link href="https://tripleemcoder.com/feed/" rel="self" type="application/rss+xml" />
	<link>https://tripleemcoder.com</link>
	<description>An attempt at blogging - SymbolSource, .NET and other matters</description>
	<lastBuildDate>Sun, 04 Oct 2015 19:43:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<site xmlns="com-wordpress:feed-additions:1">29399775</site><cloud domain='tripleemcoder.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>https://s0.wp.com/i/buttonw-com.png</url>
		<title>Marcin Mikołajczak a.k.a. TripleEmcoder</title>
		<link>https://tripleemcoder.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="https://tripleemcoder.com/osd.xml" title="Marcin Mikołajczak a.k.a. TripleEmcoder" />
	<atom:link rel='hub' href='https://tripleemcoder.com/?pushpress=hub'/>
	<item>
		<title>Moving to the new SymbolSource engine</title>
		<link>https://tripleemcoder.com/2015/10/04/moving-to-the-new-symbolsource-engine/</link>
					<comments>https://tripleemcoder.com/2015/10/04/moving-to-the-new-symbolsource-engine/#comments</comments>
		
		<dc:creator><![CDATA[TripleEmcoder]]></dc:creator>
		<pubDate>Sun, 04 Oct 2015 19:32:26 +0000</pubDate>
				<category><![CDATA[Debugging]]></category>
		<category><![CDATA[NuGet]]></category>
		<category><![CDATA[SymbolSource]]></category>
		<guid isPermaLink="false">http://tripleemcoder.com/?p=220</guid>

					<description><![CDATA[A few months ago I promised we would be launching a new version of SymbolSource. Today I&#8217;m very happy to make the first part of the new service public, the one you&#8217;ve been waiting for most impatiently. A new package repository has been deployed to production at https://nuget.smbsrc.net and contains all packages from https://www.symbolsource.org/Public/Metadata/NuGet (around [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>A few months ago I promised we would be launching a new version of SymbolSource. Today I&#8217;m very happy to make the first part of the new service public, the one you&#8217;ve been waiting for most impatiently.</p>
<p>A new package repository has been deployed to production at <a href="https://nuget.smbsrc.net">https://nuget.smbsrc.net</a> and contains all packages from <a href="https://www.symbolsource.org/Public/Metadata/NuGet">https://www.symbolsource.org/Public/Metadata/NuGet</a> (around 50 thousand of them!). In other words this is the new complementary service to <a href="https://www.nuget.org">https://www.nuget.org</a>, running on a codebase rewritten from scratch &#8211; something we needed to do to solve all of the performance issues you have been facing with SymbolSource in the past.</p>
<p>What about the SymbolSource repository for MyGet, or the other company instances, you might ask? Those will be migrated to the new service too, and I will report as soon as we will have done that.</p>
<p>For now let&#8217;s see how the new service operates. You can try all of these commands yourself, and update all of your scripts and debuggers accordingly.</p>
<h2>Publishing a symbol package</h2>
<p>To push a symbol package run this command:</p>
<pre>&gt; nuget push SymbolSource.DemoLibrary-1.0.0.0.nupkg a0f4e24d-851f-4327-a9ec-181d335e7e95 -source https://nuget.smbsrc.net
Pushing SymbolSource.DemoLibrary 1.0.0.0 to 'https://nuget.smbsrc.net'...
Your package was pushed.</pre>
<p>The command will succeed immediately without any timeouts, it just sends data to Azure storage. Packages are queued and processed asynchronously. That means that you will need to wait a bit before the symbols and sources become available, but we&#8217;ll be monitoring the queue length to make sure it never takes more than a few minutes.</p>
<p>Waiting and refreshing isn&#8217;t much fun, so we included a simple notification service, which you can use directly from the command prompt. Just append your Twitter username to the API key after a slash, like  this:</p>
<pre>&gt; nuget push SymbolSource.DemoLibrary-1.0.0.0.nupkg a0f4e24d-851f-4327-a9ec-181d335e7e95/@TripleEmcoder -source https://nuget.smbsrc.net
Pushing SymbolSource.DemoLibrary 1.0.0.0 to 'https://nuget.smbsrc.net'...
Your package was pushed.</pre>
<p>You&#8217;ll get tweeted by our friendly <a href="https://twitter.com/smbsrc">SymbolSource Bot (@smbsrc)</a> when the package starts processing and when it finishes. The tweet will also tell you if anything went wrong, in which case <a href="https://twitter.com/SymbolSource">@SymbolSource</a> will also be mentioned to alert us about the issue.</p>
<div class="embed-twitter">
<blockquote class="twitter-tweet" data-width="550" data-dnt="true">
<p lang="en" dir="ltr"><a href="https://twitter.com/TripleEmcoder?ref_src=twsrc%5Etfw">@TripleEmcoder</a> thanks for submitting SymbolSource.DemoLibrary/1.0.0.0-at-0E8H51 &#8211; I just started processing</p>
<p>&mdash; SymbolSource Bot (@smbsrc) <a href="https://twitter.com/smbsrc/status/650727440709472256?ref_src=twsrc%5Etfw">October 4, 2015</a></p></blockquote>
<p><script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script></div>
<div class="embed-twitter">
<blockquote class="twitter-tweet" data-width="550" data-dnt="true">
<p lang="en" dir="ltr"><a href="https://twitter.com/TripleEmcoder?ref_src=twsrc%5Etfw">@TripleEmcoder</a> good news &#8211; I just finished processing SymbolSource.DemoLibrary/1.0.0.0-at-0E8H51</p>
<p>&mdash; SymbolSource Bot (@smbsrc) <a href="https://twitter.com/smbsrc/status/650727452352843780?ref_src=twsrc%5Etfw">October 4, 2015</a></p></blockquote>
<p><script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script></div>
<p>One thing you&#8217;ll notice immediately is that we&#8217;ve added a suffix to the version number. Each upload to SymbolSource is identified separately. We then do a form of reference counting on all of the symbols and sources, so there is no cost to that. But in case you upload different builds with the same version number, all of them will be available to clients. Unless of course you decide to delete a package. Which is now a fully supported self-service operation!</p>
<h2>Deleting a symbol package</h2>
<p>If you know the SymbolSource version string of your package, deleting is as simple as running this command:</p>
<pre>&gt; nuget delete SymbolSource.DemoLibrary 1.0.0.0-at-0E8H51 a0f4e24d-851f-4327-a9ec-181d335e7e95/@TripleEmcoder -source https://nuget.smbsrc.net
Deleting SymbolSource.DemoLibrary 1.0.0.0-at-0E8H51 from the 'https://nuget.smbsrc.net'.
SymbolSource.DemoLibrary 1.0.0.0-at-0E8H51 was deleted successfully.</pre>
<p>Once again NuGet will lie a bit, as this is an asynchronous operation. But you will get the same friendly tweets if you include your username with the API key, as I did above.</p>
<div class="embed-twitter">
<blockquote class="twitter-tweet" data-width="550" data-dnt="true">
<p lang="en" dir="ltr"><a href="https://twitter.com/TripleEmcoder?ref_src=twsrc%5Etfw">@TripleEmcoder</a> good news &#8211; I just finished deleting SymbolSource.DemoLibrary/1.0.0.0-at-0E8H51</p>
<p>&mdash; SymbolSource Bot (@smbsrc) <a href="https://twitter.com/smbsrc/status/650729752869892096?ref_src=twsrc%5Etfw">October 4, 2015</a></p></blockquote>
<p><script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script></div>
<p>But what if you didn&#8217;t push with Twitter notifications enabled, and are now at a loss as to what the version string is? No worries, you can query SymbolSource as any other package source and find out what the version is.</p>
<p>Before we talk about that, however, if you really want to remove your content from SymbolSource, run this too:</p>
<pre>&gt; nuget delete SymbolSource.DemoLibrary 1.0.0.0-at-0E8H51 a0f4e24d-851f-4327-a9ec-181d335e7e95 -source https://nuget.smbsrc.net/,all,original
Deleting SymbolSource.DemoLibrary 1.0.0.0-at-0E8H51 from the 'https://nuget.smbsrc.net'.
SymbolSource.DemoLibrary 1.0.0.0-at-0E8H51 was deleted successfully.</pre>
<p>SymbolSource saves a copy of all uploaded packages, in case there is a change in the indexing algorithm and we need to reprocess. They are hosted in <em>subfeed</em> called <em>original </em>&#8211; see below for an explanation of what that is.</p>
<h2>Listing symbol packages</h2>
<p>By now you probably have already guessed the command to list packages from SymbolSource:</p>
<pre>&gt; nuget list SymbolSource.DemoLibrary -source https://nuget.smbsrc.net
No packages found.</pre>
<p>Well, that result might seem unexpected. But remember that we added an additional version string and therefore promoted all packages to semantic versioning. NuGet treats those as prerelease packages. A quick fix:</p>
<pre>&gt; nuget list SymbolSource.DemoLibrary -prerelease -source https://nuget.smbsrc.net
SymbolSource.DemoLibrary 1.0.0.0-at-0E8GM1</pre>
<p>There it is! Just remember about that NuGet will only show the most recent package, but you can show all of the uploads:</p>
<pre>&gt; nuget list SymbolSource.DemoLibrary -prerelease -allversions -source https://nuget.smbsrc.net
SymbolSource.DemoLibrary 1.0.0.0-at-0E2NAN
SymbolSource.DemoLibrary 1.0.0.0-at-0E8G1E
SymbolSource.DemoLibrary 1.0.0.0-at-0E8GM1</pre>
<p>All of this works in <a href="https://npe.codeplex.com">NuGet Package Explorer</a> too! As an exercise try downloading one of those packages. What you will get is a status package, useful in determining what symbols and source actually have been indexed by SymbolSource. More on this next time.</p>
<p>And in case you&#8217;re wondering&#8230; That version string is just a timestamp, encoded into an alphabet-based number system to save length. Unfortunately NuGet imposes a 20-character limit on all semantic versions.</p>
<h2>Advanced listing by status and ownership</h2>
<p>In my last post I also mentioned <em>subfeeds</em>, which let you query by status and ownership. To recap here are all of the statuses &#8211; they&#8217;ve slightly changed since our original spec:</p>
<ul>
<li><code>new</code> – not yet opened, random package name and unknown version,</li>
<li><code>original</code> – a copy of the uploaded package, without any processing, useful if we improve the indexer and need to resubmit packages without any users’ actions,</li>
<li><code>indexingqueued</code> – indexing will soon start asynchronously,</li>
<li><code>indexing</code> – processing is in progress as you are looking at the list,</li>
<li><code>succeeded</code> – the package has been indexed without any issues,</li>
<li><code>deletingqueued</code> – deleting with soon start asynchronously,</li>
<li><code>deleting</code> – deleting is in progress as you are looking at the list,</li>
<li><code>deleted</code> – the package has been completely removed from the index,</li>
<li><code>partial</code> – something went wrong, either during indexing or deleting, and some symbols and sources might be available, but some may not,</li>
<li><code>damagednew</code> &#8211; package could not be read with a standard NuGet library,</li>
<li><code>damagedindexing</code>, <code>damageddeleting</code> &#8211; these will probably indicate an error in SymbolSource.</li>
</ul>
<p>For example, if you wanted to confirm that a package has been deleted, you would need to run this command:</p>
<pre>&gt; nuget list SymbolSource.DemoLibrary -prerelease -allversions -source https://nuget.smbsrc.net/,all,deleted
SymbolSource.DemoLibrary 1.0.0.0-at-0D9I8Z
SymbolSource.DemoLibrary 1.0.0.0-at-0D9I90
SymbolSource.DemoLibrary 1.0.0.0-at-0E8H51</pre>
<p>As you can see, the list contains a package we did delete a few paragraph earlier &#8211; version 1.0.0.0-at-0E8H51. There are however also some old versions, which I deleted before writing this post. I can now delete them again, sort of, to simply remove the status package. Note that at this point symbols and sources have already been deleted, this is just similar to cleaning log files:</p>
<pre>&gt; nuget delete SymbolSource.DemoLibrary 1.0.0.0-at-0E8H51 a0f4e24d-851f-4327-a9ec-181d335e7e95 -source https://nuget.smbsrc.net/
Deleting SymbolSource.DemoLibrary 1.0.0.0-at-0E8H51 from the 'https://nuget.smbsrc.net/'.
Failed to process request. 'Not Found'.
The remote server returned an error: (404) Not Found..</pre>
<p>A 404 error is a bit odd, isn&#8217;t it? Well not exactly. Remember, we have already deleted this package. It doesn&#8217;t show in the feed. To remove the status package we need to address the <em>subfeed</em> specifically.</p>
<pre>&gt; nuget delete SymbolSource.DemoLibrary 1.0.0.0-at-0E8H51 a0f4e24d-851f-4327-a9ec-181d335e7e95 -source https://nuget.smbsrc.net/,all,deleted
Deleting SymbolSource.DemoLibrary 1.0.0.0-at-0E8H51 from the 'https://nuget.smbsrc.net/,all,deleted'.
SymbolSource.DemoLibrary 1.0.0.0-at-0E8H51 was deleted successfully.</pre>
<p>If you don&#8217;t specify a <em>subfeed</em> at all, SymbolSource defaults to <em>succeeded</em> state and <em>all</em> packages (as opposed to <em>own</em> packages). The first comma separates the feed name, which in case of nuget.org is empty. Things will be different for myget.org, but more on that in a future post.</p>
<p>So far we have listed all packages, regardless of who uploaded them. Of course pushing and deleting is permitted according to nuget.org package ownership. But you can also limit the packages listed by a query, using the following command:</p>
<pre>nuget list -prerelease -allversions -source https://nuget.smbsrc.net/,own,succeded
Please provide credentials for: https://nuget.smbsrc.net/,own,succeded
UserName: @TripleEmcoder
Password: ************************************
SymbolSource.DemoLibrary 1.0.0.0-at-0E2NAN
SymbolSource.DemoLibrary 1.0.0.0-at-0E8G1E
SymbolSource.DemoLibrary 1.0.0.0-at-0E8GM1</pre>
<p>SymbolSource will ask for credentials this time, as it needs to known who the user is, to list only the right packages. You can pass anything as the username, but if you give us something meaningfull like a Twitter handle, we will be able to get back to you in case of problems. The password is your NuGet API key.</p>
<h2>Debugging in Visual Studio</h2>
<p>And last, but not least, the new URL for Visual Studio is&#8230;</p>
<pre>https://nuget.smbsrc.net</pre>
<p>Just replace the old symbolsource.org URL in your Visual Studio options and you&#8217;re done. Happy (and fast) debugging <img src="https://s0.wp.com/wp-content/mu-plugins/wpcom-smileys/twemoji/2/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
<h2>Wrapping it up</h2>
<p>In this post I described the core features of our new SymbolSource engine. I hope you will find the new service much faster and much more stable than the previous one. We will be gradually upgrading other parts of the service over the next weeks and months. If you have any questions or feedback please leave them in the comment section.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://tripleemcoder.com/2015/10/04/moving-to-the-new-symbolsource-engine/feed/</wfw:commentRss>
			<slash:comments>4</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">220</post-id>
		<media:content url="https://0.gravatar.com/avatar/f4638cd124749b4d58d8889ea7777fb7eb81aea61ff5427999e47fe54448d3b6?s=96&#38;d=https%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">tripleemcoder</media:title>
		</media:content>
	</item>
		<item>
		<title>Designing a new SymbolSource</title>
		<link>https://tripleemcoder.com/2015/03/02/designing-a-new-symbolsource/</link>
					<comments>https://tripleemcoder.com/2015/03/02/designing-a-new-symbolsource/#comments</comments>
		
		<dc:creator><![CDATA[TripleEmcoder]]></dc:creator>
		<pubDate>Mon, 02 Mar 2015 20:39:18 +0000</pubDate>
				<category><![CDATA[NuGet]]></category>
		<category><![CDATA[SymbolSource]]></category>
		<guid isPermaLink="false">http://tripleemcoder.com/?p=207</guid>

					<description><![CDATA[A long, long time ago It&#8217;s been a long time since I have written here, and it&#8217;s been an equally long time since we have made any visible improvements to SymbolSource. Part of the reason is that Kamil and I have both been involved in building an EHR (electronic health record) webapp for the Polish [&#8230;]]]></description>
										<content:encoded><![CDATA[<h2>A long, long time ago</h2>
<p>It&#8217;s been a long time since I have written here, and it&#8217;s been an equally long time since we have made any visible improvements to SymbolSource. Part of the reason is that Kamil and I have both been involved in building an EHR (electronic health record) webapp for the Polish outpatient care market. Well, <em>involved</em> doesn&#8217;t really cut it, that startup has been more or less our entire life for three years. But now I can say, not without a lot of pride, that we have successfully led the project out of the startup phase. If you&#8217;re interested in what we have managed to build, visit <a href="http://www.mediporta.pl">www.mediporta.pl</a>. (The website only has a Polish version at the moment.)</p>
<p>We also might not have seemed very responsive when contacted with issues, but we have never stopped reading and noting all the feedback that we received. It has been very hard to reply, when the current SymbolSource architecture has not given us many options of implementing improvements. When we started the project, there was no Azure, no NuGet (yes!) and normalized SQL databases ruled the Earth. That resulted in quite a few mediocre decisions, looking back today.</p>
<p>Those times have passed, however, and it&#8217;s time to loose the excuses and make things better.</p>
<h2>Before we begin</h2>
<p>If you are not familiar with what purpose SymbolSource serves, or how it works, first have a look at the official Wiki:</p>
<ul>
<li><a href="http://docs.nuget.org/create/creating-and-publishing-a-symbol-package" rel="nofollow">http://docs.nuget.org/create/creating-and-publishing-a-symbol-package</a></li>
<li><a href="http://www.symbolsource.org/Public/Wiki/Index" rel="nofollow">http://www.symbolsource.org/Public/Wiki/Index</a></li>
</ul>
<h2>Back to drawing board</h2>
<p>A few months ago we have started talking about a total rewrite of SymbolSource, and even with the limited time we could have spared, we have made good progress in designing a new, scalable architecture for the service. It will enable us to support many different scenarios with the best possible performance:</p>
<ul>
<li>a public symbol repository for <a href="http://nuget.org">nuget.org</a>,</li>
<li>public and private feeds integrated with <a href="http://myget.org">myget.org</a>,</li>
<li>hosted instances deployed in our Azure subscription,</li>
<li>instances deployed in private Azure subscriptions,</li>
<li>on-premise instances integrated with Active Directory.</li>
</ul>
<p>But today I don&#8217;t want to talk about architecture, as it is more or less irrelevant when a service performs well. Today I&#8217;d like to share with you how we see the most basic form of interaction with the new SymbolSource &#8211; pushing and managing packages.</p>
<p>Consider this post a spec which, although already implemented, isn&#8217;t yet available publicly for testing. We are looking forward to any questions and comments!</p>
<h2>Pushing a package</h2>
<p>Pushing to the public repository:</p>
<p><code>nuget.exe push NHibernate.4.0.3.4000.symbols.nupkg 8ac00d48-a8e8-48e4-bb40-4fc92f18e15c -source http://nuget.smbsrc.net</code></p>
<p>Pushing to a named feed integrated with MyGet:</p>
<p><code>nuget.exe push EntityFramework.6.1.4-alpha1-40301.symbols.nupkg 60b1845b-116f-4eb0-8086-f96acaae46d7 -source http://myget.smbsrc.net/aspnetwebstacknightly</code></p>
<p>As a part of our effort to improve SymbolSource performance, we have decided to make all package operations asynchronous, which means that a successful push will only acknowledge that the package was received correctly. Read on to see how to determine the true package status.</p>
<h2>Listing packages in various states</h2>
<p>If all is well, you should see the package listed in the feed:</p>
<p><code>nuget.exe list -source http://nuget.smbsrc.net -allversions -prerelease</code></p>
<p>The list of packages will be similar to the following:</p>
<ul>
<li>NHibernate 4.0.3.4000-smbsrc150302193927</li>
</ul>
<p>Note that SymbolSource has automatically added a SemVer compatible version suffix. It uniquely identifies each package upload with a timestamp. There is no guarantee that two packages with identical versions don&#8217;t have different symbol files inside. That&#8217;s why we process them independently.</p>
<p>You can probably see why the extra options to nuget.exe are needed:</p>
<ul>
<li><code>-prerelease</code> shows packages with the <code>smbsrc</code> suffix,</li>
<li><code>-allversions</code> disables skipping earlier uploads.</li>
</ul>
<p>What if a previous upload was accidental? Read on for instructions on how to delete a package.</p>
<h2>Deleting a package</h2>
<p>Removing a package &#8211; and all of its symbols and sources! &#8211; will be as simple as issueing:</p>
<p><code>nuget.exe delete NHibernate 4.0.3.4000-smbsrc150302193927 8ac00d48-a8e8-48e4-bb40-4fc92f18e15c -source http://nuget.smbsrc.net</code></p>
<p>Again, this operation is asynchronous. A success message from <code>nuget.exe</code> will only tell you that the package has been found and correctly queued for deletion.</p>
<h2>Determining other states</h2>
<p>The new SymbolSource will also introduce a concept of <em>subfeeds</em>, which will let users list packages in various states. The list command showed earlier targets the default subfeed, which is <code>own,succeded</code>. You will be able to explicitly target:</p>
<ul>
<li>ownership &#8211; currently <code>own</code> or <code>all</code> (subject to permissions),</li>
<li>state &#8211; one of <code>success</code>, <code>partial</code>, <code>indexing</code> and so on.</li>
</ul>
<p>Here&#8217;s an example of listing all failed packages in the default feed as an administrator of the Caliper company instance:</p>
<p><code>nuget.exe list -source http://caliper.smbsrc.net/,all,partial -allversions -prerelease</code></p>
<p>The meaning of the various states is as follows:</p>
<ul>
<li><code>new</code> &#8211; not yet opened, random package name and unknown version,</li>
<li><code>original</code> &#8211; a copy of the uploaded package, without any processing, useful if we improve the indexer and need to resubmit packages without any users&#8217; actions,</li>
<li><code>damaged</code> &#8211; package could not be read with a standard NuGet library,</li>
<li><code>indexingqueued</code> &#8211; indexing will soon start asynchronously,</li>
<li><code>indexing</code> &#8211; processing is in progress as you are looking at the list,</li>
<li><code>succeeded</code> &#8211; the package has been indexed without any issues,</li>
<li><code>deletingqueued</code> &#8211; deleting with soon start asynchronously,</li>
<li><code>deleting</code> &#8211; deleting is in progress as you are looking at the list,</li>
<li><code>deleted</code> &#8211; the package has been completely removed from the index,</li>
<li><code>partial</code> &#8211; something went wrong, either during indexing or deleting, and some symbols and sources might be available, but some may not.</li>
</ul>
<h2>If listing is possible&#8230; is downloading too?</h2>
<p>Yes! Just as for any other NuGet package:</p>
<p><code>nuget.exe install NHibernate -version 4.0.3.4000-smbsrc150302193927 -source http://nuget.smbsrc.net</code></p>
<p>But you might be surprised by the results. Remember that when no subfeed is specified, you target the <code>succeeded</code> state. Packages in that state have no content, but status files instead! I will blog more about this in a future post. At the moment these are JSON files that specify what symbols and sources where detected and whether they have been uploaded to permanent storage. If there were any problems, a package will be listed in the <code>partial</code> state, and the status files will provide error messages.</p>
<p>By the way, since the JSON status files have complete information about indexed symbols and sources, we can delete a package entirely based only on those, without hitting any database at all. A big win performance-wise!</p>
<h2>Time for some feedback</h2>
<p>What do you think about the scheme that we designed? Please share your thoughts.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://tripleemcoder.com/2015/03/02/designing-a-new-symbolsource/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">207</post-id>
		<media:content url="https://0.gravatar.com/avatar/f4638cd124749b4d58d8889ea7777fb7eb81aea61ff5427999e47fe54448d3b6?s=96&#38;d=https%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">tripleemcoder</media:title>
		</media:content>
	</item>
		<item>
		<title>The Orchard packaging experiment</title>
		<link>https://tripleemcoder.com/2012/10/02/the-orchard-packaging-experiment/</link>
					<comments>https://tripleemcoder.com/2012/10/02/the-orchard-packaging-experiment/#comments</comments>
		
		<dc:creator><![CDATA[TripleEmcoder]]></dc:creator>
		<pubDate>Tue, 02 Oct 2012 19:29:10 +0000</pubDate>
				<category><![CDATA[Debugging]]></category>
		<category><![CDATA[NuGet]]></category>
		<category><![CDATA[Orchard]]></category>
		<category><![CDATA[SymbolSource]]></category>
		<guid isPermaLink="false">http://tripleemcoder.com/?p=180</guid>

					<description><![CDATA[I&#8217;ve written about plugins based on NuGet before. One piece of software that manages its pluggable parts with NuGet is Orchard &#8211; a CMS based on .NET and MVC, which from the experience of my company, Caliper, also serves as a nice framework for building web applications without any CMS functionality. There&#8217;s a couple of things [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>I&#8217;ve written about plugins based on NuGet before. One piece of software that manages its pluggable parts with NuGet is <a href="http://orchardproject.net/">Orchard </a>&#8211; a CMS based on .NET and MVC, which from the experience of my company, <a href="http://www.caliper.pl/en">Caliper</a>, also serves as a nice framework for building web applications without any CMS functionality.</p>
<p>There&#8217;s a couple of things that Orchard solves for you, that make it great as a general framework:</p>
<ul>
<li>database connectivity (with NHibernate), including out-of-the-box support for local, automatic SqlCe databases,</li>
<li>data migrations, for upgrading table schemas with new releases of your web applications or modules,</li>
<li>theme and module management, with the use of NuGet packages and feeds,</li>
<li><a href="http://docs.orchardproject.net/Documentation/Orchard-module-loader-and-dynamic-compilation">dynamic compilation</a>, which lets you do in place changes to your web site or application, even through FTP, and see changes instantenously.</li>
</ul>
<p>Orchard is distributed as a ZIP file that you can deploy as an application in IIS or open as a web application in Visual Studio. Module and theme packages are only managed through Orchard&#8217;s web UI, which gets them from a special <a href="http://gallery.orchardproject.net">Orchard Gallery</a> Feed URL: <code>http://packages.orchardproject.net/FeedService.svc</code>. If you open a module from that feed you&#8217;ll see that it contains all of its sources (as in *.cs files), for Orchard&#8217;s dynamic compilation to take care of. Open-source at its best. Or is it?</p>
<p>As much as we love having access to sources at <a href="http://www.caliper.pl/en">Caliper</a>, we love having them on-demand in our debugging sessions even more &#8211; instead of moving thousands of them around on disk for no reason. And we all have SymbolSource to handle that for free <img src="https://s0.wp.com/wp-content/mu-plugins/wpcom-smileys/twemoji/2/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
<p>So we set out to try and make Orchard and its modules more vanilla-nuggety and symbol/source server friendly.</p>
<h1>Step 1: Packaging Orchard</h1>
<p>First, we decided to try putting Orchard itself into packages. The end-result experience should speak for itself:</p>
<ol>
<li>Open Visual Studio and create an ASP.NET Empty Web Application (<em>yes, no MVC, no Web Forms, no nothing</em>).</li>
<li>Add <code>http://nuget.gw.symbolsource.org/Public/Orchard/FeedService.mvc</code> as a new package source to Visual Studio (<em>yes, SymbolSource can host and serve NuGet packages as a package repository</em>)</li>
<li>Install the Orchard package from this feed in the empty project.</li>
<li>Run the project with F5. You now have the Orchard setup page ready for action.</li>
</ol>
<p>Things to note, as this should be considered work-in-progress still:</p>
<ul>
<li>All standard modules and themes are downloaded as dependencies. We haven&#8217;t tried yet to determine what subset is needed for setup, and which of them could be installed an on as-needed basis later with NuGet in Visual Studio or Orchard through the web UI.</li>
<li>External dependencies are taken from the official NuGet feed only if they were taken by the Orchard team as-is, without modification or recompilation. All the rest is in Orchard.External.</li>
<li>SqlCe native binaries are not included yet. But you should be good to go on your development machine, as you probably have in installed globally in your system.</li>
<li>We haven&#8217;t yet figured out how to do versioning, so all packages have strict dependencies (==, i.e. [x.y.z] in NuGet).</li>
<li>You can easily create your own binary module packages that take other Orchard modules as NuGet dependencies and get compiled with the right references.</li>
</ul>
<p>Now for the best part:</p>
<ul>
<li><strong>No *.cs files anywhere!</strong> Less files is more speed, less waiting, less transfers, less comparing on updates, less temptation to modify modules in place.</li>
<li><strong>Debuggable &#8211; with SymbolSource!</strong> All symbols (PDB files) and sources are indexed and accessible with Visual Studio using the <a href="http://www.symbolsource.org/Public/Home/VisualStudio">regular, public SymbolSource URL</a>. This applies only to <code>Orchard.Framework</code>, <code>Orchard.Core</code> and <code>Orchard.Web</code> projects at the moment, but all Orchard modules will follow soon.</li>
<li><strong>No dynamic compilation!</strong> No more screwed up assembly names and WCF services unable to load. Yes, you can disable dynamic compilation in configuration, but then you&#8217;re still required to compile modules and cleanup sources yourself.</li>
<li>All views are included in the main project as content files, so it&#8217;s easy to find, edit or copy them to your theme.</li>
</ul>
<h1>Step 2: Repackaging modules</h1>
<p>Since a lot of the standard Orchard distribution is built using modules, we had to figure out how to transform them form source form into binary form. We have a small application that interfaces with NuGet and MSBuild to get the modules, guess their interdependencies from project references, then compile and repackage them. All of the standard modules have been uploaded in repackaged, binary form to the <a href="http://www.symbolsource.org/Public/Metadata/Orchard">SymbolSource Orchard repository</a>.</p>
<p>So far we haven&#8217;t touched any contributed modules from the Orchard Gallery, but our plan is to either create a SymbolSource gateway that would do that compilation on the fly (module authors would decide to push to it additionally), or monitor the gallery feed and repackage new modules into our Orchard repository automatically.</p>
<p>What do you think?</p>
<p>All the tooling that we created for this is available on GitHub: <a href="http://github.com/SymbolSource/Orchard">http://github.com/SymbolSource/Orchard</a>. To run it, just clone, open a Visual Studio prompt and do <code>msbuild Orchard.proj</code>. The output will be in <code>pkg</code> (main Orchard packages) and <code>pkgbin</code> (module packages).</p>
]]></content:encoded>
					
					<wfw:commentRss>https://tripleemcoder.com/2012/10/02/the-orchard-packaging-experiment/feed/</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">180</post-id>
		<media:content url="https://0.gravatar.com/avatar/f4638cd124749b4d58d8889ea7777fb7eb81aea61ff5427999e47fe54448d3b6?s=96&#38;d=https%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">tripleemcoder</media:title>
		</media:content>
	</item>
		<item>
		<title>A world of debuggable open-source software &#8211; Part 3: Applications</title>
		<link>https://tripleemcoder.com/2012/09/03/a-world-of-debuggable-open-source-software-part-3-applications/</link>
					<comments>https://tripleemcoder.com/2012/09/03/a-world-of-debuggable-open-source-software-part-3-applications/#respond</comments>
		
		<dc:creator><![CDATA[TripleEmcoder]]></dc:creator>
		<pubDate>Mon, 03 Sep 2012 20:15:08 +0000</pubDate>
				<category><![CDATA[Chocolatey]]></category>
		<category><![CDATA[Debugging]]></category>
		<category><![CDATA[NuGet]]></category>
		<category><![CDATA[SymbolSource]]></category>
		<guid isPermaLink="false">http://tripleemcoder.wordpress.com/?p=148</guid>

					<description><![CDATA[In my last post, A world of debuggable open-source software – Part 2: Plugins, I used NuGet Package Explorer as an example of an application that uses NuGet-based plugins, and how that makes it very easy to publish their symbols and sources to SymbolSource, for a great debugging experience in case anything goes wrong at [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>In my last post, <a title="A world of debuggable open-source software – Part 2: Plugins" href="https://tripleemcoder.wordpress.com/2012/09/01/a-world-of-debuggable-open-source-software-part-2-plugins/">A world of debuggable open-source software – Part 2: Plugins</a>, I used <a href="http://npe.codeplex.com">NuGet Package Explorer</a> as an example of an application that uses <a href="http://nuget.org">NuGet</a>-based plugins, and how that makes it very easy to publish their symbols and sources to <a href="http://www.symbolsource.org">SymbolSource</a>, for a great debugging experience in case anything goes wrong at runtime. If you&#8217;re interested in creating your own plugin system based on NuGet, have a look at this post by Aaron Powell: <a href="http://www.aaron-powell.com/creating-a-nuget-plugin-engine">Creating a NuGet-based plugin engine</a>.</p>
<p>I also mentioned in that post that you can push any PDB files and sources to SymbolSource, including those of entire applications. Because NuGet is still the easiest way of pushing symbol packages, what we would need is a NuGet-based method of distributing programs. Fortunately such tool exists already and is called <a href="http://chocolatey.org">Chocolatey</a>. If you haven&#8217;t heard of it before, here&#8217;s how it&#8217;s described by its authors:</p>
<blockquote><p>Chocolatey NuGet is a Machine Package Manager, somewhat like apt-get, but built with windows in mind.</p></blockquote>
<p>In this post I will show you how Chocolatey and SymbolSource can be used to publish open-source applications with full debugging support, allowing users with programming skills to analyze problems through code and provide much more useful bug reports. Or even patches and pull requests!<br />
<span id="more-148"></span></p>
<h2>The end-user experience</h2>
<p>First let&#8217;s try installing a sample application and see how a user can get into its source when something goes wrong.</p>
<ol>
<li>Install Chocolatey if you haven&#8217;t done so yet:<br />
<code>@powershell -NoProfile -ExecutionPolicy unrestricted -Command "iex ((new-object net.webclient).DownloadString('http://bit.ly/psChocInstall'))" &amp;&amp; SET PATH=%PATH%;%systemdrive%\chocolatey\bin</code></li>
<li>Install our sample application:<br />
<code>cinst SymbolSource.DemoApplication</code></li>
<li>Chocolatey automatically makes executables included in a package&#8217;s lib folder visible in PATH, so can now start our example simply as:<br />
<code>SymbolSource.DemoApplication</code></li>
<li>As printed out, you can now simulate a crash by passing an argument to the program:<br />
<code>SymbolSource.DemoApplication CrashMePlease</code></li>
<li>This will give you a stack trace:<br />
<code>Unhandled Exception: System.Exception: Exception of type 'System.Exception' was thrown.<br />
at SymbolSource.DemoApplication.Program.Main(String[] args)</code><br />
And a Windows Error Reporting window:<br />
<img data-attachment-id="151" data-permalink="https://tripleemcoder.com/2012/09/03/a-world-of-debuggable-open-source-software-part-3-applications/demoapplication-stopped-working/" data-orig-file="https://tripleemcoder.com/wp-content/uploads/2012/09/demoapplication-stopped-working.png" data-orig-size="366,201" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}" data-image-title="SymbolSource.DemoApplication has stopped working" data-image-description="" data-image-caption="" data-medium-file="https://tripleemcoder.com/wp-content/uploads/2012/09/demoapplication-stopped-working.png?w=300" data-large-file="https://tripleemcoder.com/wp-content/uploads/2012/09/demoapplication-stopped-working.png?w=366" class="alignnone size-full wp-image-151" title="SymbolSource.DemoApplication has stopped working" src="https://tripleemcoder.com/wp-content/uploads/2012/09/demoapplication-stopped-working.png?w=600" alt=""   srcset="https://tripleemcoder.com/wp-content/uploads/2012/09/demoapplication-stopped-working.png 366w, https://tripleemcoder.com/wp-content/uploads/2012/09/demoapplication-stopped-working.png?w=150&amp;h=82 150w, https://tripleemcoder.com/wp-content/uploads/2012/09/demoapplication-stopped-working.png?w=300&amp;h=165 300w" sizes="(max-width: 366px) 100vw, 366px" /></li>
<li>Wait it out and click the <em>Debug</em> button. Then choose <em>New instance of Microsoft Visual Studio</em>.<br />
<img data-attachment-id="150" data-permalink="https://tripleemcoder.com/2012/09/03/a-world-of-debuggable-open-source-software-part-3-applications/demoapplication-debug-or-close/" data-orig-file="https://tripleemcoder.com/wp-content/uploads/2012/09/demoapplication-debug-or-close.png" data-orig-size="366,206" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}" data-image-title="SymbolSource.DemoApplication &amp;#8211; Debug or Close" data-image-description="" data-image-caption="" data-medium-file="https://tripleemcoder.com/wp-content/uploads/2012/09/demoapplication-debug-or-close.png?w=300" data-large-file="https://tripleemcoder.com/wp-content/uploads/2012/09/demoapplication-debug-or-close.png?w=366" class="alignnone size-full wp-image-150" title="SymbolSource.DemoApplication - Debug or Close" src="https://tripleemcoder.com/wp-content/uploads/2012/09/demoapplication-debug-or-close.png?w=600" alt=""   srcset="https://tripleemcoder.com/wp-content/uploads/2012/09/demoapplication-debug-or-close.png 366w, https://tripleemcoder.com/wp-content/uploads/2012/09/demoapplication-debug-or-close.png?w=150&amp;h=84 150w, https://tripleemcoder.com/wp-content/uploads/2012/09/demoapplication-debug-or-close.png?w=300&amp;h=169 300w" sizes="(max-width: 366px) 100vw, 366px" /></li>
<li>You might also get this windows instead (does anybody know why?):<br />
<img data-attachment-id="159" data-permalink="https://tripleemcoder.com/2012/09/03/a-world-of-debuggable-open-source-software-part-3-applications/demoapplication-stopped-working-2/" data-orig-file="https://tripleemcoder.com/wp-content/uploads/2012/09/demoapplication-stopped-working-2.png" data-orig-size="532,286" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}" data-image-title="SymbolSource.DemoApplication has stopped working" data-image-description="" data-image-caption="" data-medium-file="https://tripleemcoder.com/wp-content/uploads/2012/09/demoapplication-stopped-working-2.png?w=300" data-large-file="https://tripleemcoder.com/wp-content/uploads/2012/09/demoapplication-stopped-working-2.png?w=532" class="alignnone size-full wp-image-159" title="SymbolSource.DemoApplication has stopped working" src="https://tripleemcoder.com/wp-content/uploads/2012/09/demoapplication-stopped-working-2.png?w=600" alt=""   srcset="https://tripleemcoder.com/wp-content/uploads/2012/09/demoapplication-stopped-working-2.png 532w, https://tripleemcoder.com/wp-content/uploads/2012/09/demoapplication-stopped-working-2.png?w=150&amp;h=81 150w, https://tripleemcoder.com/wp-content/uploads/2012/09/demoapplication-stopped-working-2.png?w=300&amp;h=161 300w" sizes="(max-width: 532px) 100vw, 532px" /></li>
<li>Make sure that the Visual Studio instance that just opened is <a href="http://www.symbolsource.org/Public/Home/VisualStudio">configured for SymbolSource</a>. Load symbols for <code>SymbolSource.DemoApplication</code> from the call stack and double click on the call to <code>Program.Main</code> to see where and why the program failed.</li>
<li>Oops, the symbols loaded fine, but the source didn&#8217;t! It turns out, that because Chocolatey installs packages in C:\Chocolatety, Visual Studio is having trouble downloading files from the source server. If you enable <em>Print source server diagnostic messages to the Output window</em> in <em>Tools -&gt; Options -&gt; Debugging -&gt; General</em> and try again, you&#8217;ll notice this hint in the log: <em>SRCSRV: Source server cannot retrieve the source code (&#8230;) Access is denied</em>.</li>
<li>My solution was to start again from step 4 in an elevated prompt. Visual Studio will warn you that it needs to elevate itself too, to debug an elevated process:<br />
<a href="https://tripleemcoder.com/wp-content/uploads/2012/09/demoapplication-needs-elevation.png"><img loading="lazy" data-attachment-id="160" data-permalink="https://tripleemcoder.com/2012/09/03/a-world-of-debuggable-open-source-software-part-3-applications/demoapplication-needs-elevation/" data-orig-file="https://tripleemcoder.com/wp-content/uploads/2012/09/demoapplication-needs-elevation.png" data-orig-size="616,335" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}" data-image-title="SymbolSource.DemoApplication needing elevation" data-image-description="" data-image-caption="" data-medium-file="https://tripleemcoder.com/wp-content/uploads/2012/09/demoapplication-needs-elevation.png?w=300" data-large-file="https://tripleemcoder.com/wp-content/uploads/2012/09/demoapplication-needs-elevation.png?w=600" class="alignnone size-full wp-image-160" title="SymbolSource.DemoApplication needing elevation" src="https://tripleemcoder.com/wp-content/uploads/2012/09/demoapplication-needs-elevation.png?w=600&#038;h=326" alt="" width="600" height="326" srcset="https://tripleemcoder.com/wp-content/uploads/2012/09/demoapplication-needs-elevation.png?w=600&amp;h=326 600w, https://tripleemcoder.com/wp-content/uploads/2012/09/demoapplication-needs-elevation.png?w=150&amp;h=82 150w, https://tripleemcoder.com/wp-content/uploads/2012/09/demoapplication-needs-elevation.png?w=300&amp;h=163 300w, https://tripleemcoder.com/wp-content/uploads/2012/09/demoapplication-needs-elevation.png 616w" sizes="(max-width: 600px) 100vw, 600px" /></a></li>
<li>You should see the source now, loaded by Visual Studio on-demand from SymbolSource.</li>
</ol>
<p>When looking at the source, notice however that the debugger is stopped at the exit of the scope where the exception occured.</p>
<p><a href="https://tripleemcoder.com/wp-content/uploads/2012/09/demoapplication-scope-exit.png"><img loading="lazy" data-attachment-id="162" data-permalink="https://tripleemcoder.com/2012/09/03/a-world-of-debuggable-open-source-software-part-3-applications/demoapplication-scope-exit/" data-orig-file="https://tripleemcoder.com/wp-content/uploads/2012/09/demoapplication-scope-exit.png" data-orig-size="705,375" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}" data-image-title="SymbolSource.DemoApplication at scope exit" data-image-description="" data-image-caption="" data-medium-file="https://tripleemcoder.com/wp-content/uploads/2012/09/demoapplication-scope-exit.png?w=300" data-large-file="https://tripleemcoder.com/wp-content/uploads/2012/09/demoapplication-scope-exit.png?w=600" class="alignnone size-full wp-image-162" title="SymbolSource.DemoApplication at scope exit" src="https://tripleemcoder.com/wp-content/uploads/2012/09/demoapplication-scope-exit.png?w=600&#038;h=319" alt="" width="600" height="319" srcset="https://tripleemcoder.com/wp-content/uploads/2012/09/demoapplication-scope-exit.png?w=600&amp;h=319 600w, https://tripleemcoder.com/wp-content/uploads/2012/09/demoapplication-scope-exit.png?w=150&amp;h=80 150w, https://tripleemcoder.com/wp-content/uploads/2012/09/demoapplication-scope-exit.png?w=300&amp;h=160 300w, https://tripleemcoder.com/wp-content/uploads/2012/09/demoapplication-scope-exit.png 705w" sizes="(max-width: 600px) 100vw, 600px" /></a></p>
<p>This is because we are actually doing post-mortem debugging here, which was triggered by the absence of any exception handler along the way. Have a look at my previous post for more on this matter: <a href="https://tripleemcoder.wordpress.com/2011/12/10/writing-an-automatic-debugger-in-15-minutes-yes-a-debugger/">Writing an automatic debugger in 15 minutes</a> &#8211; section <em>Choosing the right place and time</em>. It would help, if we set up a breakpoint at the beginning of the scope, and stepped into the exception manually. Unfortunately, for a simple application like this, there&#8217;s no way of attaching the debugger fast enough, but you can always take Chocolatey&#8217;s package install location and start the program <strong>from within</strong> the debugger. Except that Visual Studio doesn&#8217;t offer this possibility directly, so you&#8217;ll need to create a bogus project (e.g. ConsoleApplication or ClassLibrary) and go to <em>Properties -&gt;</em> <em>Debug -&gt; Start action</em> to set <em>Start external program </em>to the actual culprit. Visual Studio will then allow you to start debugging as usual, believing that at some point this external application will call into the current project. It won&#8217;t, but we just need Visual Studio to catch the exception that we&#8217;ve seen before.</p>
<p>Unfortunately, at this point Visual Studio will still break only at the end of the scope, if you have chosen to load symbols manually at <em>Tools -&gt; Options -&gt; Debugging -&gt; Symbols</em>. Add <code>SymbolSource.DemoApplication.exe</code> to the module list or choose automatic loading for all modules. After rerunning the bogus project, Visual Studio will now stop at the exception throw site:</p>
<p><a href="https://tripleemcoder.com/wp-content/uploads/2012/09/demoapplication-throw-site.png"><img loading="lazy" data-attachment-id="163" data-permalink="https://tripleemcoder.com/2012/09/03/a-world-of-debuggable-open-source-software-part-3-applications/demoapplication-throw-site/" data-orig-file="https://tripleemcoder.com/wp-content/uploads/2012/09/demoapplication-throw-site.png" data-orig-size="705,375" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}" data-image-title="SymbolSource.DemoApplication at throw site" data-image-description="" data-image-caption="" data-medium-file="https://tripleemcoder.com/wp-content/uploads/2012/09/demoapplication-throw-site.png?w=300" data-large-file="https://tripleemcoder.com/wp-content/uploads/2012/09/demoapplication-throw-site.png?w=600" class="alignnone size-full wp-image-163" title="SymbolSource.DemoApplication at throw site" src="https://tripleemcoder.com/wp-content/uploads/2012/09/demoapplication-throw-site.png?w=600&#038;h=319" alt="" width="600" height="319" srcset="https://tripleemcoder.com/wp-content/uploads/2012/09/demoapplication-throw-site.png?w=600&amp;h=319 600w, https://tripleemcoder.com/wp-content/uploads/2012/09/demoapplication-throw-site.png?w=150&amp;h=80 150w, https://tripleemcoder.com/wp-content/uploads/2012/09/demoapplication-throw-site.png?w=300&amp;h=160 300w, https://tripleemcoder.com/wp-content/uploads/2012/09/demoapplication-throw-site.png 705w" sizes="(max-width: 600px) 100vw, 600px" /></a></p>
<h2>Building a debug-enabled Chocolatey package</h2>
<p>Now let&#8217;s see how easy it is to create a Chocolatey package and how even easier it is to enable symbols and sources publishing for it.</p>
<p>Chocolatey provides a lot of helpers to wrap external setups or ZIP files in packages, but it also allows distributing applications as-is. Like I mentioned before, any executable that you put in the package&#8217;s lib folder will be included on your PATH for convenience.</p>
<p>So creating a Chocolatey package for a simple console program like SymbolSource.DemoApplication (you&#8217;ve seen all of its source already) is as easy as packaging a <code>.nuspec</code> file like the following (I prefer building packages with <code>&lt;files&gt;</code> instead of from projects):</p>
<div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:ec699921-9d97-4de9-bde5-55777746556d" class="wlWriterEditableSmartContent" style="margin:0;display:inline;float:none;padding:0;">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background:#ddd;overflow:auto;">
<ol style="background:#ffffff;margin:0 0 0 2.5em;padding:0 0 0 5px;white-space:nowrap;" start="1">
<li><span style="color:#0000ff;">&lt;?</span><span style="color:#a31515;">xml</span><span style="color:#ff0000;">version</span><span style="color:#0000ff;">=</span>&#8220;<span style="color:#0000ff;">1.0</span>&#8220;<span style="color:#ff0000;">encoding</span><span style="color:#0000ff;">=</span>&#8220;<span style="color:#0000ff;">utf-8</span>&#8220;<span style="color:#0000ff;">?&gt;</span></li>
<li style="background:#f3f3f3;"><span style="color:#0000ff;">&lt;</span><span style="color:#a31515;">package</span><span style="color:#0000ff;">&gt;</span></li>
<li>  <span style="color:#0000ff;">&lt;</span><span style="color:#a31515;">metadata</span><span style="color:#0000ff;">&gt;</span></li>
<li style="background:#f3f3f3;">    <span style="color:#0000ff;">&lt;</span><span style="color:#a31515;">id</span><span style="color:#0000ff;">&gt;</span>SymbolSource.DemoApplication<span style="color:#0000ff;">&lt;/</span><span style="color:#a31515;">id</span><span style="color:#0000ff;">&gt;</span></li>
<li>    <span style="color:#0000ff;">&lt;</span><span style="color:#a31515;">version</span><span style="color:#0000ff;">&gt;</span>1.0.0.0<span style="color:#0000ff;">&lt;/</span><span style="color:#a31515;">version</span><span style="color:#0000ff;">&gt;</span></li>
<li style="background:#f3f3f3;">    <span style="color:#0000ff;">&lt;</span><span style="color:#a31515;">authors</span><span style="color:#0000ff;">&gt;</span>SymbolSource<span style="color:#0000ff;">&lt;/</span><span style="color:#a31515;">authors</span><span style="color:#0000ff;">&gt;</span></li>
<li>    <span style="color:#0000ff;">&lt;</span><span style="color:#a31515;">description</span><span style="color:#0000ff;">&gt;</span>This is a sample package created to demo SymbolSource on-demand loading of symbols and sources.<span style="color:#0000ff;">&lt;/</span><span style="color:#a31515;">description</span><span style="color:#0000ff;">&gt;</span></li>
<li style="background:#f3f3f3;">    <span style="color:#0000ff;">&lt;</span><span style="color:#a31515;">language</span><span style="color:#0000ff;">&gt;</span>en-US<span style="color:#0000ff;">&lt;/</span><span style="color:#a31515;">language</span><span style="color:#0000ff;">&gt;</span></li>
<li>    <span style="color:#0000ff;">&lt;</span><span style="color:#a31515;">projectUrl</span><span style="color:#0000ff;">&gt;</span><a href="http://www.symbolsource.org/" rel="nofollow">http://www.symbolsource.org/</a><span style="color:#0000ff;">&lt;/</span><span style="color:#a31515;">projectUrl</span><span style="color:#0000ff;">&gt;</span></li>
<li style="background:#f3f3f3;">  <span style="color:#0000ff;">&lt;/</span><span style="color:#a31515;">metadata</span><span style="color:#0000ff;">&gt;</span></li>
<li>  <span style="color:#0000ff;">&lt;</span><span style="color:#a31515;">files</span><span style="color:#0000ff;">&gt;</span></li>
<li style="background:#f3f3f3;">    <span style="color:#0000ff;">&lt;</span><span style="color:#a31515;">file</span><span style="color:#ff0000;">src</span><span style="color:#0000ff;">=</span>&#8220;<span style="color:#0000ff;">bin\Debug\*.exe</span>&#8220;<span style="color:#ff0000;">target</span><span style="color:#0000ff;">=</span>&#8220;<span style="color:#0000ff;">lib</span>&#8220;<span style="color:#ff0000;">exclude</span><span style="color:#0000ff;">=</span>&#8220;<span style="color:#0000ff;">**\*.vshost.exe</span>&#8220;<span style="color:#0000ff;"> /&gt;</span></li>
<li>    <span style="color:#0000ff;">&lt;</span><span style="color:#a31515;">file</span><span style="color:#ff0000;">src</span><span style="color:#0000ff;">=</span>&#8220;<span style="color:#0000ff;">bin\Debug\*.pdb</span>&#8220;<span style="color:#ff0000;">target</span><span style="color:#0000ff;">=</span>&#8220;<span style="color:#0000ff;">lib</span>&#8220;<span style="color:#0000ff;"> /&gt;</span></li>
<li style="background:#f3f3f3;">    <span style="color:#0000ff;">&lt;</span><span style="color:#a31515;">file</span><span style="color:#ff0000;">src</span><span style="color:#0000ff;">=</span>&#8220;<span style="color:#0000ff;">**\*.cs</span>&#8220;<span style="color:#ff0000;">target</span><span style="color:#0000ff;">=</span>&#8220;<span style="color:#0000ff;">src</span>&#8220;<span style="color:#0000ff;"> /&gt;</span></li>
<li>  <span style="color:#0000ff;">&lt;/</span><span style="color:#a31515;">files</span><span style="color:#0000ff;">&gt;</span></li>
<li style="background:#f3f3f3;"><span style="color:#0000ff;">&lt;/</span><span style="color:#a31515;">package</span><span style="color:#0000ff;">&gt;</span></li>
</ol>
</div>
</div>
</div>
<p>With the application built and ready for packaging, all you need to do is register at <a href="http://chocolatey.org">chocolatey.org</a> to obtain a NuGet API key and run commands similar to:</p>
<ol>
<li><code>nuget.exe pack SymbolSource.DemoApplication.nuspec -symbols</code></li>
<li><code>nuget.exe setapikey &lt;key&gt; -source http://chocolatey.org</code></li>
<li><code>nuget.exe setapikey &lt;key&gt; -source http://nuget.gw.symbolsource.org/Public/Chocolatey</code></li>
<li><code>nuget.exe push SymbolSource.DemoApplication.nupkg -source http://chocolatey.org</code></li>
<li><code>nuget.exe.push SymbolSource.DemoApplication.symbols.nupkg -source http://nuget.gw.symbolsource.org/Public/Chocolatey</code></li>
</ol>
<p>Let me know if you&#8217;re aware of any open-source applications that have chosen Chocolatey as their native distribution method. They&#8217;re the first to benefit from all this, the easiest to enable symbol and source publishing for.<em><br />
</em></p>
<p>And our regular motto to finish off this post:</p>
<p><strong>Let’s create not only an open- but also debuggable-source world</strong> <img src="https://s0.wp.com/wp-includes/images/smilies/icon_smile.gif?m=1129645325g" alt=":)" /></p>
]]></content:encoded>
					
					<wfw:commentRss>https://tripleemcoder.com/2012/09/03/a-world-of-debuggable-open-source-software-part-3-applications/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">148</post-id>
		<media:content url="https://0.gravatar.com/avatar/f4638cd124749b4d58d8889ea7777fb7eb81aea61ff5427999e47fe54448d3b6?s=96&#38;d=https%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">tripleemcoder</media:title>
		</media:content>

		<media:content url="https://tripleemcoder.com/wp-content/uploads/2012/09/demoapplication-stopped-working.png" medium="image">
			<media:title type="html">SymbolSource.DemoApplication has stopped working</media:title>
		</media:content>

		<media:content url="https://tripleemcoder.com/wp-content/uploads/2012/09/demoapplication-debug-or-close.png" medium="image">
			<media:title type="html">SymbolSource.DemoApplication - Debug or Close</media:title>
		</media:content>

		<media:content url="https://tripleemcoder.com/wp-content/uploads/2012/09/demoapplication-stopped-working-2.png" medium="image">
			<media:title type="html">SymbolSource.DemoApplication has stopped working</media:title>
		</media:content>

		<media:content url="https://tripleemcoder.com/wp-content/uploads/2012/09/demoapplication-needs-elevation.png" medium="image">
			<media:title type="html">SymbolSource.DemoApplication needing elevation</media:title>
		</media:content>

		<media:content url="https://tripleemcoder.com/wp-content/uploads/2012/09/demoapplication-scope-exit.png" medium="image">
			<media:title type="html">SymbolSource.DemoApplication at scope exit</media:title>
		</media:content>

		<media:content url="https://tripleemcoder.com/wp-content/uploads/2012/09/demoapplication-throw-site.png" medium="image">
			<media:title type="html">SymbolSource.DemoApplication at throw site</media:title>
		</media:content>

		<media:content url="http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif?m=1129645325g" medium="image">
			<media:title type="html">:)</media:title>
		</media:content>
	</item>
		<item>
		<title>A world of debuggable open-source software &#8211; Part 2: Plugins</title>
		<link>https://tripleemcoder.com/2012/09/01/a-world-of-debuggable-open-source-software-part-2-plugins/</link>
					<comments>https://tripleemcoder.com/2012/09/01/a-world-of-debuggable-open-source-software-part-2-plugins/#respond</comments>
		
		<dc:creator><![CDATA[TripleEmcoder]]></dc:creator>
		<pubDate>Sat, 01 Sep 2012 14:41:08 +0000</pubDate>
				<category><![CDATA[Debugging]]></category>
		<category><![CDATA[NuGet]]></category>
		<category><![CDATA[SymbolSource]]></category>
		<guid isPermaLink="false">http://tripleemcoder.wordpress.com/?p=112</guid>

					<description><![CDATA[Apart from commonly being free-as-in-beer, open-source is also great because it enables us geeks to have a deep look into the inner-workings of software that we use. How many times have you wondered why a program fails, only to find that it has no logging capabilities, or produces useless output? Open-source often lets you avoid [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>Apart from commonly being free-as-in-beer, open-source is also great because it enables us geeks to have a deep look into the inner-workings of software that we use. How many times have you wondered why a program fails, only to find that it has no logging capabilities, or produces useless output? Open-source often lets you avoid banging your head on the wall too hard, because you can always have a look at the code and try to figure out what the problem is.</p>
<p>But what if the reason still remains a mystery after <span style="text-decoration:underline;">reading</span> the code? Fortunately then you have the most powerful tool in your development toolbox still left &#8211; the debugger. Let&#8217;s recap what it usually takes to start <span style="text-decoration:underline;">debugging</span> third-party code?<br />
<span id="more-112"></span></p>
<blockquote>
<h3>Libraries</h3>
<ol>
<li><strong>Figure out the branch and tag. </strong>If you&#8217;re lucky, the owners maintain a great source repository. If you&#8217;re not, it&#8217;s plain sorcery.</li>
<li><strong>Get the code.</strong> SVN, Git, Mercurial &#8211; piece of cake.</li>
<li><strong>Figure out the build system.</strong> MSBuild, NAnt, Rake, missing Visual Studio extensions &#8211; starting to get a headache.</li>
<li><strong>Rebuild the library.</strong> Usually straightforward after step 3.</li>
<li><strong>Replace library in the actual application.</strong> Often hard, especially when the build script failed to produce a matching version number or there was no signing key.</li>
<li><strong>Rebuild application with replaced library.</strong> To work around missing signatures or mismatched version numbers.</li>
<li><strong>Now you have all the binaries, PDBs and sources to dive deep into happy debugging.</strong></li>
</ol>
<h3>Plugins</h3>
<p>A plugin is essentially a library, so the steps are similar, but replacing it is much, much easier. Usually it&#8217;s just a matter of dropping it into to the right folder.</p>
<h3>Applications</h3>
<p>We&#8217;ve already covered getting and building the source. Replacing applications with your debug-enabled copies might, however, prove especially problematic. What if the application is installed in a location requiring elevation to overwrite? What if it&#8217;s part of a production deployment, or consists of many moving parts that would need to be replaced simultaneously?</p></blockquote>
<p>Fortunately, we can avoid all this with a symbol and source server like <a href="http://www.symbolsource.org">SymbolSource</a>, which will provide all the needed PDB files and sources on-demand, when you start a debugging session &#8211; regardless if the debugee is a library, a plugin or an entire application. Just configure Visual Studio <a href="http://www.symbolsource.org/Public/Home/VisualStudio">in a few simple steps</a>.</p>
<p>Personally I&#8217;m really happy that so many people publish to SymbolSource nowadays. It&#8217;s really easy, and most of the time requires close to no additional work when releasing a library to NuGet. Have a look at these posts to see how easy it is:</p>
<ul>
<li><a href="http://blog.davidebbo.com/2011/04/easy-way-to-publish-nuget-packages-with.html">The easy way to publish NuGet packages with sources</a> by <a href="http://twitter.com/davidebbo">David Ebbo</a>,</li>
<li><a href="http://www.symbolsource.org/Public/Blog/View/2011-04-14/The_new_integrated_NuGet_workflow">The new integrated NuGet workflow</a> by yours truly,</li>
<li><a href="http://www.xavierdecoster.com/post/2011/11/16/Why-everyone-should-be-using-a-symbol-server.aspx">Why everyone should be using a symbol server</a> by <a href="http://twitter.com/xavierdecoster">Xavier Decoster</a>.</li>
</ul>
<p>If you missed it, you can also apply this to private MyGet feeds and be sure your symbols and sources are secured:</p>
<ul>
<li><a href="http://blog.maartenballiauw.be/post/2011/11/16/Publishing-symbol-packages-for-a-MyGet-feed.aspx">Publishing symbol packages for a MyGet feed</a> by <a href="http://twitter.com/maartenballiauw">Maarten Balliauw</a>,</li>
<li><a href="http://www.symbolsource.org/Public/Blog/View/2012-08-22/How_SymbolSource_integrates_with_NuGet_and_MyGet">How SymbolSource integrates with NuGet and MyGet</a> and <a href="http://www.symbolsource.org/Public/Blog/View/2012-08-30/ASP_NET_Web_Stack_nightlies_now_also_on_SymbolSource">ASP.NET Web Stack nightlies now also on SymbolSource</a> by yours truly.</li>
</ul>
<p>By pushing symbols and sources to <a href="http://www.symbolsource.org">SymbolSource</a> you&#8217;ll help all your users avoid the pain of rebuilding code as detailed above.</p>
<p>We&#8217;re really proud at SymbolSource that this has caught on! So there was and will be no Part 1 of the series, as there is enough information and adoption on the web already <img src="https://s0.wp.com/wp-content/mu-plugins/wpcom-smileys/twemoji/2/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
<h2>Debuggable plugins</h2>
<p>Staying in the NuGet universe, there is a tool &#8211; <a href="http://npe.codeplex.com">NuGet Package Explorer</a> &#8211; that has a really cool way of distributing plugins &#8211; well&#8230; umm&#8230; NuGet.  There is a special MyGet feed where anyone is welcome to push plugin packages to, and NPE uses it to provide a list of plugins to its users, download selected plugins to a local cache, and then load all MEF exports from included assemblies.</p>
<p>Creating an NPE plugin is as easy as following these steps:</p>
<ol>
<li><a href="http://npe.codeplex.com/wikipage?title=How%20to%20write%20a%20plugin%20for%20NuGet%20Package%20Explorer">How to: Write plugins for NuGet Package Explorer</a> by <a href="https://twitter.com/dotnetjunky">Luan Nguyen</a>,</li>
<li><code>nuget.exe pack MyPlugin.csproj</code></li>
<li><code>nuget.exe push MyPlugin.nupkg -source http://www.myget.org/F/npe</code></li>
</ol>
<p>All you need to do let users debug an NPE plugin is to change those steps to:</p>
<ol start="2">
<li><code>nuget.exe pack MyPlugin.csproj -symbols</code></li>
<li><code>nuget.exe push MyPlugin.nupkg -source http://www.myget.org/F/npe</code></li>
<li><code>nuget.exe push MyPlugin.symbols.nupkg -source http://nuget.gw.symbolsource.org/MyGet/npe</code></li>
</ol>
<p>You can try the result yourself with our SymbolSource plugin that has symbols published already:</p>
<ol>
<li>Install <a href="http://npe.codeplex.com/downloads/get/clickOnce/NuGetPackageExplorer.application">NuGet Package Explorer</a> from <a href="http://npe.codeplex.com/releases/view/68211">CodePlex</a> if you don&#8217;t have it yet.</li>
<li>Install our SymbolSource plugin in NuGet Package Explorer.<br />
<a href="https://tripleemcoder.com/wp-content/uploads/2012/09/npe-symbolsource-plugin.png"><img loading="lazy" data-attachment-id="122" data-permalink="https://tripleemcoder.com/2012/09/01/a-world-of-debuggable-open-source-software-part-2-plugins/npe-symbolsource-plugin/" data-orig-file="https://tripleemcoder.com/wp-content/uploads/2012/09/npe-symbolsource-plugin.png" data-orig-size="817,652" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}" data-image-title="NuGet Package Explorer SymbolSource plugin" data-image-description="" data-image-caption="" data-medium-file="https://tripleemcoder.com/wp-content/uploads/2012/09/npe-symbolsource-plugin.png?w=300" data-large-file="https://tripleemcoder.com/wp-content/uploads/2012/09/npe-symbolsource-plugin.png?w=600" class="alignnone size-full wp-image-122" title="NuGet Package Explorer SymbolSource plugin" src="https://tripleemcoder.com/wp-content/uploads/2012/09/npe-symbolsource-plugin.png?w=600&#038;h=478" alt="" width="600" height="478" srcset="https://tripleemcoder.com/wp-content/uploads/2012/09/npe-symbolsource-plugin.png?w=600&amp;h=479 600w, https://tripleemcoder.com/wp-content/uploads/2012/09/npe-symbolsource-plugin.png?w=150&amp;h=120 150w, https://tripleemcoder.com/wp-content/uploads/2012/09/npe-symbolsource-plugin.png?w=300&amp;h=239 300w, https://tripleemcoder.com/wp-content/uploads/2012/09/npe-symbolsource-plugin.png?w=768&amp;h=613 768w, https://tripleemcoder.com/wp-content/uploads/2012/09/npe-symbolsource-plugin.png 817w" sizes="(max-width: 600px) 100vw, 600px" /></a></li>
<li>Open any package. If there&#8217;s nothing named <em>Any</em> on the NuGet feed, you can try one of the ASP.NET Web Stack Nightlies from <code>http://www.myget.org/F/aspnetwebstacknightly</code>.<a href="https://tripleemcoder.com/wp-content/uploads/2012/09/npe-aspwebstacknightlies.png"><img loading="lazy" data-attachment-id="123" data-permalink="https://tripleemcoder.com/2012/09/01/a-world-of-debuggable-open-source-software-part-2-plugins/npe-aspwebstacknightlies/" data-orig-file="https://tripleemcoder.com/wp-content/uploads/2012/09/npe-aspwebstacknightlies.png" data-orig-size="817,514" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}" data-image-title="ASP.NET Web Stack nightly feed" data-image-description="" data-image-caption="" data-medium-file="https://tripleemcoder.com/wp-content/uploads/2012/09/npe-aspwebstacknightlies.png?w=300" data-large-file="https://tripleemcoder.com/wp-content/uploads/2012/09/npe-aspwebstacknightlies.png?w=600" class="alignnone size-full wp-image-123" title="ASP.NET Web Stack nightly feed" src="https://tripleemcoder.com/wp-content/uploads/2012/09/npe-aspwebstacknightlies.png?w=600&#038;h=377" alt="" width="600" height="377" srcset="https://tripleemcoder.com/wp-content/uploads/2012/09/npe-aspwebstacknightlies.png?w=600&amp;h=377 600w, https://tripleemcoder.com/wp-content/uploads/2012/09/npe-aspwebstacknightlies.png?w=150&amp;h=94 150w, https://tripleemcoder.com/wp-content/uploads/2012/09/npe-aspwebstacknightlies.png?w=300&amp;h=189 300w, https://tripleemcoder.com/wp-content/uploads/2012/09/npe-aspwebstacknightlies.png?w=768&amp;h=483 768w, https://tripleemcoder.com/wp-content/uploads/2012/09/npe-aspwebstacknightlies.png 817w" sizes="(max-width: 600px) 100vw, 600px" /></a></li>
<li>Run <em>Tools -&gt; Analyze package</em>. Our plugin provides additional package validation rules, which are very useful when creating your own symbol packages. In this case it will just warn you that it cannot verify the package filename, because it was opened from a feed.<a href="https://tripleemcoder.com/wp-content/uploads/2012/09/npe-microsoft-aspnet-web-analyzepackage.png"><img loading="lazy" data-attachment-id="125" data-permalink="https://tripleemcoder.com/2012/09/01/a-world-of-debuggable-open-source-software-part-2-plugins/npe-microsoft-aspnet-web-analyzepackage/" data-orig-file="https://tripleemcoder.com/wp-content/uploads/2012/09/npe-microsoft-aspnet-web-analyzepackage.png" data-orig-size="945,529" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}" data-image-title="Microsoft.AspNet.Mvc with &amp;#8220;Analyze package&amp;#8221;" data-image-description="" data-image-caption="" data-medium-file="https://tripleemcoder.com/wp-content/uploads/2012/09/npe-microsoft-aspnet-web-analyzepackage.png?w=300" data-large-file="https://tripleemcoder.com/wp-content/uploads/2012/09/npe-microsoft-aspnet-web-analyzepackage.png?w=600" class="alignnone size-full wp-image-125" title="Microsoft.AspNet.Mvc with &quot;Analyze package&quot;" src="https://tripleemcoder.com/wp-content/uploads/2012/09/npe-microsoft-aspnet-web-analyzepackage.png?w=600&#038;h=335" alt="" width="600" height="335" srcset="https://tripleemcoder.com/wp-content/uploads/2012/09/npe-microsoft-aspnet-web-analyzepackage.png?w=600&amp;h=336 600w, https://tripleemcoder.com/wp-content/uploads/2012/09/npe-microsoft-aspnet-web-analyzepackage.png?w=150&amp;h=84 150w, https://tripleemcoder.com/wp-content/uploads/2012/09/npe-microsoft-aspnet-web-analyzepackage.png?w=300&amp;h=168 300w, https://tripleemcoder.com/wp-content/uploads/2012/09/npe-microsoft-aspnet-web-analyzepackage.png?w=768&amp;h=430 768w, https://tripleemcoder.com/wp-content/uploads/2012/09/npe-microsoft-aspnet-web-analyzepackage.png 945w" sizes="(max-width: 600px) 100vw, 600px" /></a></li>
<li>Now rename <code>System.Web.Mvc.xml</code> to <code>System.Web.Mvc.pdb</code> to trick our plugin into loading a malformed symbols file, which we did not anticipate in our code.<a href="https://tripleemcoder.com/wp-content/uploads/2012/09/npe-system-web-mvc-rename1.png"><img loading="lazy" data-attachment-id="127" data-permalink="https://tripleemcoder.com/2012/09/01/a-world-of-debuggable-open-source-software-part-2-plugins/npe-system-web-mvc-rename/" data-orig-file="https://tripleemcoder.com/wp-content/uploads/2012/09/npe-system-web-mvc-rename1.png" data-orig-size="930,514" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}" data-image-title="Renaming System.Web.Mvc.dll in System.Web.Mvc.pdb" data-image-description="" data-image-caption="" data-medium-file="https://tripleemcoder.com/wp-content/uploads/2012/09/npe-system-web-mvc-rename1.png?w=300" data-large-file="https://tripleemcoder.com/wp-content/uploads/2012/09/npe-system-web-mvc-rename1.png?w=600" class="alignnone size-full wp-image-127" title="Renaming System.Web.Mvc.dll in System.Web.Mvc.pdb" src="https://tripleemcoder.com/wp-content/uploads/2012/09/npe-system-web-mvc-rename1.png?w=600&#038;h=331" alt="" width="600" height="331" srcset="https://tripleemcoder.com/wp-content/uploads/2012/09/npe-system-web-mvc-rename1.png?w=600&amp;h=332 600w, https://tripleemcoder.com/wp-content/uploads/2012/09/npe-system-web-mvc-rename1.png?w=150&amp;h=83 150w, https://tripleemcoder.com/wp-content/uploads/2012/09/npe-system-web-mvc-rename1.png?w=300&amp;h=166 300w, https://tripleemcoder.com/wp-content/uploads/2012/09/npe-system-web-mvc-rename1.png?w=768&amp;h=424 768w, https://tripleemcoder.com/wp-content/uploads/2012/09/npe-system-web-mvc-rename1.png 930w" sizes="(max-width: 600px) 100vw, 600px" /></a></li>
<li>Run<em> Tools -&gt; Analyze package</em> again to crash the app. Select <em>Debug the program</em> and <em>New instance of Microsoft Visual Studio </em>to launch a debugging session.<a href="https://tripleemcoder.com/wp-content/uploads/2012/09/npe-microsoft-aspnet-web-crashed.png"><img loading="lazy" data-attachment-id="129" data-permalink="https://tripleemcoder.com/2012/09/01/a-world-of-debuggable-open-source-software-part-2-plugins/npe-microsoft-aspnet-web-crashed/" data-orig-file="https://tripleemcoder.com/wp-content/uploads/2012/09/npe-microsoft-aspnet-web-crashed.png" data-orig-size="930,514" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}" data-image-title="NuGet Package Explorer crashed" data-image-description="" data-image-caption="" data-medium-file="https://tripleemcoder.com/wp-content/uploads/2012/09/npe-microsoft-aspnet-web-crashed.png?w=300" data-large-file="https://tripleemcoder.com/wp-content/uploads/2012/09/npe-microsoft-aspnet-web-crashed.png?w=600" class="alignnone size-full wp-image-129" title="NuGet Package Explorer crashed" src="https://tripleemcoder.com/wp-content/uploads/2012/09/npe-microsoft-aspnet-web-crashed.png?w=600&#038;h=331" alt="" width="600" height="331" srcset="https://tripleemcoder.com/wp-content/uploads/2012/09/npe-microsoft-aspnet-web-crashed.png?w=600&amp;h=332 600w, https://tripleemcoder.com/wp-content/uploads/2012/09/npe-microsoft-aspnet-web-crashed.png?w=150&amp;h=83 150w, https://tripleemcoder.com/wp-content/uploads/2012/09/npe-microsoft-aspnet-web-crashed.png?w=300&amp;h=166 300w, https://tripleemcoder.com/wp-content/uploads/2012/09/npe-microsoft-aspnet-web-crashed.png?w=768&amp;h=424 768w, https://tripleemcoder.com/wp-content/uploads/2012/09/npe-microsoft-aspnet-web-crashed.png 930w" sizes="(max-width: 600px) 100vw, 600px" /></a></li>
<li>You should now see Visual Studio detailing a <code>NullReferenceException</code> without any source code to back it up.</li>
<li>If you haven&#8217;t done so yet, configure <code>http://srv.symbolsource.org/pdb/MyGet</code> as one of your symbol servers at <em>Tools -&gt; Options -&gt; Debugging -&gt; Symbols.</em></li>
<li>Open <em>Debug -&gt; Windows -&gt; Modules</em> and make sure <code>SymbolSource.Integration.NuGet.PackageExplorer.dll</code> has symbols loaded. Right-click on its row and select <em>Load Symbols From -&gt; Symbol Path</em> to load them manually.</li>
<li>Find <code>SymbolSource.Intergration.NuGet.PackageExplorer.dll</code> on the call stack and double-click to see where our plugin failed.</li>
<li>But that&#8217;s not the real reason, there&#8217;s a lot more methods on the call stack. Explore it by right-clicking those calls and loading symbols. You&#8217;ll need to have <code>http://srv.symbolsource.org/pdb/Public</code> configured as a symbol server for this to work, as all the other assemblies are available as packages on the NuGet Gallery and have symbols published to the regular SymbolSource repository, not as part of the MyGet plugin feed.</li>
<li>You should be able to see that something went horribly wrong while reading the PDB file&#8217;s hash, included in its header. That&#8217;s because we have an XML file serving as a corrupted PDB file.<a href="https://tripleemcoder.com/wp-content/uploads/2012/09/symbolstoremanager-readhash.png"><img loading="lazy" data-attachment-id="133" data-permalink="https://tripleemcoder.com/2012/09/01/a-world-of-debuggable-open-source-software-part-2-plugins/symbolstoremanager-readhash/" data-orig-file="https://tripleemcoder.com/wp-content/uploads/2012/09/symbolstoremanager-readhash.png" data-orig-size="597,545" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}" data-image-title="SymbolStoreManager.PdbRwInternal.ReadHash" data-image-description="" data-image-caption="" data-medium-file="https://tripleemcoder.com/wp-content/uploads/2012/09/symbolstoremanager-readhash.png?w=300" data-large-file="https://tripleemcoder.com/wp-content/uploads/2012/09/symbolstoremanager-readhash.png?w=597" class="alignnone size-full wp-image-133" title="SymbolStoreManager.PdbRwInternal.ReadHash" src="https://tripleemcoder.com/wp-content/uploads/2012/09/symbolstoremanager-readhash.png?w=600" alt=""   srcset="https://tripleemcoder.com/wp-content/uploads/2012/09/symbolstoremanager-readhash.png 597w, https://tripleemcoder.com/wp-content/uploads/2012/09/symbolstoremanager-readhash.png?w=150&amp;h=137 150w, https://tripleemcoder.com/wp-content/uploads/2012/09/symbolstoremanager-readhash.png?w=300&amp;h=274 300w" sizes="(max-width: 597px) 100vw, 597px" /></a></li>
</ol>
<p>That&#8217;s it. In Part 3 I will talk about debuggable applications and how you can publish them with NuGet, <a href="http://chocolatey.org">Chocolatey</a> and <a href="http://www.symbolsource.org">SymbolSource</a>, so stay tuned.</p>
<p>If you know about any other programs that use NuGet to distribute plugins, don&#8217;t hesitate to leave a comment. Also, remember that NuGet is just a means of transport for SymbolSource, and you can upload symbols and sources for just about anything, including tools published with ZIP files, MSI packages or regular setup files.</p>
<p>Let&#8217;s create not only an open- but also debuggable-source world <img src="https://s0.wp.com/wp-content/mu-plugins/wpcom-smileys/twemoji/2/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
]]></content:encoded>
					
					<wfw:commentRss>https://tripleemcoder.com/2012/09/01/a-world-of-debuggable-open-source-software-part-2-plugins/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">112</post-id>
		<media:content url="https://0.gravatar.com/avatar/f4638cd124749b4d58d8889ea7777fb7eb81aea61ff5427999e47fe54448d3b6?s=96&#38;d=https%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">tripleemcoder</media:title>
		</media:content>

		<media:content url="https://tripleemcoder.com/wp-content/uploads/2012/09/npe-symbolsource-plugin.png" medium="image">
			<media:title type="html">NuGet Package Explorer SymbolSource plugin</media:title>
		</media:content>

		<media:content url="https://tripleemcoder.com/wp-content/uploads/2012/09/npe-aspwebstacknightlies.png" medium="image">
			<media:title type="html">ASP.NET Web Stack nightly feed</media:title>
		</media:content>

		<media:content url="https://tripleemcoder.com/wp-content/uploads/2012/09/npe-microsoft-aspnet-web-analyzepackage.png" medium="image">
			<media:title type="html">Microsoft.AspNet.Mvc with &#034;Analyze package&#034;</media:title>
		</media:content>

		<media:content url="https://tripleemcoder.com/wp-content/uploads/2012/09/npe-system-web-mvc-rename1.png" medium="image">
			<media:title type="html">Renaming System.Web.Mvc.dll in System.Web.Mvc.pdb</media:title>
		</media:content>

		<media:content url="https://tripleemcoder.com/wp-content/uploads/2012/09/npe-microsoft-aspnet-web-crashed.png" medium="image">
			<media:title type="html">NuGet Package Explorer crashed</media:title>
		</media:content>

		<media:content url="https://tripleemcoder.com/wp-content/uploads/2012/09/symbolstoremanager-readhash.png" medium="image">
			<media:title type="html">SymbolStoreManager.PdbRwInternal.ReadHash</media:title>
		</media:content>
	</item>
		<item>
		<title>Creating a custom PostSharp aspect (with IL transformation)</title>
		<link>https://tripleemcoder.com/2012/01/17/creatin-a-custom-postsharp-aspect-with-msil-transformation/</link>
					<comments>https://tripleemcoder.com/2012/01/17/creatin-a-custom-postsharp-aspect-with-msil-transformation/#comments</comments>
		
		<dc:creator><![CDATA[TripleEmcoder]]></dc:creator>
		<pubDate>Tue, 17 Jan 2012 17:35:35 +0000</pubDate>
				<category><![CDATA[Debugging]]></category>
		<category><![CDATA[PADRE]]></category>
		<category><![CDATA[PostSharp]]></category>
		<guid isPermaLink="false">http://tripleemcoder.wordpress.com/?p=90</guid>

					<description><![CDATA[Last time I wrote about my efforts to create minidumps with PostSharp aspects. I showed some ways of achieving that, but the main conclusion was that no out-of-the-box aspect in PostSharp provides a transformation that would allow inserting minidump generation code in the optimal place: just before throw instructions. Fortunately, it isn&#8217;t too hard to [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>Last time I wrote about my efforts to create minidumps with PostSharp aspects. I showed some ways of achieving that, but the main conclusion was that no out-of-the-box aspect in PostSharp provides a transformation that would allow inserting minidump generation code in the optimal place: just before throw instructions. Fortunately, it isn&#8217;t too hard to create such an aspect, even though the required <a href="http://www.sharpcrafters.com/blog/post/PostSharp-SDK-is-undocumented-and-unsupported.aspx">PostSharp SDK is unsupported and undocumented</a>.</p>
<p>Let&#8217;s start by analyzing how PostSharp aspects are architected. Then we&#8217;ll move to implementing the actual IL transformation required to temporarily store the exception about be thrown, pass it to the aspect code, and then actually throw it expected.</p>
<p><span id="more-90"></span></p>
<h2>A look at the FastTrace sample</h2>
<p>Although the <a href="http://www.sharpcrafters.com/blog/post/PostSharp-SDK-is-undocumented-and-unsupported.aspx">PostSharp SDK is unsupported and undocumented</a>, Gael Fraiteur (the creator of PostSharp) was kind enough to point me to a sample on the <a href="http://www.sharpcrafters.com">SharpCrafters</a> website that showed me how to solve the most important part of the problem: registering with the PostSharp engine. The sample is <a href="http://www.sharpcrafters.com/downloads/samples/2.1/FastTrace.zip">FastTrace</a> (Download -&gt; All downloads -&gt; Samples -&gt; PostSharp 2.1 &#8211; Sample Code -&gt; FastTrace), which basically achieves the same thing as the standard and supported <a href="http://doc.sharpcrafters.com/postsharp-2.0/##PostSharp-2.0.chm/html/T_PostSharp_Aspects_OnMethodBoundaryAspect.htm">OnMethodBoundaryAspect</a>, but shows how it can be done manually. The actual PostSharp implementation of this aspect, as far as I can tell, is far more complicated and robust, but for a little experiment like mine this is more than enough.</p>
<h3>Registering PostSharp plugins</h3>
<p>The FastTrace sample consists of 3 projects:</p>
<ol>
<li>FastTrace &#8211; defines the aspect attribute, and is shared by both the client project (FastTrace.Test) and the plugin project (FastTrace.Weaver);</li>
<li>FastTrace.Test &#8211; contains test code that has the aspect attribute attached, we expect that aspect code will run along regular code once the project is built and processed by PostSharp;</li>
<li>FastTrace.Weaver &#8211; contains transformation code (the so-called weaver) that runs inside PostSharp, when it is invoked at the end of the build process &#8211; the engine detects the aspect attribute and calls into the weaver code passing the elements the attribute was applied to, so that tracing code can be inserted.</li>
</ol>
<p>The solution has an additional manual dependency (apart from project references) added between FastTrace.Test and FastTrace.Weaver. This ensures that when FastTrace.Test is built, the FastTrace.Weaver binary is available. Without it, PostSharp would report an error about a missing plugin (thanks to the RequirePostSharp attribute on the aspect class). Where do plugins come from? The PostSharp installation directory has Plugins subfolder, but a project property can also override the plugin search path. The FastTrace.Test.csproj file contains the following code:</p>
<div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:48efa7d3-80ab-41c5-9d26-56568ae1f245" class="wlWriterEditableSmartContent" style="display:inline;float:none;margin:0;padding:0;">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background:#ddd;overflow:auto;">
<ol style="background:#ffffff;white-space:nowrap;margin:0 0 0 2em;padding:0 0 0 5px;" start="1">
<li><span style="color:#0000ff;">&lt;</span><span style="color:#a31515;">PropertyGroup</span><span style="color:#0000ff;">&gt;</span></li>
<li style="background:#f3f3f3;">    <span style="color:#0000ff;">&lt;</span><span style="color:#a31515;">PostSharpSearchPath</span><span style="color:#0000ff;">&gt;</span></li>
<li>      $(PostSharpSearchPath);</li>
<li style="background:#f3f3f3;">      ..\FastTrace.Weaver\bin\$(Configuration)</li>
<li>    <span style="color:#0000ff;">&lt;/</span><span style="color:#a31515;">PostSharpSearchPath</span><span style="color:#0000ff;">&gt;</span></li>
<li style="background:#f3f3f3;">  <span style="color:#0000ff;">&lt;/</span><span style="color:#a31515;">PropertyGroup</span><span style="color:#0000ff;">&gt;</span></li>
</ol>
</div>
</div>
</div>
<p>You could also specify this property on the msbuild command-line. Speaking of msbuild, the absolutely irreplacable switch is <code>/p:PostSharpAttachDebugger=True</code>, which will let you debug the aspect transformation code during compile-time. See <a href="http://doc.sharpcrafters.com/postsharp-2.0/##PostSharp-2.0.chm/html/fc617e2f-308b-469e-a393-e006526dd56a.htm">Debugging Compile-Time Logic</a> for more information. Also, what can save you from losing a lot of hair, is to always stop the PostSharp tray server and do a full rebuild of all projects (attribute, weaver, and target) each time you change the weaver code.</p>
<p>To be recognized as a PostSharp plugin, an assembly must have a corresponding .psplugin file. For FastTrace, it looks as follows:</p>
<div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:cc7ec425-81e8-4d66-8eb3-299616f8234c" class="wlWriterEditableSmartContent" style="display:inline;float:none;margin:0;padding:0;">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background:#ddd;overflow:auto;">
<ol style="background:#ffffff;white-space:nowrap;margin:0 0 0 2em;padding:0 0 0 5px;" start="1">
<li><span style="color:#0000ff;">&lt;?</span><span style="color:#a31515;">xml</span><span style="color:#ff0000;">version</span><span style="color:#0000ff;">=</span>&#8220;<span style="color:#0000ff;">1.0</span>&#8220;<span style="color:#ff0000;">encoding</span><span style="color:#0000ff;">=</span>&#8220;<span style="color:#0000ff;">utf-8</span>&#8220;<span style="color:#0000ff;"> ?&gt;</span></li>
<li style="background:#f3f3f3;"><span style="color:#0000ff;">&lt;</span><span style="color:#a31515;">PlugIn</span><span style="color:#ff0000;">xmlns</span><span style="color:#0000ff;">=</span>&#8220;<span style="color:#0000ff;"><a href="http://schemas.postsharp.org/1.0/configuration" rel="nofollow">http://schemas.postsharp.org/1.0/configuration</a></span>&#8220;<span style="color:#0000ff;">&gt;</span></li>
<li>  <span style="color:#0000ff;">&lt;</span><span style="color:#a31515;">TaskType</span><span style="color:#ff0000;">Name</span><span style="color:#0000ff;">=</span>&#8220;<span style="color:#0000ff;">FastTrace</span>&#8220;</li>
<li style="background:#f3f3f3;">            <span style="color:#ff0000;">Implementation</span><span style="color:#0000ff;">=</span>&#8220;<span style="color:#0000ff;">FastTrace.Weaver.FastTracePlugIn, FastTrace.Weaver</span>&#8220;<span style="color:#0000ff;">&gt;</span></li>
<li>    <span style="color:#0000ff;">&lt;</span><span style="color:#a31515;">Dependency</span><span style="color:#ff0000;">TaskType</span><span style="color:#0000ff;">=</span>&#8220;<span style="color:#0000ff;">AspectWeaver</span>&#8220;<span style="color:#0000ff;">/&gt;</span></li>
<li style="background:#f3f3f3;">  <span style="color:#0000ff;">&lt;/</span><span style="color:#a31515;">TaskType</span><span style="color:#0000ff;">&gt;</span></li>
<li><span style="color:#0000ff;">&lt;/</span><span style="color:#a31515;">PlugIn</span><span style="color:#0000ff;">&gt;</span></li>
</ol>
</div>
</div>
</div>
<p>The file is copied to the output bin\$(Configuration) directory when FastTrace.Weaver is built. It registers the FastTracePlugIn class as task to be run by PostSharp. In that class you can see how the transformation code is associated with a given aspect attribute:</p>
<div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:cd4c7267-b598-41af-bdbf-9bf5110b0bf3" class="wlWriterEditableSmartContent" style="display:inline;float:none;margin:0;padding:0;">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background:#ddd;overflow:auto;">
<ol style="background:#ffffff;white-space:nowrap;margin:0 0 0 2em;padding:0 0 0 5px;" start="1">
<li><span style="color:#0000ff;">protected</span> <span style="color:#0000ff;">override</span> <span style="color:#0000ff;">void</span> Initialize()</li>
<li style="background:#f3f3f3;">{</li>
<li>    <span style="color:#0000ff;">this</span>.BindAspectWeaver&lt;<span style="color:#2b91af;">FastTraceAttribute</span>, <span style="color:#2b91af;">FastTraceAspectWeaver</span>&gt;();</li>
<li style="background:#f3f3f3;">}</li>
</ol>
</div>
</div>
</div>
<p>The FastTraceAspectWeaver class contains mainly plumbing code, but also one thing that will be of interest to us. See line 6 (line 17 in the original file):</p>
<div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:5be24e7c-3ed6-4088-a495-14d8e7314a6b" class="wlWriterEditableSmartContent" style="display:inline;float:none;margin:0;padding:0;">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background:#ddd;overflow:auto;">
<ol style="background:#ffffff;white-space:nowrap;margin:0 0 0 2em;padding:0 0 0 5px;" start="1">
<li><span style="color:#0000ff;">public</span> FastTraceAspectWeaver()</li>
<li style="background:#f3f3f3;">    : <span style="color:#0000ff;">base</span>(</li>
<li>        defaultConfiguration, <span style="color:#2b91af;">ReflectionObjectBuilder</span>.Dynamic,</li>
<li style="background:#f3f3f3;">        <span style="color:#2b91af;">MulticastTargets</span>.Method | <span style="color:#2b91af;">MulticastTargets</span>.InstanceConstructor | <span style="color:#2b91af;">MulticastTargets</span>.StaticConstructor | <span style="color:#2b91af;">MulticastTargets</span>.Field )</li>
<li>{</li>
<li style="background:#f3f3f3;">    <span style="color:#0000ff;">this</span>.RequiresRuntimeInstance = <span style="color:#0000ff;">false</span>;</li>
<li>    <span style="color:#0000ff;">this</span>.RequiresRuntimeReflectionObject = <span style="color:#0000ff;">false</span>;</li>
<li style="background:#f3f3f3;">}</li>
</ol>
</div>
</div>
</div>
<p>This property tells PostSharp whether an instance of the aspect attribute class should be made available to the weaver. In case of FastTrace, this is not necessary, as the attribute it is only used to mark pieces of code for transformation. But later on, when we proceed to implement the minidump aspect, it will be needed to be able to call custom code implemented in the aspect attribute.</p>
<h3>Transforming assemblies with aspect weavers</h3>
<p>Let&#8217;s move to FastTraceTransformation for the really cool part of AOP. This class implements the actual IL rewriting, although it cheats a bit by using the pre-defined MethodBodyWrappingImplementation class. Generally speaking, the starting point here is the MethodBodyTransformation base class, that specifies that rewriting will be performed on the method level.</p>
<p>First, references to other code elements are obtained, in this case to Console.WriteLine, so that the injected code can write out traces to the console:</p>
<div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:2e9b0b86-e4ee-46d2-87cd-1dc465a4258d" class="wlWriterEditableSmartContent" style="display:inline;float:none;margin:0;padding:0;">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background:#ddd;overflow:auto;">
<ol style="background:#ffffff;white-space:nowrap;margin:0 0 0 2em;padding:0 0 0 5px;" start="1">
<li><span style="color:#0000ff;">public</span> FastTraceTransformation(<span style="color:#2b91af;">AspectWeaver</span> aspectWeaver)</li>
<li style="background:#f3f3f3;">    : <span style="color:#0000ff;">base</span>(aspectWeaver)</li>
<li>{</li>
<li style="background:#f3f3f3;">    <span style="color:#2b91af;">ModuleDeclaration</span> module = <span style="color:#0000ff;">this</span>.AspectInfrastructureTask.Project.Module;</li>
<li>    <span style="color:#0000ff;">this</span>.assets = module.Cache.GetItem(() =&gt; <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">Assets</span>(module));</li>
<li style="background:#f3f3f3;">}</li>
</ol>
</div>
</div>
</div>
<div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:3e745010-afc7-46fd-9b81-4bd55bc156ed" class="wlWriterEditableSmartContent" style="display:inline;float:none;margin:0;padding:0;">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background:#ddd;overflow:auto;">
<ol style="background:#ffffff;white-space:nowrap;margin:0 0 0 2.5em;padding:0 0 0 5px;" start="1">
<li><span style="color:#0000ff;">private</span> <span style="color:#0000ff;">sealed</span> <span style="color:#0000ff;">class</span> <span style="color:#2b91af;">Assets</span></li>
<li style="background:#f3f3f3;">{</li>
<li>    <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">readonly</span> <span style="color:#2b91af;">IMethod</span> WriteLineMethod;</li>
<li style="background:#f3f3f3;"></li>
<li>    <span style="color:#0000ff;">public</span> Assets(<span style="color:#2b91af;">ModuleDeclaration</span> module)</li>
<li style="background:#f3f3f3;">    {</li>
<li>        <span style="color:#0000ff;">this</span>.WriteLineMethod = module.FindMethod(<span style="color:#0000ff;">typeof</span>(<span style="color:#2b91af;">Console</span>).GetMethod(<span style="color:#a31515;">&#8220;WriteLine&#8221;</span>, <span style="color:#0000ff;">new</span>[] { <span style="color:#0000ff;">typeof</span>(<span style="color:#0000ff;">string</span>) }), <span style="color:#2b91af;">BindingOptions</span>.Default);</li>
<li style="background:#f3f3f3;">    }</li>
<li>}</li>
</ol>
</div>
</div>
</div>
<p>For performance reasons this is cached &#8211; remember that an aspect can easily be attached to all elements of a large assembly with multicasting.</p>
<p>Processing starts with a MethodBodyTransformationContext object in Instance.Implement. It provides a reference to a method that was annotated with the FastTrace attribute, and is called for each one of them. Then, the actual rewriting is done in EmitMessage:</p>
<div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:7eda17a5-f076-424c-a5ee-ba3959a4e03e" class="wlWriterEditableSmartContent" style="display:inline;float:none;margin:0;padding:0;">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background:#ddd;overflow:auto;">
<ol style="background:#ffffff;white-space:nowrap;margin:0 0 0 2.5em;padding:0 0 0 5px;" start="1">
<li><span style="color:#0000ff;">private</span> <span style="color:#0000ff;">void</span> EmitMessage(<span style="color:#2b91af;">InstructionBlock</span> block, <span style="color:#2b91af;">InstructionWriter</span> writer, <span style="color:#0000ff;">string</span> message)</li>
<li style="background:#f3f3f3;">{</li>
<li>    <span style="color:#2b91af;">InstructionSequence</span> sequence = block.AddInstructionSequence(<span style="color:#0000ff;">null</span>, <span style="color:#2b91af;">NodePosition</span>.After, <span style="color:#0000ff;">null</span>);</li>
<li style="background:#f3f3f3;">    writer.AttachInstructionSequence(sequence);</li>
<li>    writer.EmitInstructionString(<span style="color:#2b91af;">OpCodeNumber</span>.Ldstr, message);</li>
<li style="background:#f3f3f3;">    writer.EmitInstructionMethod(<span style="color:#2b91af;">OpCodeNumber</span>.Call,</li>
<li>                                    ((<span style="color:#2b91af;">FastTraceTransformation</span>)<span style="color:#0000ff;">this</span>.transformationInstance.Transformation).assets.WriteLineMethod);</li>
<li style="background:#f3f3f3;">    writer.DetachInstructionSequence();</li>
<li>}</li>
</ol>
</div>
</div>
</div>
<h2>Implementing the OnThrowAspect</h2>
<p>Now for the even cooler part, where we implement our own custom transformation. As discussed before, for the richest minidumps, they need to be created right before an exception is thrown. It is is possible to capture that moment with a debugger (see <a href="https://tripleemcoder.wordpress.com/2011/12/10/writing-an-automatic-debugger-in-15-minutes-yes-a-debugger/">Writing an automatic debugger in 15 minutes</a>). This applies to all exceptions, including those originating from system code. Because running under a debugger has its implications, let&#8217;s try actually injecting the minidump code before all throw instructions. Of course with approach we we will only be able to hijack exceptions thrown in our own code, where an aspect attribute can be applied.</p>
<p>All further code will refer to Padre.PostSharp (more on that later), which is a direct result of trial-and-error modifications to FastTrace.</p>
<h3>Finding throw instructions</h3>
<p>Since the transformation will process method bodies, and not wrap around them, we can safely delete all code run by Instance.Implement. Instead we need to look into the IL instruction sequences and find all throws. Luckily, PostSharp  allows that with the visitor pattern:</p>
<div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:9cb6b5be-53a7-4749-b82b-9ed47c280c81" class="wlWriterEditableSmartContent" style="display:inline;float:none;margin:0;padding:0;">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background:#ddd;overflow:auto;">
<ol style="background:#ffffff;white-space:nowrap;margin:0 0 0 2.5em;padding:0 0 0 5px;" start="1">
<li><span style="color:#0000ff;">namespace</span> PostSharp.Sdk.CodeModel</li>
<li style="background:#f3f3f3;">{</li>
<li>    <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">interface</span> <span style="color:#2b91af;">IMethodBodyVisitor</span></li>
<li style="background:#f3f3f3;">    {</li>
<li>        <span style="color:#0000ff;">void</span> EnterInstructionBlock(<span style="color:#2b91af;">InstructionBlock</span> instructionBlock, <span style="color:#2b91af;">InstructionBlockExceptionHandlingKind</span> exceptionHandlingKind);</li>
<li style="background:#f3f3f3;">        <span style="color:#0000ff;">void</span> LeaveInstructionBlock(<span style="color:#2b91af;">InstructionBlock</span> instructionBlock, <span style="color:#2b91af;">InstructionBlockExceptionHandlingKind</span> exceptionHandlingKind);</li>
<li>        <span style="color:#0000ff;">void</span> EnterInstructionSequence(<span style="color:#2b91af;">InstructionSequence</span> instructionSequence);</li>
<li style="background:#f3f3f3;">        <span style="color:#0000ff;">void</span> LeaveInstructionSequence(<span style="color:#2b91af;">InstructionSequence</span> instructionSequence);</li>
<li>        <span style="color:#0000ff;">void</span> EnterExceptionHandler(<span style="color:#2b91af;">ExceptionHandler</span> exceptionHandler);</li>
<li style="background:#f3f3f3;">        <span style="color:#0000ff;">void</span> LeaveExceptionHandler(<span style="color:#2b91af;">ExceptionHandler</span> exceptionHandler);</li>
<li>        <span style="color:#0000ff;">void</span> VisitInstruction(<span style="color:#2b91af;">InstructionReader</span> instructionReader);</li>
<li style="background:#f3f3f3;">    }</li>
<li>}</li>
</ol>
</div>
</div>
</div>
<p>Before I show the final piece of code and explain what it does, let&#8217;s go through all the various helpers that we need. First, we want to be able to implement custom aspects that will be invoked before throwing exceptions, so let&#8217;s prepare a base attribute class that supports that:</p>
<div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:041fb8e8-d08f-46cd-9105-6ae587728f13" class="wlWriterEditableSmartContent" style="display:inline;float:none;margin:0;padding:0;">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background:#ddd;overflow:auto;">
<ol style="background:#ffffff;white-space:nowrap;margin:0 0 0 2em;padding:0 0 0 5px;" start="1">
<li>[<span style="color:#2b91af;">MulticastAttributeUsage</span>(<span style="color:#2b91af;">MulticastTargets</span>.Method | <span style="color:#2b91af;">MulticastTargets</span>.InstanceConstructor | <span style="color:#2b91af;">MulticastTargets</span>.StaticConstructor)]</li>
<li style="background:#f3f3f3;">[<span style="color:#2b91af;">RequirePostSharp</span>(<span style="color:#a31515;">&#8220;Padre.PostSharp&#8221;</span>, <span style="color:#a31515;">&#8220;Padre.PostSharp&#8221;</span>)]</li>
<li>[<span style="color:#2b91af;">Serializable</span>]</li>
<li style="background:#f3f3f3;"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">abstract</span> <span style="color:#0000ff;">class</span> <span style="color:#2b91af;">OnThrowAspectAttribute</span> : <span style="color:#2b91af;">MulticastAttribute</span>, <span style="color:#2b91af;">IAspect</span></li>
<li>{</li>
<li style="background:#f3f3f3;">    <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">abstract</span> <span style="color:#0000ff;">void</span> OnThrow(<span style="color:#2b91af;">Exception</span> exception);</li>
<li>}</li>
</ol>
</div>
</div>
</div>
<p>The minidump generation code will just implement this aspect. You can of course do anything else, like logging the exception, in the following way:</p>
<div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:a45f6dfa-26fe-44ac-8f56-0029adc229b6" class="wlWriterEditableSmartContent" style="display:inline;float:none;margin:0;padding:0;">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background:#ddd;overflow:auto;">
<ol style="background:#ffffff;white-space:nowrap;margin:0 0 0 2.5em;padding:0 0 0 5px;" start="1">
<li>[<span style="color:#2b91af;">Serializable</span>]</li>
<li style="background:#f3f3f3;"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">class</span> <span style="color:#2b91af;">ClrDumpAspectAttribute</span> : <span style="color:#2b91af;">OnThrowAspectAttribute</span></li>
<li>{</li>
<li style="background:#f3f3f3;">    <span style="color:#0000ff;">private</span> <span style="color:#0000ff;">bool</span> IsWorthCapturing(<span style="color:#2b91af;">Exception</span> exception)</li>
<li>    {</li>
<li style="background:#f3f3f3;">        <span style="color:#008000;">//&#8230;</span></li>
<li>    }</li>
<li style="background:#f3f3f3;"></li>
<li>    <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">override</span> <span style="color:#0000ff;">void</span> OnThrow(<span style="color:#2b91af;">Exception</span> exception)</li>
<li style="background:#f3f3f3;">    {</li>
<li>        <span style="color:#0000ff;">if</span> (IsWorthCapturing(exception))</li>
<li style="background:#f3f3f3;">            <span style="color:#2b91af;">ClrDump</span>.Dump();</li>
<li>    }</li>
<li style="background:#f3f3f3;">}</li>
</ol>
</div>
</div>
</div>
<p>To be able to call into the aspect code, we need to set RequiresRuntimeInstance to true, and gather the required assets:</p>
<div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:1f0b041d-3b97-4a60-ba21-e0eda4c67b30" class="wlWriterEditableSmartContent" style="display:inline;float:none;margin:0;padding:0;">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background:#ddd;overflow:auto;">
<ol style="background:#ffffff;white-space:nowrap;margin:0 0 0 2.5em;padding:0 0 0 5px;" start="1">
<li><span style="color:#0000ff;">private</span> <span style="color:#0000ff;">sealed</span> <span style="color:#0000ff;">class</span> <span style="color:#2b91af;">Assets</span></li>
<li style="background:#f3f3f3;">{</li>
<li>    <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">readonly</span> <span style="color:#2b91af;">IMethod</span> OnThrow;</li>
<li style="background:#f3f3f3;">    <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">readonly</span> <span style="color:#2b91af;">ITypeSignature</span> Exception;</li>
<li></li>
<li style="background:#f3f3f3;">    <span style="color:#0000ff;">public</span> Assets(<span style="color:#2b91af;">ModuleDeclaration</span> module)</li>
<li>    {</li>
<li style="background:#f3f3f3;">        OnThrow = module.FindMethod(<span style="color:#0000ff;">typeof</span>(<span style="color:#2b91af;">OnThrowAspectAttribute</span>).GetMethod(<span style="color:#a31515;">&#8220;OnThrow&#8221;</span>, <span style="color:#0000ff;">new</span>[] { <span style="color:#0000ff;">typeof</span>(<span style="color:#2b91af;">Exception</span>) }), <span style="color:#2b91af;">BindingOptions</span>.Default);</li>
<li>        Exception = module.FindType(<span style="color:#0000ff;">typeof</span>(<span style="color:#2b91af;">Exception</span>));</li>
<li style="background:#f3f3f3;">    }</li>
<li>}</li>
</ol>
</div>
</div>
</div>
<p>In the AspectWeaverInstance we can call our MethodBodyVisitor to scan for throw instructions:</p>
<div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:222058e7-48c5-441d-aa80-c0c383dd8db3" class="wlWriterEditableSmartContent" style="display:inline;float:none;margin:0;padding:0;">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background:#ddd;overflow:auto;">
<ol style="background:#ffffff;white-space:nowrap;margin:0 0 0 2em;padding:0 0 0 5px;" start="1">
<li><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">override</span> <span style="color:#0000ff;">void</span> Implement(<span style="color:#2b91af;">MethodBodyTransformationContext</span> context)</li>
<li style="background:#f3f3f3;">{</li>
<li>    context.InstructionBlock.MethodBody.Visit(<span style="color:#0000ff;">new</span>[] { <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">Visitor</span>(<span style="color:#0000ff;">this</span>, context) });</li>
<li style="background:#f3f3f3;">}</li>
</ol>
</div>
</div>
</div>
<p>Now, finally, the actual IL transformation for all throw instructions found:</p>
<div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:54ba8abc-dbd8-4e63-b181-d27610ff72a2" class="wlWriterEditableSmartContent" style="display:inline;float:none;margin:0;padding:0;">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background:#ddd;overflow:auto;">
<ol style="background:#ffffff;white-space:nowrap;margin:0 0 0 2.5em;padding:0 0 0 5px;" start="1">
<li><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">void</span> VisitInstruction(<span style="color:#2b91af;">InstructionReader</span> reader)</li>
<li style="background:#f3f3f3;">{</li>
<li>    <span style="color:#0000ff;">if</span> (reader.CurrentInstruction.OpCodeNumber == <span style="color:#2b91af;">OpCodeNumber</span>.Throw)</li>
<li style="background:#f3f3f3;">    {</li>
<li>        <span style="color:#0000ff;">var</span> assets = ((<span style="color:#2b91af;">OnThrowTransformation</span>)instance.Transformation).assets;</li>
<li style="background:#f3f3f3;"></li>
<li>        context.InstructionBlock.MethodBody.InitLocalVariables = <span style="color:#0000ff;">true</span>;</li>
<li style="background:#f3f3f3;">        <span style="color:#0000ff;">var</span> variable = reader.CurrentInstructionBlock.DefineLocalVariable(assets.Exception, <span style="color:#a31515;">&#8220;&#8221;</span>);</li>
<li></li>
<li style="background:#f3f3f3;">        <span style="color:#2b91af;">InstructionSequence</span> before, after;</li>
<li>        reader.CurrentInstructionSequence.SplitAroundReaderPosition(reader, <span style="color:#0000ff;">out</span> before, <span style="color:#0000ff;">out</span> after);</li>
<li style="background:#f3f3f3;">        <span style="color:#0000ff;">var</span> sequence = reader.CurrentInstructionBlock.AddInstructionSequence(<span style="color:#0000ff;">null</span>, <span style="color:#2b91af;">NodePosition</span>.After, before);</li>
<li></li>
<li style="background:#f3f3f3;">        <span style="color:#0000ff;">var</span> writer = <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">InstructionWriter</span>();</li>
<li>        writer.AttachInstructionSequence(sequence);</li>
<li style="background:#f3f3f3;">        writer.EmitInstructionLocalVariable(<span style="color:#2b91af;">OpCodeNumber</span>.Stloc, variable);</li>
<li>        instance.AspectWeaverInstance.AspectRuntimeInstanceField.EmitLoadField(writer, context.MethodMapping.CreateWriter());</li>
<li style="background:#f3f3f3;">        writer.EmitInstructionLocalVariable(<span style="color:#2b91af;">OpCodeNumber</span>.Ldloc, variable);</li>
<li>        writer.EmitInstructionMethod(<span style="color:#2b91af;">OpCodeNumber</span>.Callvirt, assets.OnThrow);</li>
<li style="background:#f3f3f3;">        writer.EmitInstructionLocalVariable(<span style="color:#2b91af;">OpCodeNumber</span>.Ldloc, variable);</li>
<li>        writer.DetachInstructionSequence();</li>
<li style="background:#f3f3f3;">    }</li>
<li>}</li>
</ol>
</div>
</div>
</div>
<p>Here’s a quick walkthrough of what the code does:</p>
<ul>
<li>lines 7-8: create a temporary variable (unnamed) to store the exception, after making sure that the method initializes stack space for local variables – if we are introducing the first one, it may not be the case;</li>
<li>lines 10-12: split the instruction sequence of the current block, so that we can insert code right before the throw instruction – first sequence will reference everything before the throw, and the second – after (<code>after</code> may be null if throw is the last instruction of the block – this will be true most of the time, as any code after throw is unreachable anyway, and will probably be optimized way, if ever actually written), then create a new instruction sequence between <code>before</code> and <code>throw</code> (attaching directly to <code>before</code> would overwrite existing code);</li>
<li>lines 14-15: create an InstructionWriter, which is a convenient factory of opcodes and their arguments, and attach it to the new instruction sequence;</li>
<li>line 16: store the exception object, which is currently on the stack ready to be thrown, into the temporary variable;</li>
<li>line 17: emit code that will read the deserialized aspect attribute instance (luckily PostSharp does this for us) – we will now have the this value ready for calling OnThrowAspectAttribute.OnThrow;</li>
<li>line 18: push the exception object back to the stack – this will serve as the first argument to OnThrow;</li>
<li>line 19: execute OnThrow as a virtual function;</li>
<li>line 20: push the exception object again to the stack – for the original throw instruction that will immediately follow.</li>
</ul>
<p>It took about 3 hours to get to that 20 line piece of code, but that’s probably still less than it took to write this blog post, and absolutely worth every minute. PostSharp SDK provides a really convenient way of rewriting IL code, and very robust engine that seamlessly integrates with msbuild and VisualStudio. It’s a real shame that SharpCrafters don’t have the resources to market and support it. I imagine a lot of really cool aspects could be developed using it – after all IL manipulation isn’t <em>that</em> hard. And most of the time peverify.exe will tell you exactly what is wrong with the code you produced.</p>
<h2>Trying out the OnThrowAspect</h2>
<p>The final code is available on GitHub as part of the <a href="http://github.com/TripleEmcoder/Padre">PADRE repository</a> (as it serves the same purpose as a the PADRE project partly will &#8211; to generate information-rich minidumps automatically).</p>
<p>Would anyone like to help and create a NuGet package for it? I suppose it would require writing a custom install script to insert PostSharpSearchPath modifications into .csproj files.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://tripleemcoder.com/2012/01/17/creatin-a-custom-postsharp-aspect-with-msil-transformation/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">90</post-id>
		<media:content url="https://0.gravatar.com/avatar/f4638cd124749b4d58d8889ea7777fb7eb81aea61ff5427999e47fe54448d3b6?s=96&#38;d=https%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">tripleemcoder</media:title>
		</media:content>
	</item>
		<item>
		<title>Writing minidumps with PostSharp aspects</title>
		<link>https://tripleemcoder.com/2012/01/08/creating-minidumps-with-postsharp-aspects/</link>
					<comments>https://tripleemcoder.com/2012/01/08/creating-minidumps-with-postsharp-aspects/#respond</comments>
		
		<dc:creator><![CDATA[TripleEmcoder]]></dc:creator>
		<pubDate>Sun, 08 Jan 2012 17:31:20 +0000</pubDate>
				<category><![CDATA[Debugging]]></category>
		<category><![CDATA[PostSharp]]></category>
		<guid isPermaLink="false">http://tripleemcoder.wordpress.com/?p=72</guid>

					<description><![CDATA[In the comments for one of my previous posts, Writing an automatic debugger in 15 minutes, a reader suggested creating minidumps with PostSharp aspects. Although I proved (by the very scientific method of guesstimation &#8211; see Performance impact of running under MDbgEngine) that running under a debugger introduces only a 25% performance penalty, it is [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>In the comments for one of my previous posts, <a href="https://tripleemcoder.wordpress.com/2011/12/10/writing-an-automatic-debugger-in-15-minutes-yes-a-debugger/">Writing an automatic debugger in 15 minutes</a>, a reader suggested creating minidumps with <a href="http://www.sharpcrafters.com">PostSharp</a> aspects. Although I proved (by the very scientific method of guesstimation &#8211; see <a href="https://tripleemcoder.wordpress.com/2011/12/18/performance-impact-of-running-under-mdbgengine/">Performance impact of running under MDbgEngine</a>) that running under a debugger introduces only a 25% performance penalty, it is reasonable to try to avoid it altogether. Today&#8217;s post will be an investigation into using PostSharp as a means of injecting minidump creation code into exception handlers.</p>
<p><span id="more-72"></span></p>
<h2>What we&#8217;re trying to achieve</h2>
<p>Let&#8217;s recap the most important point about minidumps: they can&#8217;t be created in the usual catch-all exception handlers of ASP.NET (in <code>Global.asax</code> or an <code>HttpModule</code>), WinForms (<code>Application.ThreadException</code>) or the general <code>AppDomain.UnhandledException</code>, because when they execute, the stack frames of calls leading up to the exception (along with variable values) are already all lost. The only information available is a stack trace in the Exception object, but&#8217;s that&#8217;s a normal runtime feature (used by Elmah, for example) that doesn&#8217;t provide any value for minidumps. Therefore, we need a way to insert minidump creation code as close to exception throw instructions as possible.</p>
<p>There are at least a few ways to achieve this:</p>
<ul>
<ul>
<li>attach a debugger and respond to exception thrown events &#8211; covered in previous posts, this method has the additional benefit of applying to exceptions originating in external code, including the .NET Framework itself;</li>
<li>insert minidump calls before every throw instruction of your code &#8211; I think I don&#8217;t need to tell you how big of a maintenance nightmare that would be;</li>
<li>insert minidump calls into every catch handler of your code &#8211; there will probably be less of those than throw instructions, bit it&#8217;s still a very weak solution, and it will cost you some context information (stack frames lost between the actual throw and executing catch;</li>
<li>use PostSharp or a different aspect framework to inject code automatically &#8211; in this post I&#8217;ll show you where and how calls can be injected with PostSharp, to create the information-rich minidumps possible.</li>
</ul>
</ul>
<h2>PostSharp and exceptions</h2>
<p>Intercepting exceptions is the first part of the PostSharp tutorial: <a href="http://www.sharpcrafters.com/blog/post/Day-1-e28093-OnExceptionAspect.aspx">PostSharp Principles: Day 1 – OnExceptionAspect</a>. It introduces the <code>OnExceptionAspect</code>, which we could extend the following way to generate minidumps:</p>
<div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:2f6eeaa3-5a2c-430d-95a5-c76e069ebd0c" class="wlWriterEditableSmartContent" style="display:inline;float:none;margin:0;padding:0;">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background:#ddd;overflow:auto;">
<ol style="background:#ffffff;margin:0 0 0 2.5em;padding:0 0 0 5px;" start="1">
<li>[<span style="color:#2b91af;">Serializable</span>]</li>
<li style="background:#f3f3f3;"><span style="color:#0000ff;">class</span> <span style="color:#2b91af;">ClrDumpAspect</span> : <span style="color:#2b91af;">OnExceptionAspect</span></li>
<li>{</li>
<li style="background:#f3f3f3;">    <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">override</span> <span style="color:#0000ff;">void</span> OnException(<span style="color:#2b91af;">MethodExecutionArgs</span> args)</li>
<li>    {</li>
<li style="background:#f3f3f3;">        <span style="color:#2b91af;">ClrDump</span>.Dump();</li>
<li>        <span style="color:#0000ff;">base</span>.OnException(args);</li>
<li style="background:#f3f3f3;">    }</li>
<li>}</li>
</ol>
</div>
</div>
</div>
<p>There is a convenient way of attaching this aspect to all methods in an assembly, described in <a href="http://www.sharpcrafters.com/blog/post/Day-3-Applying-Aspects-with-Multicasting-Part-2.aspx">PostSharp Principles: Day 3 &#8211; Applying Aspects with Multicasting Part 2</a>:</p>
<div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:98270ad8-c305-45c3-9ef5-4bcc1d3892da" class="wlWriterEditableSmartContent" style="display:inline;float:none;margin:0;padding:0;">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background:#ddd;overflow:auto;">
<ol style="background:#ffffff;margin:0 0 0 2em;padding:0 0 0 5px;" start="1">
<li>[<span style="color:#0000ff;">assembly</span>: ClrDumpAspectDemo.<span style="color:#2b91af;">ClrDumpAspect</span>]</li>
</ol>
</div>
</div>
</div>
<p>Here’s what an OnExceptionAspect does:</p>
<blockquote><p>The OnException method is called when an unhandled exception occurs in the target method. PostSharp will wrap the target method in a try/catch where the code we provided will be placed in the catch.</p></blockquote>
<p>Indeed, PostSharp wraps each and every method in an exception handler:</p>
<p><img loading="lazy" data-attachment-id="75" data-permalink="https://tripleemcoder.com/2012/01/08/creating-minidumps-with-postsharp-aspects/postsharp-clrdumpaspect-demo-png/" data-orig-file="https://tripleemcoder.com/wp-content/uploads/2012/01/postsharp-clrdumpaspect-demo.png" data-orig-size="684,504" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}" data-image-title="PostSharp ClrDumpAspect Demo" data-image-description="" data-image-caption="" data-medium-file="https://tripleemcoder.com/wp-content/uploads/2012/01/postsharp-clrdumpaspect-demo.png?w=300" data-large-file="https://tripleemcoder.com/wp-content/uploads/2012/01/postsharp-clrdumpaspect-demo.png?w=600" class="alignnone size-full wp-image-75" title="PostSharp ClrDumpAspect Demo" src="https://tripleemcoder.com/wp-content/uploads/2012/01/postsharp-clrdumpaspect-demo.png?w=600&#038;h=442" alt="" width="600" height="442" srcset="https://tripleemcoder.com/wp-content/uploads/2012/01/postsharp-clrdumpaspect-demo.png?w=600&amp;h=442 600w, https://tripleemcoder.com/wp-content/uploads/2012/01/postsharp-clrdumpaspect-demo.png?w=150&amp;h=111 150w, https://tripleemcoder.com/wp-content/uploads/2012/01/postsharp-clrdumpaspect-demo.png?w=300&amp;h=221 300w, https://tripleemcoder.com/wp-content/uploads/2012/01/postsharp-clrdumpaspect-demo.png 684w" sizes="(max-width: 600px) 100vw, 600px" /></p>
<p>Decompiling with ILSpy shows what the Main method is rewritten to:</p>
<div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:64a992d6-6dfd-44bb-a3f9-d6b435336986" class="wlWriterEditableSmartContent" style="display:inline;float:none;margin:0;padding:0;">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background:#ddd;overflow:auto;">
<ol style="background:#ffffff;margin:0 0 0 2.5em;padding:0 0 0 5px;" start="1">
<li><span style="color:#0000ff;">private</span> <span style="color:#0000ff;">static</span> <span style="color:#0000ff;">void</span> Main(<span style="color:#0000ff;">string</span>[] args)</li>
<li style="background:#f3f3f3;">{</li>
<li>    <span style="color:#0000ff;">try</span></li>
<li style="background:#f3f3f3;">    {</li>
<li>        <span style="color:#2b91af;">Program</span>.Foo(1);</li>
<li style="background:#f3f3f3;">    }</li>
<li>    <span style="color:#0000ff;">catch</span> (<span style="color:#2b91af;">Exception</span> arg_0C_0)</li>
<li style="background:#f3f3f3;">    {</li>
<li>        <span style="color:#2b91af;">MethodExecutionArgs</span> args2 = <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">MethodExecutionArgs</span>(<span style="color:#0000ff;">null</span>, <span style="color:#0000ff;">null</span>);</li>
<li style="background:#f3f3f3;">        <span style="color:#2b91af;">Program</span>.&lt;&gt;<span style="color:#ff0000;">z__Aspects</span>.a2.OnException(args2);</li>
<li>        <span style="color:#0000ff;">throw</span>;</li>
<li style="background:#f3f3f3;">    }</li>
<li>}</li>
</ol>
</div>
</div>
</div>
<p>Personally, I don’t like the fact that every method is now wrapped in a try-catch, but since wisemen say that it doesn’t have a negative performance impact (one proof of that is <a href="http://www.codeproject.com/KB/exception/ExceptionPerformance.aspx">here</a>), we could go along with it. But there a different problem. Take a look at this method (also after rewriting by PostSharp):</p>
<div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:8e2c1d48-bbc3-4c1c-977b-66488d699b6f" class="wlWriterEditableSmartContent" style="display:inline;float:none;margin:0;padding:0;">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background:#ddd;overflow:auto;">
<ol style="background:#ffffff;margin:0 0 0 2.5em;padding:0 0 0 5px;" start="1">
<li><span style="color:#0000ff;">private</span> <span style="color:#0000ff;">static</span> <span style="color:#0000ff;">void</span> Throw(<span style="color:#0000ff;">int</span> i)</li>
<li style="background:#f3f3f3;">{</li>
<li>    <span style="color:#0000ff;">try</span></li>
<li style="background:#f3f3f3;">    {</li>
<li>        <span style="color:#0000ff;">if</span> (i == 1)</li>
<li style="background:#f3f3f3;">        {</li>
<li>            <span style="color:#0000ff;">int</span> j = i + 2;</li>
<li style="background:#f3f3f3;">            <span style="color:#0000ff;">if</span> (j == 3)</li>
<li>            {</li>
<li style="background:#f3f3f3;">                <span style="color:#0000ff;">throw</span> <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">Exception</span>();</li>
<li>            }</li>
<li style="background:#f3f3f3;">        }</li>
<li>        <span style="color:#0000ff;">if</span> (i == 2)</li>
<li style="background:#f3f3f3;">        {</li>
<li>            <span style="color:#0000ff;">throw</span> <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">Exception</span>();</li>
<li style="background:#f3f3f3;">        }</li>
<li>    }</li>
<li style="background:#f3f3f3;">    <span style="color:#0000ff;">catch</span> (<span style="color:#2b91af;">Exception</span> arg_38_0)</li>
<li>    {</li>
<li style="background:#f3f3f3;">        <span style="color:#2b91af;">MethodExecutionArgs</span> args = <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">MethodExecutionArgs</span>(<span style="color:#0000ff;">null</span>, <span style="color:#0000ff;">null</span>);</li>
<li>        <span style="color:#2b91af;">Program</span>.&lt;&gt;<span style="color:#ff0000;">z__Aspects</span>.a5.OnException(args);</li>
<li style="background:#f3f3f3;">        <span style="color:#0000ff;">throw</span>;</li>
<li>    }</li>
<li style="background:#f3f3f3;">}</li>
</ol>
</div>
</div>
</div>
<p>This code exhibits the same problem that I described earlier, when talking about generic catch-all exception handlers, although on a smaller scale – when the exception aspect is run, variables from local blocks are lost – in this case <code>j</code> (which is serves as an extremely hard to calculate value, which we simply must have minidumped). Here is a screenshot form a post-mortem debugging session opened from a minidump generated by the throw instruction on line 10:</p>
<p><img loading="lazy" data-attachment-id="81" data-permalink="https://tripleemcoder.com/2012/01/08/creating-minidumps-with-postsharp-aspects/postsharp-clrdumpaspect-dump1/" data-orig-file="https://tripleemcoder.com/wp-content/uploads/2012/01/postsharp-clrdumpaspect-dump1.png" data-orig-size="762,700" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}" data-image-title="PostSharp ClrDumpAspect Dump 1" data-image-description="" data-image-caption="" data-medium-file="https://tripleemcoder.com/wp-content/uploads/2012/01/postsharp-clrdumpaspect-dump1.png?w=300" data-large-file="https://tripleemcoder.com/wp-content/uploads/2012/01/postsharp-clrdumpaspect-dump1.png?w=600" class="alignnone size-full wp-image-81" title="PostSharp ClrDumpAspect Dump 1" src="https://tripleemcoder.com/wp-content/uploads/2012/01/postsharp-clrdumpaspect-dump1.png?w=600&#038;h=551" alt="" width="600" height="551" srcset="https://tripleemcoder.com/wp-content/uploads/2012/01/postsharp-clrdumpaspect-dump1.png?w=600&amp;h=551 600w, https://tripleemcoder.com/wp-content/uploads/2012/01/postsharp-clrdumpaspect-dump1.png?w=150&amp;h=138 150w, https://tripleemcoder.com/wp-content/uploads/2012/01/postsharp-clrdumpaspect-dump1.png?w=300&amp;h=276 300w, https://tripleemcoder.com/wp-content/uploads/2012/01/postsharp-clrdumpaspect-dump1.png 762w" sizes="(max-width: 600px) 100vw, 600px" /></p>
<h2>Intercepting the throw instruction</h2>
<p>Ideally, we could insert minidump code right before every throw instruction. The simplest way to do this is to always use custom exception types and invoke ClrDump.Dump in their constructors. Below is a similar post-mortem debugging session, this time with a minidump created in an exception constructor:</p>
<p><img loading="lazy" data-attachment-id="82" data-permalink="https://tripleemcoder.com/2012/01/08/creating-minidumps-with-postsharp-aspects/postsharp-clrdumpaspect-dump2/" data-orig-file="https://tripleemcoder.com/wp-content/uploads/2012/01/postsharp-clrdumpaspect-dump2.png" data-orig-size="762,700" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}" data-image-title="PostSharp ClrDumpAspect Dump 2" data-image-description="" data-image-caption="" data-medium-file="https://tripleemcoder.com/wp-content/uploads/2012/01/postsharp-clrdumpaspect-dump2.png?w=300" data-large-file="https://tripleemcoder.com/wp-content/uploads/2012/01/postsharp-clrdumpaspect-dump2.png?w=600" class="alignnone size-full wp-image-82" title="PostSharp ClrDumpAspect Dump 2" src="https://tripleemcoder.com/wp-content/uploads/2012/01/postsharp-clrdumpaspect-dump2.png?w=600&#038;h=551" alt="" width="600" height="551" srcset="https://tripleemcoder.com/wp-content/uploads/2012/01/postsharp-clrdumpaspect-dump2.png?w=600&amp;h=551 600w, https://tripleemcoder.com/wp-content/uploads/2012/01/postsharp-clrdumpaspect-dump2.png?w=150&amp;h=138 150w, https://tripleemcoder.com/wp-content/uploads/2012/01/postsharp-clrdumpaspect-dump2.png?w=300&amp;h=276 300w, https://tripleemcoder.com/wp-content/uploads/2012/01/postsharp-clrdumpaspect-dump2.png 762w" sizes="(max-width: 600px) 100vw, 600px" /></p>
<p>A variation of this would be to apply an OnMethodBoundaryAspect aspect to constructors of all exceptions defined in your assemblies. Using system exceptions, however, would require MSIL rewriting &#8211; to insert aspect code right before the throw instructions. As far as I know, there is no out-of-the-box support for this in PostSharp. Also, as far as I can tell, PostSharp authors are going to great lengths to discourage writing custom aspects like the one we need for minidumps. I get why the <a href="http://www.sharpcrafters.com/blog/post/PostSharp-SDK-is-undocumented-and-unsupported.aspx">PostSharp SDK is unsupported and undocumented</a>. But it would be great if there was at least a null aspect sample to show how to configure PostSharp to load a plugin. With a fair knowledge of MSIL and a class browser, the rest is doable.</p>
<p>I would love to hear from someone with bigger experience in using PostSharp!</p>
]]></content:encoded>
					
					<wfw:commentRss>https://tripleemcoder.com/2012/01/08/creating-minidumps-with-postsharp-aspects/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">72</post-id>
		<media:content url="https://0.gravatar.com/avatar/f4638cd124749b4d58d8889ea7777fb7eb81aea61ff5427999e47fe54448d3b6?s=96&#38;d=https%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">tripleemcoder</media:title>
		</media:content>

		<media:content url="https://tripleemcoder.com/wp-content/uploads/2012/01/postsharp-clrdumpaspect-demo.png" medium="image">
			<media:title type="html">PostSharp ClrDumpAspect Demo</media:title>
		</media:content>

		<media:content url="https://tripleemcoder.com/wp-content/uploads/2012/01/postsharp-clrdumpaspect-dump1.png" medium="image">
			<media:title type="html">PostSharp ClrDumpAspect Dump 1</media:title>
		</media:content>

		<media:content url="https://tripleemcoder.com/wp-content/uploads/2012/01/postsharp-clrdumpaspect-dump2.png" medium="image">
			<media:title type="html">PostSharp ClrDumpAspect Dump 2</media:title>
		</media:content>
	</item>
		<item>
		<title>Performance impact of running under MDbgEngine</title>
		<link>https://tripleemcoder.com/2011/12/18/performance-impact-of-running-under-mdbgengine/</link>
					<comments>https://tripleemcoder.com/2011/12/18/performance-impact-of-running-under-mdbgengine/#comments</comments>
		
		<dc:creator><![CDATA[TripleEmcoder]]></dc:creator>
		<pubDate>Sun, 18 Dec 2011 21:57:18 +0000</pubDate>
				<category><![CDATA[Debugging]]></category>
		<category><![CDATA[PADRE]]></category>
		<guid isPermaLink="false">http://tripleemcoder.wordpress.com/?p=59</guid>

					<description><![CDATA[As promised, this post will present the results of my investigation into the performance impact of running under the simplest possible debugger written using MDbgEngine. Timing method For timing of all the samples, I used this method inside the debugee: private static void Time(Action action, int count) { var sum = 0L; for (var i [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>As promised, this post will present the results of my investigation into the performance impact of running under the simplest possible debugger written using MDbgEngine.<br />
<span id="more-59"></span></p>
<h2>Timing method</h2>
<p>For timing of all the samples, I used this method inside the debugee:</p>
<pre>private static void Time(Action action, int count)
{
    var sum = 0L;

    for (var i = 0; i &lt; count; i++)
    {
        var s = new Stopwatch();
        s.Start();
        action();
        s.Stop();
        sum += s.ElapsedMilliseconds;
        Thread.Sleep(1000);
    }
    Console.WriteLine(sum/count);
}</pre>
<p>To minimize the impact of random system events, I run all of the samples 10 times, with a 1 second pause between each invocation, and then took an arithmetic average of the execution times.</p>
<h2>CPU-bound code</h2>
<pre>private static void CPU(int count)
{
    Array.Sort(Enumerable.Range(1, count).Reverse().ToArray());
}</pre>
<table>
<thead>
<tr>
<th></th>
<th>count = 1 000 000</th>
<th>count = 10 000 000</th>
</tr>
</thead>
<tbody>
<tr>
<td>No debugger</td>
<td align="right">106 ms</td>
<td align="right">1048 ms</td>
</tr>
<tr>
<td>Visual Studio</td>
<td align="right">105 ms</td>
<td align="right">1085 ms</td>
</tr>
<tr>
<td>MDbgEngine</td>
<td align="right">112 ms</td>
<td align="right">1067 ms</td>
</tr>
</tbody>
</table>
<p><strong>Conclusion:</strong> Running under a debugger has no impact on CPU-bound code. All measurements are within the margin of error.</p>
<h2>IO-bound code</h2>
<p>Base on the above findings, and a personal hunch, I decided to skip this one.</p>
<h2>Exception-bound code</h2>
<p>This test should prove most interesting, as it&#8217;s the only that has code really interfacing with the debugger.</p>
<p>The sample code throws exceptions in a loop:</p>
<pre>private static void Exception(int count)
{
    for (int i = 0; i &lt; count; i++)
    {
        try
        {
            throw new Exception();
        }
        catch
        {
        }
    }
}</pre>
<p>And the debugger inspects them and does nothing:</p>
<pre>process.PostDebugEvent +=
    (sender, e) =&gt;
        {
            if (e.CallbackType == ManagedCallbackType.OnBreakpoint)
                process.Go();

            if (e.CallbackType == ManagedCallbackType.OnException2)
            {
                var e2 = (CorException2EventArgs)e.CallbackArgs;
            }

            if (e.CallbackType == ManagedCallbackType.OnProcessExit)
                stop.Set();
        };</pre>
<table>
<thead>
<tr>
<th></th>
<th>count = 1 000</th>
</tr>
</thead>
<tbody>
<tr>
<td>No debugger</td>
<td align="right">41 ms</td>
<td align="right">1.0</td>
</tr>
<tr>
<td>Visual Studio</td>
<td align="right">6380 ms</td>
<td align="right">155.6</td>
</tr>
<tr>
<td>MDbgEngine</td>
<td align="right">1322 ms</td>
<td align="right">32.2</td>
</tr>
</tbody>
</table>
<p><strong>Conclusion:</strong> Going back and forth between the debugger and its debuggee, causes a performance drop of 2 orders of magnitude. I guess Visual Studio is more because of the Output window, which logs all exceptions.</p>
<p>The question is: how many exceptions does code generate on average? Instead of guesstimating, I decided to guessmeasure. All of the code indexed by <a href="http://www.symbolsource.org">SymbolSource</a>, including only the most recent version of each project, consists of more than 1.5 million lines of code (that&#8217;s where I stopped counting). Of the lines used for this measurement, there were 12 thousand lines that contained the word &#8220;throw&#8221;. Therefore, I have guessmeasured, that all code is 0.8% exception on average.</p>
<p><strong>Final conclusion:</strong> running under MDbgEngine causes a 24.8% drop in performance.</p>
<p>Would you be willing to take that, for the promise of gaining access to detailed call stacks and being able to generate minidumps for really hard to catch bugs?</p>
<p>Personally, I&#8217;ll shout a loud yes for all development and integration, and for occasional production too.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://tripleemcoder.com/2011/12/18/performance-impact-of-running-under-mdbgengine/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">59</post-id>
		<media:content url="https://0.gravatar.com/avatar/f4638cd124749b4d58d8889ea7777fb7eb81aea61ff5427999e47fe54448d3b6?s=96&#38;d=https%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">tripleemcoder</media:title>
		</media:content>
	</item>
		<item>
		<title>Accessing stack traces with MDbgEngine and PADRE</title>
		<link>https://tripleemcoder.com/2011/12/11/accessing-stack-traces-with-mdbgengine-and-padre/</link>
					<comments>https://tripleemcoder.com/2011/12/11/accessing-stack-traces-with-mdbgengine-and-padre/#respond</comments>
		
		<dc:creator><![CDATA[TripleEmcoder]]></dc:creator>
		<pubDate>Sun, 11 Dec 2011 15:18:03 +0000</pubDate>
				<category><![CDATA[Debugging]]></category>
		<category><![CDATA[PADRE]]></category>
		<guid isPermaLink="false">http://tripleemcoder.wordpress.com/?p=49</guid>

					<description><![CDATA[In my previous post, I showed how MDbgEngine (available on NuGet) can be used to stop a process when an exception is thrown, and how a minidump can then be created to enable post-mortem debugging. Using MDbgEngine, you can do much, much more &#8211; and all with a very high-level API.Have a look at how [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>In my previous post, I showed how MDbgEngine (available on <a href="https://nuget.org/packages/Microsoft.Samples.Debugging.MdbgEngine">NuGet</a>) can be used to stop a process when an exception is thrown, and how a minidump can then be created to enable post-mortem debugging.</p>
<p>Using MDbgEngine, you can do much, much more &#8211; and all with a very high-level API.<span id="more-49"></span>Have a look at how you can print a call stack (with argument values!):</p>
<pre>process.PostDebugEvent +=
    (sender, e) =&gt;
    {
        log.Log(e.CallbackType.ToString());

        if (e.CallbackType == ManagedCallbackType.OnException2)
        {
            var ce = (CorException2EventArgs)e.CallbackArgs;

            if (ce.EventType == CorDebugExceptionCallbackType.DEBUG_EXCEPTION_FIRST_CHANCE)
            {
                var thread = process.Threads.Lookup(ce.Thread);

                foreach (var frame in thread.Frames)
                {
                    if (!frame.IsManaged || frame.Function.FullName.StartsWith("System."))
                        break;

                    log.Log("{0}({1})", frame.Function.FullName, string.Join(", ", frame.Function.GetArguments(frame).Select(
                        arg =&gt; string.Format("{0} = {1}", arg.Name, arg.GetStringValue(false)))));
                }
            }
        }
    };</pre>
<p>This code, when attached to an example process, printed logged the following information:</p>
<pre>OnException2
AspNet.Default.B(i = 3, t = "test 2")
AspNet.Default.A(i = 1, t = "test")</pre>
<h2>PADRE &#8211; Pluggable Automatic Debugging and Reporting Engine</h2>
<p>In the previous blog post, and on Twitter, I&#8217;ve already mentioned the idea of turning this into a project. The above sample code is now available on <a href="http://github.com/TripleEmcoder/Padre">GitHub</a>, along with some boilerplate code in MEF, to make it truly pluggable and a sample ASP.NET application throwing exceptions.</p>
<p>Just open the solution, run it and go to the ASP.NET application to click Button 2. You should get a stack trace in the console window like above.</p>
<p>I&#8217;d love to hear some feedback!</p>
]]></content:encoded>
					
					<wfw:commentRss>https://tripleemcoder.com/2011/12/11/accessing-stack-traces-with-mdbgengine-and-padre/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">49</post-id>
		<media:content url="https://0.gravatar.com/avatar/f4638cd124749b4d58d8889ea7777fb7eb81aea61ff5427999e47fe54448d3b6?s=96&#38;d=https%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">tripleemcoder</media:title>
		</media:content>
	</item>
		<item>
		<title>Writing an automatic debugger in 15 minutes (yes, a debugger!)</title>
		<link>https://tripleemcoder.com/2011/12/10/writing-an-automatic-debugger-in-15-minutes-yes-a-debugger/</link>
					<comments>https://tripleemcoder.com/2011/12/10/writing-an-automatic-debugger-in-15-minutes-yes-a-debugger/#comments</comments>
		
		<dc:creator><![CDATA[TripleEmcoder]]></dc:creator>
		<pubDate>Sat, 10 Dec 2011 21:13:21 +0000</pubDate>
				<category><![CDATA[Debugging]]></category>
		<category><![CDATA[PADRE]]></category>
		<guid isPermaLink="false">http://tripleemcoder.wordpress.com/?p=35</guid>

					<description><![CDATA[Seriously, it will take you longer to read this long introduction, than to code a working debugger in C#. You may also want to check out: Accessing stack traces with MDbgEngine and PADRE Performance impact of running under MDbgEngine Bugs in production Remember all those reports coming back form clients saying &#8220;hey, your program crashed&#8221; [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><em>Seriously, it will take you longer to read this long introduction, than to code a working debugger in C#.</em></p>
<p><em>You may also want to check out:</em></p>
<ul>
<li><a title="Accessing stack traces with MDbgEngine and PADRE" href="https://tripleemcoder.wordpress.com/2011/12/11/accessing-stack-traces-with-mdbgengine-and-padre/">Accessing stack traces with MDbgEngine and PADRE</a></li>
<li><a href="https://tripleemcoder.wordpress.com/2011/12/18/performance-impact-of-running-under-mdbgengine/">Performance impact of running under MDbgEngine</a></li>
</ul>
<h2>Bugs in production</h2>
<p>Remember all those reports coming back form clients saying &#8220;hey, your program crashed&#8221; or &#8220;hey, your is site showing these ugly yellow pages at random moments&#8221;? So do I. Unfortunately, there isn&#8217;t much that can be done to diagnose problems in running software, basically we&#8217;re at the mercy of our clients&#8217; reports (which vary in quality, most of the time tending towards useless) or more or less verbose logging. Having those, we can reproduce issues during a debugging session to see what code causes them. If that fails,  we can go to the extremes of attaching a debugger in a production environment. Not feeling enough pressure today? Attach to a live site and try to setup breakpoints the exact way needed to only catch the error, and not stop a milion people from doing their daily work. At first try. Logging, on the other hand is very safe, it but will only tell you as much as you predicted that would be needed.</p>
<p>Now what if we could have something in the middle? More than logging, but less than an interactive debugging session?<br />
<span id="more-35"></span></p>
<h2>Windows Error Reporting</h2>
<p>In the ancient times, when not all software run as web applications, and especially in the even darker times when programs were being written mostly in native code, you could often see hard crashes that literally made entire applications disappear. Then Microsoft invented Windows Error Reporting, that filled that post-crash emptiness with a nice-looking window that supposedly gathered some data and sent it back to the author. This feature is present in all recent versions of Windows, and is available not only for Microsoft applications, but also for third party programs. Provided that their author gets a signing certificate (authenticode), signs all components of the software and registers on a deeply hidden Microsoft site. If all these conditions are met, Windows will automatically create a so called minidump of the process when it crashes (with important parts of memory, including stack traces of all threads) and  ask the user to allow sending it to Microsoft.</p>
<p>Since a minidump contains stack state of all threads at the moment of the crash, it allows you to open a post-mortem debugging session, and feel almost as if you were attached to the original process when the failure occured. WinDbg has supported this since&#8230; probably always, but Visual Studio 2010 does so too &#8211; although through a slightly hidden feature of just opening (File -&gt; Open -&gt; File&#8230;) minidumps, i.e. *.dmp files.</p>
<p>Just having access to precise call stacks used to be a killer feature at the time, but does it provide any value to the .NET developer, used to getting stack traces with every exception?</p>
<p>You guessed it: yes, it does.</p>
<p>With a minidump, you&#8217;ll be able to see parameter and variable values for all functions on the call stack.</p>
<h2>Crashes in a .NET world</h2>
<p>Before we go deeper, we need to clarify one thing. What exactly is a crash? What causes Windows Error Reporting to kick in? It&#8217;s unhandled exceptions. Native unhandled exceptions. Normally, the last exception handler registered in a running process is a system function that reports program failure, which in turn causes a default (defined in the registry) system just-in-time debugger to launch &#8211; which will be Windows Error Reporting a.k.a Dr. Watson, Visual Studio, or something else depending on your setup. Some programs also register their own unhandled exception handlers to report errors. Firefox does that, Winamp too. Perhaps you&#8217;ve already seen their crash windows in action. By registering their own handlers, these programs can create minidumps of their own liking (there are various types to choose from) and send them wherever they want.</p>
<p>What about .NET apps then? Do they crash at all? Of course they do, but unfortunately not in the sense described so far. You can have an unhandled managed exception in your code, but it will always be caught by the runtime &#8211; which in turn prints a stack trace (in a console application), shows a pop-up window (in a Windows Forms application) or displays the Yellow Screen of Death (in a web application). No minidump will ever be created automatically for a .NET application.</p>
<h2>Creating minidumps manually</h2>
<p>A minidump is created by calling <code>MiniDumpWriteDump</code> from <code>dbghelp.dll</code>. Mind though, that it needs to be a version from <a href="http://msdn.microsoft.com/en-us/windows/hardware/gg463009">Debugging Tools for Windows</a>, not the Windows system folder. There are various tools that call it, like SysInternals&#8217; <a href="http://technet.microsoft.com/en-us/sysinternals/dd996900">ProcDump</a>. MiniDumpWriteDump and ProcDump have been described in an article in the recent edition of MSDN Magazine: <a href="http://msdn.microsoft.com/en-us/magazine/hh580738.aspx">Writing a Plug-in for Sysinternals ProcDump v4.0</a>.</p>
<p>One of those tools is also <a href="http://www.debuginfo.com/tools/clrdump.html">ClrDump</a>, which is available both as a very simple command-line tool and a convenient library. Read this blog post, and you&#8217;ll know everything about how to create minidumps from .NET applications: <a href="http://voneinem-windbg.blogspot.com/2007/03/creating-and-analyzing-minidumps-in-net.html">Creating and analyzing minidumps in .NET production applications</a>.</p>
<h2>Choosing the right place and time</h2>
<p>The last article I linked to has one thing wrong though. It triggers minidump generation from <code>AppDomain.UnhandledException</code> and <code>Application.ThreadException</code>. And it would be equally wrong to call it from an error handler in <code>Global.asax</code> or to register one with an HttpModule, like Elmah does. The reason is that those handlers are called from a generic exception handler at the base of your application. At this point all of the context (call stack, variables) available where the exception was thrown is lost. To really benefit from minidumps, you need to trigger them as deep in your call hierarchy as you can. Also, often you&#8217;ll face exceptions that are caught by your own code, but you&#8217;ll still want minidumps generated, to better explain why those exceptions occured.</p>
<p>And let&#8217;s not forget generating minidumps like this is similar to debugging with printf &#8211; you need to modify code and redeploy. We need something smarter. And external to the inspected application.</p>
<h2>Writing a managed debugger in C#</h2>
<p>The CLR exposes debugging capabilities through COM, so it isn&#8217;t impossible for a mere mortal to implement a debugger. But thanks to the <a href="http://www.microsoft.com/download/en/details.aspx?id=2282">CLR Managed Debugger Sample</a> anyone can do it, really. The sample mainly consists of a console tool, <code>mdbg.exe</code>, that you can use as a poor-man&#8217;s replacement for <code>windbg.exe</code> or <code>cdb.exe</code>, and &#8211; more importantly &#8211; a shared debuging engine library, written in C#. The latter is now also available on NuGet (courtesy of yours truly) as <a href="https://nuget.org/packages/Microsoft.Samples.Debugging.MdbgEngine">Microsoft.Samples.Debugging.MdbgEngine</a>.</p>
<p>Let&#8217;s consider this trivial console test application:</p>
<pre>namespace TestApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            A(1, new { property = 2 });
        }

        private static void A(int i, object state)
        {
            B(i + 4, state);
        }

        private static void B(int i, object state)
        {
            try
            {
                C(i);
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception.Message + ": " + i);
            }
        }

        private static void C(int i)
        {
            throw new InvalidOperationException("Expected failure");
        }
    }
}</pre>
<p>Here is an only slighly longer console application that runs a debugger and creates minidumps on each exception (as you can see, also those caught in code):</p>
<pre>using Microsoft.Samples.Debugging.CorDebug;
using Microsoft.Samples.Debugging.MdbgEngine;

namespace DebuggerApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            var stop = new ManualResetEvent(false);
            var engine = new MDbgEngine();
            var process = engine.CreateProcess("TestApplication.exe", "", DebugModeFlag.Default, null);
            process.Go();

            process.PostDebugEvent +=
                (sender, e) =&gt;
                    {
                        if (e.CallbackType == ManagedCallbackType.OnBreakpoint)
                            process.Go();

                        if (e.CallbackType == ManagedCallbackType.OnException2)
                        {
                            ClrDump.CreateDump(process.CorProcess.Id, @"C:\temp.dmp", (int)MINIDUMP_TYPE.MiniDumpWithFullMemory, 0, IntPtr.Zero);
                        }

                        if (e.CallbackType == ManagedCallbackType.OnProcessExit)
                            stop.Set();
                    };

            stop.WaitOne();
        }
    }
}</pre>
<p>Go ahead and try it. If you open <code>test.dmp</code> in Visual Studio, you&#8217;ll be able to see not only the call stack at the moment when the exception occurred, not only values of variables that are easy to log (like <code>i</code>), but you&#8217;ll be also able to inspect complex and dynamic structures (like <code>state</code>).</p>
<p><strong>I hope you&#8217;re having a big &#8220;holy shit&#8221; moment. I definitely did.</strong></p>
<h2>Where can we go from here?</h2>
<p>The code above &#8220;logs&#8221; all exceptions. To implement this idea in the real world, we&#8217;d need quite a bit more &#8211; load symbols (you know where to get those from &#8211; <a href="http://www.symbolsource.org">SymbolSource</a>), set breakpoints at specific locations, catch only specified exceptions.</p>
<p>Catch me on Twitter if you like the idea. This has potential for a great and very useful open source project.</p>
<p>We also have some very cool ideas how to integrate this with SymbolSource. Imagine setting breakpoints on the website and choosing exceptions to monitor, then seeing automatically collected reports from all your deployments. Call stacks with variable values, failure statistics, minidumps for download and offline analysis.</p>
<p><strong>Interested?</strong></p>
]]></content:encoded>
					
					<wfw:commentRss>https://tripleemcoder.com/2011/12/10/writing-an-automatic-debugger-in-15-minutes-yes-a-debugger/feed/</wfw:commentRss>
			<slash:comments>30</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">35</post-id>
		<media:content url="https://0.gravatar.com/avatar/f4638cd124749b4d58d8889ea7777fb7eb81aea61ff5427999e47fe54448d3b6?s=96&#38;d=https%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">tripleemcoder</media:title>
		</media:content>
	</item>
	</channel>
</rss>
