<?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/"
	>

<channel>
	<title>Dude, where is my Kaizen? &#187; Utilities</title>
	<atom:link href="http://www.bjoernrochel.de/tag/utilities/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bjoernrochel.de</link>
	<description>Björn Rochel&#039;s weblog</description>
	<lastBuildDate>Mon, 21 Jun 2010 07:26:00 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>A good resource for learning Castle.DynamicProxy</title>
		<link>http://www.bjoernrochel.de/2009/07/28/a-good-resource-for-learning-castledynamicproxy/</link>
		<comments>http://www.bjoernrochel.de/2009/07/28/a-good-resource-for-learning-castledynamicproxy/#comments</comments>
		<pubDate>Tue, 28 Jul 2009 19:19:37 +0000</pubDate>
		<dc:creator>BjRo</dc:creator>
				<category><![CDATA[Utilities]]></category>

		<guid isPermaLink="false">http://www.bjoernrochel.de/?p=464</guid>
		<description><![CDATA[Castle.DynamicProxy is one of those really cool libraries with really poor documentation. Today I stumbled over Krysztof Kozmics blog, which has a really, really good tutorial for Castle.DynamicProxy. The tutorial covers most of its features. If you&#8217;re interested, give it a try. You won&#8217;t regret it . . .
Here&#8217;s the link: http://kozmic.pl/category/23.aspx
]]></description>
			<content:encoded><![CDATA[<p>Castle.DynamicProxy is one of those really cool libraries with really poor documentation. Today I stumbled over Krysztof Kozmics blog, which has a really, really good tutorial for Castle.DynamicProxy. The tutorial covers most of its features. If you&#8217;re interested, give it a try. You won&#8217;t regret it . . .</p>
<p>Here&#8217;s the link: <a href="http://kozmic.pl/category/23.aspx" target="_blank">http://kozmic.pl/category/23.aspx</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.bjoernrochel.de/2009/07/28/a-good-resource-for-learning-castledynamicproxy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to shoot yourself in the foot with ILMerge</title>
		<link>http://www.bjoernrochel.de/2009/07/07/how-to-shoot-yourself-in-the-foot-with-ilmerge/</link>
		<comments>http://www.bjoernrochel.de/2009/07/07/how-to-shoot-yourself-in-the-foot-with-ilmerge/#comments</comments>
		<pubDate>Tue, 07 Jul 2009 16:48:04 +0000</pubDate>
		<dc:creator>BjRo</dc:creator>
				<category><![CDATA[Utilities]]></category>
		<category><![CDATA[ILMerge]]></category>

		<guid isPermaLink="false">http://www.bjoernrochel.de/?p=370</guid>
		<description><![CDATA[xUnit.BDDExtensions and is now completely merged into a single assembly. However, getting to that state wasn&#8217;t as straight forward as I originally expected. 
The initial problem 
xUnit.BDDExtensions internally depends on StructureMap, StructureMap.AutoMocking and Rhino.Mocks. However, I don&#8217;t like the need to carry around 3 extra assemblies with me, especially if I don&#8217;t use them directly [...]]]></description>
			<content:encoded><![CDATA[<p>xUnit.BDDExtensions and is now completely merged into a single assembly. However, getting to that state wasn&#8217;t as straight forward as I originally expected. </p>
<p><b>The initial problem </b></p>
<p>xUnit.BDDExtensions internally depends on StructureMap, StructureMap.AutoMocking and Rhino.Mocks. However, I don&#8217;t like the need to carry around 3 extra assemblies with me, especially if I don&#8217;t use them directly in the xUnit.BDDExtensions API. So I decided to give <a href="http://research.microsoft.com/en-us/people/mbarnett/ilmerge.aspx" target="_blank">ILMerge</a> a try and started with this: </p>
<p></p>
<pre class="brush: csharp">
ILMerge.exe /t:library /out:&#039;Deploy/xUnit.BDDExtensions.dll&#039; &#039;xUnit.BDDExtensions.dll&#039; &#039;StructureMap.dll&#039; &#039;StructureMap.AutoMocking.dll&#039; &#039;Rhino.Mocks.dll&#039;
</pre>
</p>
<p>Initial merging went fine, but when I tried to actually use the merged assembly in a solution also containing a StructureMap binary, I received a lot of build errors indicating duplicate types. The solution simply didn&#8217;t compile any more. Crap ! </p>
<p><b>What went wrong </b></p>
<p>The way I merged the assemblies, all public types of the dependent assemblies stayed public (although they&#8217;re only internally used). The merged assembly exposed all public APIs of the merged-in assemblies. When using the assembly in conjunction with one of the original assemblies (for instance StructureMap) the compiler basically didn&#8217;t know which type my code was actually referring to. Hence the error. </p>
<p>Besides the observed effect those APIs can clearly be confusing to a developer with no knowledge that the assembly at hand is actually a merged one. So imho definitely a situation which needed to be fixed.<br />
  <br /><b></b></p>
<p><b>How to fix it<br />
    <br /></b>What needed to be done is to internalize the all public types of the merged-in assemblies. The related switch for this in ILMerge is &#8216;/internalize&#8217;. </p>
<pre class="brush: csharp">
ILMerge.exe /t:library /internalize /out:&#039;Deploy/xUnit.BDDExtensions.dll&#039; &#039;xUnit.BDDExtensions.dll&#039; &#039;StructureMap.dll&#039; &#039;StructureMap.AutoMocking.dll&#039; &#039;Rhino.Mocks.dll&#039;
</pre>
<p>The solution using both xUnit.BDDExtensions and StructureMap now compiled without errors. Duplicate type issue solved. Everything fine now? Nope, obviously internalization created some other problems: Specs driven by xUnit.BDDExtensions showed that neither the auto-mocking feature nor the mock support worked anymore. Nearly every test failed due to an internal exception. </p>
<p><b>How to fix it (Take 2)<br />
    <br /></b>The problem with the internalization of all public types is that sometimes the merged APIs somehow depend on several types being public. If you take that away, you effectively break their functionality. In my case my problems where created by Castle.DynamicProxy2 (which is used by  Rhino.Mocks internally) and StructureMap. Both tools are doing dynamic type generation internally and the generated types wanted to implement some interfaces which were formally public but now weren&#8217;t accessible any more. To my luck ILMerge provides a workaround for situations like that: You can exclude types from being internalized. Here&#8217;s what I did in order to make it work: </p>
<p></p>
<pre class="brush: csharp">
ILMerge.exe /t:library /internalize:&#039;Build/ILMergeIncludes.txt&#039; /out:&#039;Deploy/xUnit.BDDExtensions.dll&#039; &#039;xUnit.BDDExtensions.dll&#039; &#039;StructureMap.dll&#039; &#039;StructureMap.AutoMocking.dll&#039; &#039;Rhino.Mocks.dll&#039;
</pre>
<p>Notice the modified &#8216;/internalize&#8217; switch. A file now specifies the types to exclude from the internalization. ILMerge expects the file to contain a regular expression per line. Every line is evaluated against each type name and automatically excluded from the internalization process in case the regular expression matches. My exclude file looks like this: </p>
<p><pre class="brush: csharp">
StructureMap.InstanceBuilder
StructureMap.Pipeline.*
Rhino.Mocks.Interfaces.IMockedObject
Castle.Core.Interceptor.IProxyTargetAccessor
Castle.DynamicProxy.AbstractInvocation
Castle.DynamicProxy.Generators.AttributesToAvoidReplicating
</pre>
<p><b>Lessons learned<br />
    <br /></b>Merging for deployment isn&#8217;t that hard, but you have to be careful that everything works as expected after you&#8217;ve created the merged assembly. A successful ILMerge call doesn&#8217;t necessarily mean that everything&#8217;s fine and works as expected. On the other hand the ILMerge documentation is very good and provided me with a simple solution to the problem. I&#8217;ve shot myself in the foot, but it&#8217;s bandaged and I can walk again, so to say. If you&#8217;re interested in doing something similar (not the shooting part) I highly suggest that you should give ILMerge a try . . . </p>
<p><b>Sidenotes </b><b><br />
    <br /></b>Is it possible that ILMerge fails to merge WPF based assemblies? I&#8217;m currently experiencing strange effects when trying to merge them. Anyone? </p>
]]></content:encoded>
			<wfw:commentRss>http://www.bjoernrochel.de/2009/07/07/how-to-shoot-yourself-in-the-foot-with-ilmerge/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Determining the CLR directory</title>
		<link>http://www.bjoernrochel.de/2009/07/06/determining-the-clr-directory/</link>
		<comments>http://www.bjoernrochel.de/2009/07/06/determining-the-clr-directory/#comments</comments>
		<pubDate>Mon, 06 Jul 2009 18:38:36 +0000</pubDate>
		<dc:creator>BjRo</dc:creator>
				<category><![CDATA[Utilities]]></category>

		<guid isPermaLink="false">http://www.bjoernrochel.de/2009/07/06/determining-the-clr-directory/</guid>
		<description><![CDATA[If you ever need to locate the directory of the CLR version which&#160; runs your .NET application, this little helper might be exactly what you need. At least it was exactly what I needed today   


 System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory(); 

]]></description>
			<content:encoded><![CDATA[<p>If you ever need to locate the directory of the CLR version which&#160; runs your .NET application, this little helper might be exactly what you need. At least it was exactly what I needed today <img src='http://www.bjoernrochel.de/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />  </p>
<pre class="brush: csharp">

 System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory(); 
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.bjoernrochel.de/2009/07/06/determining-the-clr-directory/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
