<?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>{(something&#124;&#124;other).soft()} &#187; silverlight</title>
	<atom:link href="http://www.somethingorothersoft.com/tag/silverlight/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.somethingorothersoft.com</link>
	<description>About Software Development And Other Stuff By Igor Zevaka</description>
	<lastBuildDate>Mon, 25 Jul 2011 00:03:47 +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>Keeping your sanity whilst developing for Windows Phone 7</title>
		<link>http://www.somethingorothersoft.com/2010/04/28/keeping-your-sanity-whilst-developing-for-windows-phone-7/</link>
		<comments>http://www.somethingorothersoft.com/2010/04/28/keeping-your-sanity-whilst-developing-for-windows-phone-7/#comments</comments>
		<pubDate>Tue, 27 Apr 2010 23:04:18 +0000</pubDate>
		<dc:creator>igor</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[silverlight]]></category>
		<category><![CDATA[windows-phone-7]]></category>
		<category><![CDATA[wpf]]></category>

		<guid isPermaLink="false">http://www.somethingorothersoft.com/?p=368</guid>
		<description><![CDATA[Dealing with those obtuse run-time errors whilst developing for WP7.

<img src="http://www.somethingorothersoft.com/wp-content/uploads/2010/04/frustration-300x299.jpg"/>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.somethingorothersoft.com/wp-content/uploads/2010/04/frustration-300x299.jpg"><img src="http://www.somethingorothersoft.com/wp-content/uploads/2010/04/frustration-300x299.jpg" alt="" title="frustration-300x299" width="300" height="299" class="alignnone size-full wp-image-380" /></a></p>

<p>Please note that this post is written in April 2010, when the WP7 SDK is only one month old. Most of the issues described here will likely not be a problem in later releases. The defining characteristic of such pre-release SDK is that when you are doing the right thing, everything is OK. When you screw up, it just goes KABOOM! without much explanation.</p>

<p>I spent a few hours of trying to work out why I am getting these run-time errors and so I&#8217;ve put together a list of the most painful ones, enjoy.</p>

<h2>Using <code>{x:Static ...}</code> Syntax</h2>

<p><strong>Problem:</strong> <code>{x:Static ...}</code> is not supported in Silverlight.</p>

<p>If you to do something like this:</p>

<div><pre class="brush: xml; title: ; notranslate">
&lt;DiscreteObjectKeyFrame  KeyTime=&quot;00:00:00&quot; Value=&quot;{x:Static Visibility.Collapsed}&quot;&gt;
</pre></div>

<p>You will get an obtuse error at runtime:</p>

<p><pre>
A first chance exception of type 'System.Windows.Markup.XamlParseException' occurred in System.Windows.dll
Additional information: 2024 An error has occurred. [Line: 114 Position: 61]
</pre></p>

<p>Get used to seeing that error. It&#8217;ll happen every time you screw up the XAML. Sometimes it&#8217;s more helpful than other times and you get the line number of the offending XAML. The line number, along with the exception text will be available in the Output window:</p>

<p><a href="http://www.somethingorothersoft.com/wp-content/uploads/2010/04/crash1.png"><img src="http://www.somethingorothersoft.com/wp-content/uploads/2010/04/crash1-1024x611.png" alt="" title="crash1" width="450" height="268" class="alignnone size-large wp-image-369" /></a></p>

<p>If you are like me and rarely look at the error window, perhaps you should start now. This particular error doesn&#8217;t raise a warning during compilation, but does come up as an error when the file is open in the editor:</p>

<p><a href="http://www.somethingorothersoft.com/wp-content/uploads/2010/04/xaml_error.png"><img src="http://www.somethingorothersoft.com/wp-content/uploads/2010/04/xaml_error.png" alt="" title="xaml_error" width="641" height="262" class="alignnone size-full wp-image-370" /></a></p>

<p><strong>Solution:</strong> Don&#8217;t use <code>x:Static</code> but instead an instance of a type in XAML like so:</p>

<div><pre class="brush: xml; title: ; notranslate">
    &lt;DiscreteObjectKeyFrame  KeyTime=&quot;00:00:00&quot;&gt;
        &lt;DiscreteObjectKeyFrame.Value&gt;
            &lt;Visibility&gt;Collapsed&lt;/Visibility&gt;
        &lt;/DiscreteObjectKeyFrame.Value&gt;
    &lt;/DiscreteObjectKeyFrame&gt;
</pre></div>

<h2>Misspelling Animation Element or Property Name</h2>

<p><strong>Problem:</strong> Misspelling Animation Element or Property Name</p>

<p>In the below code <code>Storyboard.TargetName</code> is invalid. The project compiles and there are no errors in the error window.</p>

<div><pre class="brush: xml; title: ; notranslate">
    &lt;ObjectAnimationUsingKeyFrames Storyboard.TargetName=&quot;SearchBoxMisspelled&quot; Storyboard.TargetProperty=&quot;Visibility&quot;&gt;
        &lt;!--animation key frames--&gt;
    &lt;/ObjectAnimationUsingKeyFrames&gt;
</pre></div>

<p>At run-time, you get this error message:</p>

<p><pre>
A first chance exception of type 'System.InvalidOperationException' occurred in System.Windows.dll
An unhandled exception of type 'System.InvalidOperationException' occurred in System.Windows.dll
Additional information: 2213 An error has occurred.
</pre></p>

<p>The call stack only tells you that this is something to do with the animation:</p>

<p><pre>
System.Windows.dll!MS.Internal.XcpImports.MethodEx(System.IntPtr ptr = 146517008, string name = "Begin", MS.Internal.CValue[] cvData = null) + 0x9d bytes
System.Windows.dll!MS.Internal.XcpImports.MethodEx(System.Windows.DependencyObject obj = {System.Windows.Media.Animation.Storyboard}, string name = "Begin") + 0x6 bytes<br />
System.Windows.dll!MS.Internal.XcpImports.Storyboard_Begin(System.Windows.Media.Animation.Storyboard storyboard = {System.Windows.Media.Animation.Storyboard})
System.Windows.dll!System.Windows.Media.Animation.Storyboard.Begin() + 0x6 bytes
</pre></p>

<p><strong>Solution:</strong> To resolve this, check your animation element and property names. Unfortunately I haven&#8217;t found a way to get at the offending animation frame from the call stack. Would be happy to find out if there is a way.</p>

<h2>References&#8217; Dependencies</h2>

<p><strong>Problem:</strong> &#8220;Object reference is not set to an instance of an object&#8221; error when debugging and crashes when running without debugger.</p>

<p>After adding a reference library you might start getting this error when you debug the project:</p>

<p><a href="http://www.somethingorothersoft.com/wp-content/uploads/2010/04/error_debugging.png"><img src="http://www.somethingorothersoft.com/wp-content/uploads/2010/04/error_debugging.png" alt="" title="error_debugging" width="391" height="171" class="alignnone size-full wp-image-371" /></a></p>

<p>This is caused, as far as I can tell, by your references&#8217; dependencies not being copied to the device. After hours of playing around with this it&#8217;s apparent to me that this is an intermittent issue with Visual Studio. It is supposed to work out what all the references&#8217; dependencies are, copy them to the output folder and add them to the manifest file (<code>$(OutputDir)\AppManifest.xaml</code>).</p>

<p>Sometimes that doesn&#8217;t happen and the app gets deployed without those dependencies. It will still work, up until the point where a class is referenced from a dependant assembly and that assembly cannot be loaded. I expect this problem to go away in later releases of WP7 SDK.</p>

<p>The error will look something like this:</p>

<p><a href="http://www.somethingorothersoft.com/wp-content/uploads/2010/04/runtime_error.png"><img src="http://www.somethingorothersoft.com/wp-content/uploads/2010/04/runtime_error.png" alt="" title="runtime_error" width="396" height="772" class="alignnone size-full wp-image-372" /></a></p>

<p><pre>
2024 An error has occurred[Line: <line> Position: <position>]
at
System.Windows.Application.LoadComponent
...Rest of the callstack.
</pre></p>

<p><strong>Solution:</strong> Add all the assembiles that your references depend upon as references to the project.
<strong>Edit:</strong> This error kept happening to me until my coworker pointed out the solution, which led to the &#8220;Doh moment of the week.&#8221;
<strong>Solution2:</strong> When debugging the project <strong>select the project in the solution pane and press F5</strong>. Yeah, that simple.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.somethingorothersoft.com/2010/04/28/keeping-your-sanity-whilst-developing-for-windows-phone-7/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

