<?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>Fredrik Haglund's blog &#187; Debug</title>
	<atom:link href="http://blog.fredrikhaglund.se/blog/tag/debug/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.fredrikhaglund.se</link>
	<description>Chatter about EPiServer, ASP.NET, CSS and Web Development.</description>
	<lastBuildDate>Tue, 28 Jun 2011 13:37:32 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Debugging &#8220;Exception has been thrown by the target of an invocation&#8221;</title>
		<link>http://blog.fredrikhaglund.se/blog/2009/12/22/debugging-exception-has-been-thrown-by-the-target-of-an-invocation/</link>
		<comments>http://blog.fredrikhaglund.se/blog/2009/12/22/debugging-exception-has-been-thrown-by-the-target-of-an-invocation/#comments</comments>
		<pubDate>Tue, 22 Dec 2009 05:00:00 +0000</pubDate>
		<dc:creator>Fredrik Haglund</dc:creator>
				<category><![CDATA[EPiServer]]></category>
		<category><![CDATA[Debug]]></category>

		<guid isPermaLink="false">http://blog.fredrikhaglund.se/blog/2009/12/22/debugging-exception-has-been-thrown-by-the-target-of-an-invocation/</guid>
		<description><![CDATA[I got a question how to find what was wrong when you only got an error “Exception has been thrown by the target of an invocation. [The server committed a protocol violation The server response was: …]” from a junior developer and I want to share my answer with all of you since it can [...]]]></description>
			<content:encoded><![CDATA[<p>I got a question how to find what was wrong when you only got an error “Exception has been thrown by the target of an invocation. [The server committed a protocol violation The server response was: …]” from a junior developer and I want to share my answer with all of you since it can be a little tricky.</p>
<p>The Exception “thrown by the target of invocation” indicated that an error has occurred in code called by using invoke through dot net reflection. This technique is common when you have plug-ins (like scheduled jobs in EPiServer) and other late binding in run-time.</p>
<p>The text in square brackets are the original exception (caught by the <em>Invoke()</em> method) and gives a clue what goes wrong but it is usually not enough to find the error.</p>
<h3>How to find more clues when debugging</h3>
<p>As always when searching for the cause of a problem or error condition the first rule is to get more clues.&#160; Usually this process consist of finding a reproducible test scenario that triggers the condition and hook up the debugger to see what is happening inside the application.</p>
<p>We must make sure it halts on thrown exceptions even if it outside our code to get a call stack that can help us. Open your options dialog and uncheck ”Enable Just My Code”.</p>
<p><a href="http://blog.fredrikhaglund.se/wp-content/uploads/2009/12/clip_image002.jpg"><img style="border-bottom: 0px; border-left: 0px; display: inline; margin-left: 0px; border-top: 0px; margin-right: 0px; border-right: 0px" title="clip_image002" border="0" alt="clip_image002" align="right" src="http://blog.fredrikhaglund.se/wp-content/uploads/2009/12/clip_image002_thumb.jpg" width="244" height="143" /></a></p>
<p>With default settings the debugger will only break on uncaught exceptions. We need the debugger to break when an exceptions are thrown regardless of they are handled by a try-catch statement.</p>
<p>This can be changed in your Exceptions dialog (Ctrl+Alt+E). You can either set it to catch all managed exceptions as I have in the screen shot below or if you know what exception you are looking for you can halt on that one alone to minimize noise since it will probably halt on exceptions a lot of places that are normal before reaching your area of intrest.</p>
<p><a href="http://blog.fredrikhaglund.se/wp-content/uploads/2009/12/clip_image004.jpg"><img style="border-bottom: 0px; border-left: 0px; display: inline; margin-left: 0px; border-top: 0px; margin-right: 0px; border-right: 0px" title="clip_image004" border="0" alt="clip_image004" align="left" src="http://blog.fredrikhaglund.se/wp-content/uploads/2009/12/clip_image004_thumb.jpg" width="240" height="125" /></a></p>
<p>With this setup we are now ready to run the test case again to trigger the error. If everything is correctly configured it will break on the exception and show you a call stack.</p>
<p>Use the debugger windows in Visual Studio to examine the Call Stack. Inspect parameters and Local Variables at each step in the call stack. This should give enough clues so to find what is causing the error.</p>
<h3>How to find more clues when you do not have the source code</h3>
<p>If the exception is raised in code that is not our own we can use several strategies to find out more. One of the best is to use Lutz Roeder’s .NET Reflector and click File&gt;Open to load all assemblies in your web applications bin-folder. Search for the class or method and Disassemble the methods outside your code and get more clues. (Another way, if the exception is inside Microsoft code, is to configure VS to use Microsoft source server to download source code.)</p>
<p><a href="http://blog.fredrikhaglund.se/wp-content/uploads/2009/12/clip_image006.jpg"><img style="border-bottom: 0px; border-left: 0px; display: inline; margin-left: 0px; border-top: 0px; margin-right: 0px; border-right: 0px" title="clip_image006" border="0" alt="clip_image006" align="right" src="http://blog.fredrikhaglund.se/wp-content/uploads/2009/12/clip_image006_thumb.jpg" width="244" height="176" /></a></p>
<p>Here is an example of when I caught a “Exception has been thrown by the target of an invocation.&#160; [NullReferenceException: Object reference not set to an instance of an object.]“ and found <i>TransformCategoryForExport</i> in the call stack.</p>
<p>By analyzing the call stack we can usually also find the point in our own code that is starting the chain of calls causing the exception. I would recommend setting a break point there and rerunning the test case to see if the parameters to the call are invalid.</p>
<h3>Need more help?</h3>
<p>God luck with you bug hunting! If you are stuck you are welcome to contact me at INEXOR and buy my services.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.fredrikhaglund.se/blog/2009/12/22/debugging-exception-has-been-thrown-by-the-target-of-an-invocation/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>EPiServer Export, Import or Mirror Troubles?</title>
		<link>http://blog.fredrikhaglund.se/blog/2008/03/28/episerver-export-import-or-mirror-troubles/</link>
		<comments>http://blog.fredrikhaglund.se/blog/2008/03/28/episerver-export-import-or-mirror-troubles/#comments</comments>
		<pubDate>Fri, 28 Mar 2008 16:28:22 +0000</pubDate>
		<dc:creator>Fredrik Haglund</dc:creator>
				<category><![CDATA[EPiServer]]></category>
		<category><![CDATA[Category]]></category>
		<category><![CDATA[Debug]]></category>
		<category><![CDATA[Disassemble]]></category>
		<category><![CDATA[EPiServer 5]]></category>
		<category><![CDATA[Export]]></category>
		<category><![CDATA[Import]]></category>
		<category><![CDATA[Mirror]]></category>
		<category><![CDATA[PageTypeTransfer]]></category>
		<category><![CDATA[PropertyCategoryTransform]]></category>
		<category><![CDATA[TransformCategoryForExport]]></category>

		<guid isPermaLink="false">http://blog.fredrikhaglund.se/blog/2008/03/28/episerver-export-import-or-mirror-troubles/</guid>
		<description><![CDATA[I have been working a lot with migration and mirroring lately using EPiServer&#8217;s functions for export and import of data. My EPiServer Wish list Show call stack when exceptions halt export or import jobs Show PageID and Property related to errors and warnings during import and export This area of the product is still one [...]]]></description>
			<content:encoded><![CDATA[<p>I have been working a lot with migration and mirroring lately using EPiServer&#8217;s functions for export and import of data.</p>
<div class="insert insertright">
<h3>My EPiServer Wish list</h3>
<ul>
<li>Show call stack when exceptions halt export or import jobs</li>
<li>Show PageID and Property related to errors and warnings during import and export</li>
</ul>
</div>
<p>This area of the product is still one of EPiServer weaker areas mainly because the error massages when something goes wrong does not contain enough information.</p>
<p>I want to share the last issue I run into today and also show how I did to find out what was wrong. We could not export and only got this lovely message:</p>
<p><code>The following errors have occurred: Exception: Object reference not set to an instance of an object.[]</code></p>
<p>As you can see not much to go on here&#8230;</p>
<h3>Strategy to resolve issues with EPiServer Export</h3>
<p><a href="http://blog.fredrikhaglund.se/wp-content/uploads/2008/03/image15.png"><img border="0" align="right" width="244" src="http://blog.fredrikhaglund.se/wp-content/uploads/2008/03/image-thumb3.png" alt="image" height="143" style="border-width: 0px" /></a> First thing you should do is to narrow down what is causing our problems and a call stack can often help. 1) We need to attach your debugger to the web server.</p>
<p>2) We must make sure it halts on thrown exceptions even if it outside our code. Open your options dialog and uncheck&#8221;Enable Just My Code&#8221;.</p>
<p><img border="0" align="left" width="244" src="http://blog.fredrikhaglund.se/wp-content/uploads/2008/03/image-thumb4.png" alt="image" height="127" style="border-width: 0px" />With default settings the debugger will only break on uncaught exceptions.</p>
<p>3) We need the debugger to break when an exceptions are thrown regardless of they are handled by a try-catch statement.</p>
<p>This can be changed in your Exceptions dialog (Ctrl+Shift+E). You can either set it to catch all managed exceptions as I have in the screen shot or if you know what exception you are looking for you can halt on that one alone.</p>
<p>We are now ready to start the export again to trigger the error. If everything is correctly configured it will break on the exception and show you a call stack.</p>
<h3>Analyzing the call stack and Disassembling EPiServer</h3>
<p><a href="http://blog.fredrikhaglund.se/wp-content/uploads/2008/03/image16.png"><img border="0" align="right" width="244" src="http://blog.fredrikhaglund.se/wp-content/uploads/2008/03/image-thumb5.png" alt="image" height="176" style="border-width: 0px" /></a>With a call stack we have more clues to go on. In this case the two methods on top of the call stack gives us valuable clues.</p>
<p>Use <em>Lutz Roeder&#8217;s .NET Reflector</em> and click File&gt;Open to load all assemblies in your web applications bin-folder. Search for the class or method and Disassemble the two methods and get more clues.</p>
<p><code>PropertyCategoryTransform.TransformCategoryForExport<br />
PageTypeTransfer.Export</code></p>
<p>In this case it is probable that calling split on <em>categoriesAsIds</em> when <em>categoriesAsIds</em> is null is the culprit.</p>
<p><a href="http://blog.fredrikhaglund.se/wp-content/uploads/2008/03/image17.png"><img border="0" align="left" width="244" src="http://blog.fredrikhaglund.se/wp-content/uploads/2008/03/image-thumb6.png" alt="image" height="148" style="border: 0px" /></a> Looking at the calling method we can see that it is calling <em>TransformCategoryForExport</em> for <em>PageDefinitions</em> (a <em>PageDefinition</em> is another name for a property on a page type) if it as a Category. It does so to convert the Default Value for a Category property into a string with names instead of integer ids.</p>
<h3>Conclusion and workaround</h3>
<p>It is not possible to export a page type if you add a property of type Category selection (in EPiServer CMS 5 RC1 SP1 5.1.422.122). The reason is that default value is null and an easy workaround is to set the default value to &#8220;1&#8243; for each added Category property. The value &#8220;1&#8243; is the root category.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.fredrikhaglund.se/blog/2008/03/28/episerver-export-import-or-mirror-troubles/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

