<?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>The Inquisitive Coder - Davy Brion&#039;s Blog &#187; Silverlight</title> <atom:link href="http://davybrion.com/blog/category/silverlight/feed/" rel="self" type="application/rss+xml" /><link>http://davybrion.com/blog</link> <description>inquisitive: adjective. given to inquiry, research, or asking questions; eager for knowledge; intellectually curious</description> <lastBuildDate>Mon, 14 May 2012 21:08:36 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.2</generator> <item><title>Silverlight&#8217;s Broken Promise</title><link>http://davybrion.com/blog/2011/11/silverlights-broken-promise/</link> <comments>http://davybrion.com/blog/2011/11/silverlights-broken-promise/#comments</comments> <pubDate>Sun, 20 Nov 2011 17:31:42 +0000</pubDate> <dc:creator>Davy Brion</dc:creator> <category><![CDATA[Opinions]]></category> <category><![CDATA[Silverlight]]></category><guid
isPermaLink="false">http://davybrion.com/blog/?p=3808</guid> <description><![CDATA[By now, I'm sure you've all read about the rumors that the upcoming Silverlight 5 might be the last release of Silverlight. Of course, people who've been paying attention to the Silverlight news coming out of Microsoft and the blogosphere in the past year shouldn't be surprised at this. But for those of you who [...]]]></description> <content:encoded><![CDATA[<p>By now, I'm sure you've all read about the rumors that the upcoming Silverlight 5 might be the last release of Silverlight. Of course, people who've been paying attention to the Silverlight news coming out of Microsoft and the blogosphere in the past year shouldn't be surprised at this. But for those of you who are still in the "oh please, it's just a rumor" camp, you might want to keep in mind that every negative rumor about Silverlight of the past year has turned out to be true. As a result, I fully expect the upcoming Silverlight 5 release to indeed be the last stop along a troubled line.</p><p>Plenty of Silverlight developers were concerned that their investment in the technology would end up being worthless. I never really understood that since I've always believed that good developers focus on skills that are transferable to multiple technologies instead of betting it all on a single technology. Nevertheless, many Silverlight developers were up in arms, but their worries and fears seem to have been calmed by the news that Windows 8 will make extensive use of XAML. Silverlight developers will be able to transfer their XAML skills to building Metro apps and of course, WP7 apps. And there's no reason to assume that Microsoft intends to change its smartphone platform in a way that would diminish the importance of XAML. So, Silverlight developers who were worried that their skills will be worthless don't really have anything to worry about and I'm sure many of them are quite relieved by that. After all, many Silverlight projects will be able to run as native apps on Windows 8 with relatively minor modifications.</p><p>Of course, that doesn't quite offer a solution to the thorny little issue about all the Silverlight projects that have been developed because of some of the benefits that Silverlight promised: cross platform and browser-independent availability of the plugin. The promise was that you could develop projects that would be available to users no matter what platform or browser that they were using (believers of this promise would even mention Moonlight, which has never really offered a truly compatible version), and with no deployment-related issues. After all, users only needed to have the Silverlight plugin installed to run your software. And that promise has been broken. Yes, you can migrate your Silverlight projects to Windows 8. Yes, people will be able to keep running existing Silverlight projects as long as they have the upcoming Silverlight 5 runtime installed. But we also already know that the Metro version of IE10 will <em>not</em> run the Silverlight plugin and that running the plugin in the 'desktop' version of IE10 will require users to install it themselves. For enterprise software, that's not much of an issue but you do have to ask yourself: how long are you willing to hang on to a plugin that Microsoft itself is no longer interested in improving in the long run?</p><p>The reality of the matter is that your Silverlight products only have a future if you convert them to WinRT so they can run on Metro natively. Which means you've lost the ability to reach users on multiple platforms and devices. The very same technology you picked because of its cross-browser and cross-platform benefits has forced you on a path where in the future, you can only target users on the Windows platform meaning either Windows 8 or WP7. Sure, you can hang on to the fact that the plugin will be available for a few more years, but that also is a limiting choice since an ever increasing number of users will be running iOS and Android, and there's no reason whatsoever to expect the plugin to actually run on those platforms. Hell, WP7 doesn't even have the Silverlight plugin for its browser. My previous employer pretty much bet it all on Silverlight, mostly because they didn't want to deal with HTML/JavaScript, but also because they thought it would eventually be available on all devices. Which essentially means they're stuck with a couple of products that only really have a long-term future on Windows 8 or WP7, and its subsequent versions. Unless of course, current promises about said platforms are broken again. Yet another reason to start taking open standards and technologies that have multiple stakeholders seriously, I suppose.</p><div
class="bottomcontainerBox" style=""><div
style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <iframe
src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fdavybrion.com%2Fblog%2F2011%2F11%2Fsilverlights-broken-promise%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:85px; height:21px;"></iframe></div><div
style="float:left; width:80px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <g:plusone size="medium" href="http://davybrion.com/blog/2011/11/silverlights-broken-promise/"></g:plusone></div><div
style="float:left; width:95px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <a
href="http://twitter.com/share" class="twitter-share-button" data-url="http://davybrion.com/blog/2011/11/silverlights-broken-promise/"  data-text="Silverlight&#8217;s Broken Promise" data-count="horizontal" data-via="davybrion"></a></div><div
style="float:left; width:105px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script type="in/share" data-url="http://davybrion.com/blog/2011/11/silverlights-broken-promise/" data-counter="right"></script></div><div
style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script src="http://www.stumbleupon.com/hostedbadge.php?s=1&amp;r=http://davybrion.com/blog/2011/11/silverlights-broken-promise/"></script></div></div><div
style="clear:both"></div><div
style="padding-bottom:4px;"></div>]]></content:encoded> <wfw:commentRss>http://davybrion.com/blog/2011/11/silverlights-broken-promise/feed/</wfw:commentRss> <slash:comments>14</slash:comments> </item> <item><title>Yet Another Nail In Silverlight&#8217;s Coffin?</title><link>http://davybrion.com/blog/2011/06/yet-another-nail-in-silverlights-coffin/</link> <comments>http://davybrion.com/blog/2011/06/yet-another-nail-in-silverlights-coffin/#comments</comments> <pubDate>Sat, 04 Jun 2011 13:07:26 +0000</pubDate> <dc:creator>Davy Brion</dc:creator> <category><![CDATA[Opinions]]></category> <category><![CDATA[Silverlight]]></category><guid
isPermaLink="false">http://davybrion.com/blog/?p=3303</guid> <description><![CDATA[As i'm sure you know by now, Microsoft caused a bit of a stir in the .NET development community with their recent 10 minute demo of Windows 8. More specifically, the fact that they explicitly mentioned HTML5 and JavaScript as one of the ways to build these new-look Windows 8 applications while neglecting to mention [...]]]></description> <content:encoded><![CDATA[<p>As i'm sure you know by now, Microsoft caused a bit of a stir in the .NET development community with their recent 10 minute demo of Windows 8.  More specifically, the fact that they explicitly mentioned HTML5 and JavaScript as one of the ways to build these new-look Windows 8 applications while neglecting to mention Silverlight or WPF left a lot of developers wondering what the future holds for both Silverlight and WPF.  An interesting <a
href="http://forums.silverlight.net/forums/p/230502/562113.aspx">thread</a> showed up on the Silverlight forums where Silverlight developers expressed their fear for the future of their platform.  I've been following that thread with a lot of interest, not only because the statements and behavior displayed in that thread are both hilarious and astounding, but because i wanted to see how Microsoft would react to it.</p><p>Surely, if the core audience of one of their most-touted technologies of the past years started to doubt the future of their platform so openly, a response to calm down the fears would have to be forthcoming, no?  The only Microsoft employee to respond was Pete Brown, and i thought it was quite telling:</p><blockquote> You all saw a very small technology demo of Windows 8, and a brief press release. We're all being quiet right now because we can't comment on this. It's not because we don't care, aren't listening, have given up, or are agreeing or disagreeing with you on something. All I can say for now is to please wait until September. If we say more before then, that will be great, but there are no promises (and I'm not aware of any plans) to say more right now. I'm very sorry that there's nothing else to share at the moment. I know that answer is terrible, but it's all that we can say right now. Seriously.</blockquote><p>Followed by:</p><blockquote> Guys, I've been pretty clear that my hands are tied here, so don't read anything more into my lack of comments than that. We simply aren't allowed to say anything about this. It's not that we have nothing to say. It's not that we don't care. It's not that I personally don't care, because I do, a lot.</blockquote><p>And finally:</p><blockquote> This whole thing has blown way out of proportion. Base your information on our primary sources (like our press release), not on third party speculation. That's not to minimize how everyone feels, but keep in mind that Windows 8 itself is still a ways off from retail, and even much further away from internal IT adoption. The 8 weeks until //build/ is a pretty small amount of time to wait in comparison. Take some vacation time this summer, and look forward to the //build/ conference. Stop speculating based on just a small demo of some very cool new technology. Tell your management to do the same: if they're basing your project work for the next X years on the results of a quick demo for an unreleased operating system, then they are doing you and your company a real disservice.</blockquote><p>If i were still a Silverlight developer, i'd find the final sentence quite insulting.  If anything, Microsoft is doing a sizable portion of their customers a disservice by being so unclear about the future of one of their technologies.  This certainly isn't the first storm to come up about Silverlight's future, and every time people have openly questioned the future of the platform Microsoft has responded <a
href="http://davybrion.com/blog/2010/11/never-underestimate-the-power-of-a-message/">rather softly</a>.  There's never been a convincing and strong "we are fully committed to making Silverlight a smart choice for the future" kind of response.  And this time, no response at all. Just silence. Deafening silence even, because of Pete's remark that they are not even <em>allowed</em> to talk about it.  Once again, the Silverlight community is screaming for a real response and they're being ignored. They're being told to wait until September.</p><p>Obviously, i don't know what Microsoft is planning for Silverlight, but i really have difficulties understanding how any company could still trust it as a viable technological choice.  First the mixed messages, then the clear favoritism Microsoft is showing towards HTML5 and JavaScript (which, IMO, is justified but that's another topic), and now the unwillingness to stand up for one of their products that is being doubted so openly, for the first time by its very users who only want assurance of Microsoft that their investments in the technology haven't been a total waste.  I took a lot of flack from the Silverlight community when i scored Silverlight so low in the 'strategic' department in my <a
href="http://davybrion.com/blog/2011/03/why-were-going-with-html5-instead-of-silverlight/">post where i detailed how we came to the conclusion to go with HTML(5) instead of Silverlight</a> but this recent PR fiasco kind of validates that score IMO.</p><p>However, Microsoft certainly isn't the only one to blame here.  If you read the thread i linked to, you'll see some reactions from people who've pretty much put all of their eggs in the Silverlight basket and are now reacting angrily towards Microsoft.  If any of those people are reading this, allow me to quote myself from 2 posts that i wrote over 6 months ago:</p><blockquote> If however, your product is supposed to become the basis of your long-term success, then the choice of Silverlight over HTML/CSS/JavaScript is short-sighted and ultimately flawed for a number of reasons. The first of which is that Silverlight is a proprietary technology in the worst possible way. Its future will be determined by a single company who naturally hold their own best interest at heart, and not yours. As long as it makes sense for them to keep improving Silverlight, they will and you can benefit from that. As soon as it no longer makes sense for them, the technology will become increasingly irrelevant. Obviously, that is a risk that you face with any kind of technology. Sticking with open standards and open source software might very well result in the same outcome but there is one tremendously important difference here: with Silverlight, you have no migration path.</blockquote><p>That quote was from '<a
href="http://davybrion.com/blog/2010/09/keep-your-eyes-on-the-road/">Keep Your Eyes On The Road</a>', written in September 2010.  And the next quote is from '<a
href="http://davybrion.com/blog/2010/10/developers-shouldnt-specialize/">Developers Shouldn't Specialize</a>', written in October 2010:</p><blockquote> There's also another factor to keep in mind, which is more important than you might realize. If you specialize in technology from commercial vendors, you need to keep the market forces in mind that could influence the vendor. Those market forces might be (or seem) irrelevant to you, but the vendor will not let that influence its decisions and strategies if the vendor itself is competing with other companies on a much larger level than your company or your clients are. And when a vendor changes tactics due to market forces, the technology you've chosen to specialize in might be on the way out, or it might no longer be the hot new thing that you can capitalize on. And that is where one of the biggest dangers in specialization lies. If you're specialized in a specific technology, you're personally invested in it. Your current standard of life, your livelihood, depends largely on that specific technology. Sure, you can move on to something else but you will have to get used to less than you're used to, probably both in money and stature for a while. Realistically speaking, odds are high that you are emotionally attached to this technology because of this. When you are confronted with bad news regarding the technology's future, you're likely to exhibit classic denial symptoms. The recent news about the Silverlight strategy shift and specifically the reactions to it, is a beautiful example of this.</blockquote><p>Anyone who's upset at Microsoft about this has only himself to blame. You've put yourself in this position, because the writing has been on the wall for a while now.</p><div
class="bottomcontainerBox" style=""><div
style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <iframe
src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fdavybrion.com%2Fblog%2F2011%2F06%2Fyet-another-nail-in-silverlights-coffin%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:85px; height:21px;"></iframe></div><div
style="float:left; width:80px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <g:plusone size="medium" href="http://davybrion.com/blog/2011/06/yet-another-nail-in-silverlights-coffin/"></g:plusone></div><div
style="float:left; width:95px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <a
href="http://twitter.com/share" class="twitter-share-button" data-url="http://davybrion.com/blog/2011/06/yet-another-nail-in-silverlights-coffin/"  data-text="Yet Another Nail In Silverlight&#8217;s Coffin?" data-count="horizontal" data-via="davybrion"></a></div><div
style="float:left; width:105px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script type="in/share" data-url="http://davybrion.com/blog/2011/06/yet-another-nail-in-silverlights-coffin/" data-counter="right"></script></div><div
style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script src="http://www.stumbleupon.com/hostedbadge.php?s=1&amp;r=http://davybrion.com/blog/2011/06/yet-another-nail-in-silverlights-coffin/"></script></div></div><div
style="clear:both"></div><div
style="padding-bottom:4px;"></div>]]></content:encoded> <wfw:commentRss>http://davybrion.com/blog/2011/06/yet-another-nail-in-silverlights-coffin/feed/</wfw:commentRss> <slash:comments>18</slash:comments> </item> <item><title>Why We&#8217;re Going With HTML(5) Instead Of Silverlight</title><link>http://davybrion.com/blog/2011/03/why-were-going-with-html5-instead-of-silverlight/</link> <comments>http://davybrion.com/blog/2011/03/why-were-going-with-html5-instead-of-silverlight/#comments</comments> <pubDate>Sun, 06 Mar 2011 18:11:15 +0000</pubDate> <dc:creator>Davy Brion</dc:creator> <category><![CDATA[ASP.NET MVC]]></category> <category><![CDATA[Silverlight]]></category><guid
isPermaLink="false">http://davybrion.com/blog/?p=3126</guid> <description><![CDATA[I recently had to research which UI technology would be the best choice for the applications that my client is going to build in the next couple of years. This is a .NET shop, so there are 2 major directions you could move into: standards-based web development, or Silverlight. When you have to recommend one [...]]]></description> <content:encoded><![CDATA[<p>I recently had to research which UI technology would be the best choice for the applications that my client is going to build in the next couple of years. This is a .NET shop, so there are 2 major directions you could move into: standards-based web development, or Silverlight. When you have to recommend one over the other, you ideally want to be able to back up your choice with more than just some opinions.  So we made a list of candidates and did a POC for each one. Then we came up with a list of criteria, grouped in a bunch of categories. The criteria were all assigned a weight, and we scored each of them for all candidates.</p><p>In this post, i want to go over the categories of criteria, and discuss our findings. I'm also going to share the spreadsheet so you can go through the numbers yourself. Depending on your needs or your opinions, you can change the weights and the scores and see how that affects the outcome. I removed some of the criteria that were specific to my client, but it didn't have a significant impact on the outcome. For this post, I also limited the candidates to ASP.NET MVC 3 in combination with the jQuery family (jQuery Core, jQuery UI and jQuery Mobile) and Silverlight.</p><p>Here's a quick listing of the categories and some of their criteria (for the actual list, check the spreadsheet... the link is at the end of the post):</p><ul><li>User experience (compelling UI, accessibility, intuitive/ease-of-use, accessible from multiple devices, accessable from multiple platforms)</li><li>Infrastructure (easy/flexible deployment, monitorability)</li><li>Security (safe from XSS, CSRF)</li><li>Performance (server footprint, client-side resource usage, asynchronicity, UI responsiveness, initial load times)</li><li>Code/Architecture (maturity, reusability of validation logic, simplicity, maintainability, flexibility, power, testability, i18n, feedback cycle, learning curve, potential efficiency, rapid application prototyping, readable URLs, extensibility)</li><li>People (limits the number of required skills, mindshare, documentation, community support, commercial support)</li><li>Strategic (future-proof, standards-compliant, differentiator, backing, vision)</li><li>License (do we have access to the code?)</li><li>Cost</li><li>Tools (IDE support, availability of extra tools, free 3rd party component availability, commercial 3rd party component availability</li></ul><p>Depending on what you or your organization requires, some of these might not apply to you. Perhaps there are other criteria that you find important and that we missed. Nevertheless, i think this is a pretty comprehensive list which covers most of the factors that you need to think about when making this kind of decision.</p><p>This graph visualizes how both technologies scored, grouped by category:</p><p><a
href="http://davybrion.com/blog/wp-content/uploads/2011/02/webdev_vs_silverlight.png" rel="prettyPhoto[3126]"><img
src="http://davybrion.com/blog/wp-content/uploads/2011/02/webdev_vs_silverlight.png" alt="" title="webdev_vs_silverlight" width="756" height="500" class="aligncenter size-full wp-image-3143" /></a></p><p>I'm sure there are quite a few things about that image that surprise you. The first thing you might be thinking is "how can Silverlight score so badly when it comes to User Experience?". The answer to that is quite simple: if your users aren't using a desktop/laptop with Windows or OS X on it, there is no experience to be had at all. Users that require assistive technology are out of luck as well since accessibility support in Silverlight is still very poor. If you hold those factors into account, it really doesn't matter much that you can easily make Silverlight applications incredibly flashy (pardon the pun).  Besides, most people get bored and annoyed with excessive animations rather quickly, so you're often better off not to overdo it. With that in mind, jQuery UI and HTML5 will easily meet your needs for that kind of stuff.</p><p>Another area where Silverlight scores very poorly is the strategic department. The fact that it's not standards-compliant obviously hurts a lot here, but there's more to it than that. First of all, the mobile story (again) pretty much kills it. Android and iOS don't support it.  We already know it's never going to work on iOS and as long as it doesn't work on iOS, Android has no reason whatsoever to provide support because Silverlight simply isn't important in the grand scheme of things to any of the important players. Microsoft hasn't even announced a Silverlight browser plugin for WP7 yet and who knows if it will? That means that Silverlight web applications aren't usable on <em>any</em> mobile device right now, except for slates running a full Windows OS which looks like its only a tiny portion of the market.  Secondly, despite its original tagline of "Lighting up the web", it appears that Microsoft only has about 3 scenario's in mind where it still actively pushes Silverlight: <em>internal</em> business applications, video streaming and native WP7 development.  While internal business applications are certainly a large part of what we're going to do in the next couple of years, we're also going to build things that are available publicly and to a large variety of people. Going with Silverlight for the internal applications and HTML(5) for the public-facing applications wouldn't be very cost-efficient either since that means we have to train our developers for both cases. And it wouldn't make much sense anyway since HTML(5) is a great fit for internal business apps as well.</p><p>But, as you can see, there are areas where Silverlight scores better than ASP.NET MVC 3 with jQuery. For instance, when it comes to Tools, you can't deny the fact that Visual Studio and Blend cover a lot of ground when it comes to the whole Silverlight developer experience.  At the very least, you can mostly stick to your familiar integrated environment, whereas with standards-based web development, you're likely to spend some time in Firebug or Google Chrome's developer tools instead of sticking almost entirely with Visual Studio.  I personally don't mind (at all actually) to use other tools than Visual Studio, but there are quite a few .NET developers who do prefer to stick with Visual Studio.  Which brings me to the People category.  The biggest benefit that Silverlight has over standards-based web development is that you only need to know C# and XAML.  With standards-based web development, you have to know HTML, CSS, JavaScript <em>and</em> the language of your server-side technology, in this case also C#.  This might impact your ability to find new developers so Silverlight does have sort of an advantage there. Though i'd argue that you're better off in the long term with people who are willing to <a
href="http://davybrion.com/blog/2010/09/you-need-to-step-out-of-your-comfort-zone/">step out of their comfort zone instead of clinging to what they know</a>. From a security point of view, Silverlight also scores better because you don't really have to worry about common issues such as XSS, CSRF and other vulnerabilities that are common in web-development.</p><p>So we have 3 categories where Silverlight scores better than ASP.NET MVC3/jQuery but that's far from sufficient to close the gap. Based on the weights we assigned to the criteria, the maximum possible score is 732.  ASP.NET MVC3 with jQuery scored 568.  Silverlight scored 304. Obviously, the results will vary depending on what you find important.  Which is why we asked an analyst from one of those large IT research &amp; advisory companies to give us some feedback on this. The analyst agreed entirely with our findings and our data, and  confirmed that his company is recommending moving towards HTML5 to all of their customers.  He even went as far as to say that Silverlight is hard to recommend, unless you're not targeting any mobile users <em>and</em> the applications are internal-only <em>and</em> you've already invested in the technology.  I can't provide a link for any of this yet, but a paper about this will be published soon so i'll either link to it when it's out (if it's publicly available) or at least reference it.</p><p>I encourage anyone who is faced with the same decision to use the spreadsheet and modify it to your needs (adding more criteria, changing weights and/or scores, whatever) to see which one is the best fit for your situation. You can download the spreadsheet <a
href="http://davybrion.com/html_vs_silverlight.xlsx">here</a>.</p><div
class="bottomcontainerBox" style=""><div
style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <iframe
src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fdavybrion.com%2Fblog%2F2011%2F03%2Fwhy-were-going-with-html5-instead-of-silverlight%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:85px; height:21px;"></iframe></div><div
style="float:left; width:80px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <g:plusone size="medium" href="http://davybrion.com/blog/2011/03/why-were-going-with-html5-instead-of-silverlight/"></g:plusone></div><div
style="float:left; width:95px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <a
href="http://twitter.com/share" class="twitter-share-button" data-url="http://davybrion.com/blog/2011/03/why-were-going-with-html5-instead-of-silverlight/"  data-text="Why We&#8217;re Going With HTML(5) Instead Of Silverlight" data-count="horizontal" data-via="davybrion"></a></div><div
style="float:left; width:105px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script type="in/share" data-url="http://davybrion.com/blog/2011/03/why-were-going-with-html5-instead-of-silverlight/" data-counter="right"></script></div><div
style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script src="http://www.stumbleupon.com/hostedbadge.php?s=1&amp;r=http://davybrion.com/blog/2011/03/why-were-going-with-html5-instead-of-silverlight/"></script></div></div><div
style="clear:both"></div><div
style="padding-bottom:4px;"></div>]]></content:encoded> <wfw:commentRss>http://davybrion.com/blog/2011/03/why-were-going-with-html5-instead-of-silverlight/feed/</wfw:commentRss> <slash:comments>142</slash:comments> </item> <item><title>Do You Still Believe In Silverlight?</title><link>http://davybrion.com/blog/2010/10/do-you-still-believe-in-silverlight/</link> <comments>http://davybrion.com/blog/2010/10/do-you-still-believe-in-silverlight/#comments</comments> <pubDate>Sat, 30 Oct 2010 14:30:07 +0000</pubDate> <dc:creator>Davy Brion</dc:creator> <category><![CDATA[Silverlight]]></category><guid
isPermaLink="false">http://davybrion.com/blog/?p=2859</guid> <description><![CDATA[Unless you're not really paying attention to what's going on in the Silverlight world, you probably already heard that Microsoft has confirmed a shift in strategy for Silverlight: I asked Bob Muglia, the Microsoft President in charge of the company’s server and tools business, that very question and got what I consider to be the [...]]]></description> <content:encoded><![CDATA[<p>Unless you're not really paying attention to what's going on in the Silverlight world, you probably already heard that Microsoft has <a
href="http://www.zdnet.com/blog/microsoft/microsoft-our-strategy-with-silverlight-has-shifted/7834">confirmed a shift in strategy for Silverlight</a>:</p><blockquote> I asked Bob Muglia, the Microsoft President in charge of the company’s server and tools business, that very question and got what I consider to be the clearest answer yet about how Microsoft is evolving its Silverlight strategy. “Silverlight is our development platform for Windows Phone,” he said. Silverlight also has some “sweet spots” in media and line-of-business applications, he said.</blockquote><p>It's <em>the</em> development platform for Windows Phone (more on that in a minute).  It has <em>some</em> sweet spots in media and business apps.  Things sure can change a lot in a short time.  Silverlight was at first positioned as an <em>ideal</em> technology for media.  After that, it was increasingly being marketed as a great platform to develop business applications, cross-platform ones even.  Now, despite the fact that nothing has been taken away from the platform's capabilities, it has <em>some</em> "sweet spots" in both areas where it was supposed to be a great technological choice.  Every single feature or capability that once formed Microsoft's message that it was great for business applications is still there.  And they won't take that away either.  The mere fact that their message about Silverlight has transformed so much now, is incredibly telling. If you're a Microsoft customer who's invested a lot in Silverlight for business applications, you have some pretty good reasons to be upset about this.</p><p>After all, given how the stated goals of Silverlight have evolved in the past 3 years, who's to say those "sweet spots" will remain interesting enough for Microsoft?  I have no doubt that they're going to heavily invest in making Silverlight a great development platform for Windows Phone (whether they will succeed at it is an entirely different matter though), but what you need to develop great mobile applications differs a lot from the needs you have when building great business applications.  Will the needs of developers using Silverlight to create business applications be met by Microsoft?  Let me rephrase that: keeping the manner in which they're now promoting HTML5 in mind, will they also keep putting <em>additional</em> resources into improving some niche areas of a technology who's primary purpose is to facilitate <em>mobile</em> development?  Maybe they will.  Maybe they won't. I sure as hell wouldn't bet on it.</p><p>Now, unlike a lot of people, i don't think that Silverlight is dead. Far from it even.  Silverlight has a future as long as Windows Phone has one.  Its real future lies in the mobile world now, and no longer in the browser or on the desktop.  It's going to keep working in your browsers, and its going to keep working on your desktops.  But you really need to wonder how many of the needed improvements for those 2 environments you'll see being introduced to Silverlight, and how long it'll take.  It's quite reasonable to assume that improvements in Silverlight which target the mobile development story will be receiving higher priorities than those which target the browser or desktop development model.  After all, that is what the new Silverlight strategy implies.  And given Microsoft's need to conquer a respectable position in the mobile world, and their ever increasing support of HTML5, it only makes sense for them to do so.</p><p>As for Silverlight being a suitable platform for mobile development, i can't help but wonder whether it really can live up to the high expectations that people will set on it.  Anyone who's done any serious Silverlight development knows that it is a technology which suffers from a <em>lot</em> of memory usage problems.  Partly because there are quite a few memory leaks in Silverlight's own controls, but also because the Silverlight programming model easily leads to a lot of dangling references which <em>will</em> lead to serious memory problems in a memory constrained device such as a mobile phone.  Unless they get rid of the memory problems very quickly, i can easily see Windows Phones suffering from a lot of problems as people start using more and more 3rd party applications on their phones simultaneously.  Well, it would have to support running multiple applications simultaneously before it'll be a real problem, but you know that's only a matter of time.</p><p>So, as for me personally, i don't really have a lot of belief left in Silverlight as a technology.  I don't see it advancing much more in the browser or on the desktop, and i think it's got some real, difficult challenges ahead in the mobile world.  What do you think?</p><div
class="bottomcontainerBox" style=""><div
style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <iframe
src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fdavybrion.com%2Fblog%2F2010%2F10%2Fdo-you-still-believe-in-silverlight%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:85px; height:21px;"></iframe></div><div
style="float:left; width:80px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <g:plusone size="medium" href="http://davybrion.com/blog/2010/10/do-you-still-believe-in-silverlight/"></g:plusone></div><div
style="float:left; width:95px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <a
href="http://twitter.com/share" class="twitter-share-button" data-url="http://davybrion.com/blog/2010/10/do-you-still-believe-in-silverlight/"  data-text="Do You Still Believe In Silverlight?" data-count="horizontal" data-via="davybrion"></a></div><div
style="float:left; width:105px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script type="in/share" data-url="http://davybrion.com/blog/2010/10/do-you-still-believe-in-silverlight/" data-counter="right"></script></div><div
style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script src="http://www.stumbleupon.com/hostedbadge.php?s=1&amp;r=http://davybrion.com/blog/2010/10/do-you-still-believe-in-silverlight/"></script></div></div><div
style="clear:both"></div><div
style="padding-bottom:4px;"></div>]]></content:encoded> <wfw:commentRss>http://davybrion.com/blog/2010/10/do-you-still-believe-in-silverlight/feed/</wfw:commentRss> <slash:comments>16</slash:comments> </item> <item><title>Silverlight Getting Worse When It Comes To Memory Leaks</title><link>http://davybrion.com/blog/2010/08/silverlight-getting-worse-when-it-comes-to-memory-leaks/</link> <comments>http://davybrion.com/blog/2010/08/silverlight-getting-worse-when-it-comes-to-memory-leaks/#comments</comments> <pubDate>Thu, 19 Aug 2010 08:32:12 +0000</pubDate> <dc:creator>Davy Brion</dc:creator> <category><![CDATA[Memory Management]]></category> <category><![CDATA[Silverlight]]></category><guid
isPermaLink="false">http://davybrion.com/blog/?p=2537</guid> <description><![CDATA[A coworker of mine spent some hours yesterday hunting down memory leaks in an app that he'd already gotten 'leak-free' back when it was in Silverlight 3. Turns out that the leaks are caused by changes in Silverlight 4 and not in our code. As you surely know, Microsoft releases major Silverlight versions pretty frequently [...]]]></description> <content:encoded><![CDATA[<p>A coworker of mine spent some hours yesterday hunting down memory leaks in an app that he'd already gotten 'leak-free' back when it was in Silverlight 3.  Turns out that the leaks are caused by changes in Silverlight 4 and not in our code.  As you surely know, Microsoft releases major Silverlight versions pretty frequently (there's at least one major new version each year).  That's great and all when it comes to introducing new features and capabilities, but it truly sucks if you keep introducing new problems as well.  The total amount of time (and thus, money) that we've lost hunting down leaks that are located in either the core Silverlight code or the Control Toolkit (also Microsoft code) is just starting to become embarrassingly high.</p><p>To give you an idea of what kind of leaks that keep popping up, be sure to check out these links: <a
href="http://forums.silverlight.net/forums/t/179177.aspx">http://forums.silverlight.net/forums/t/179177.aspx</a> <a
href="http://forums.silverlight.net/forums/t/179358.aspx">http://forums.silverlight.net/forums/t/179358.aspx</a> <a
href="http://forums.silverlight.net/forums/t/180702.aspx">http://forums.silverlight.net/forums/t/180702.aspx</a> <a
href="http://forums.silverlight.net/forums/t/181257.aspx">http://forums.silverlight.net/forums/t/181257.aspx</a> <a
href="http://forums.silverlight.net/forums/t/171739.aspx ">http://forums.silverlight.net/forums/t/171739.aspx </a></p><p>If anyone from Microsoft reads this: please, pretty please, pretty please with sugar on top: can we get a little bit more QA from you guys? If you can put out products like WebMatrix and LightSwitch, than surely you must have enough resources available to make sure that your <em>real</em> development platforms do not become a cost-sink for your customers due to your own lack of quality control, no?</p><p>Update: it's also quite telling that the search phrase "silverlight memory leak" is the number one search phrase through which people get to this site.  #justsaying</p><div
class="bottomcontainerBox" style=""><div
style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <iframe
src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fdavybrion.com%2Fblog%2F2010%2F08%2Fsilverlight-getting-worse-when-it-comes-to-memory-leaks%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:85px; height:21px;"></iframe></div><div
style="float:left; width:80px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <g:plusone size="medium" href="http://davybrion.com/blog/2010/08/silverlight-getting-worse-when-it-comes-to-memory-leaks/"></g:plusone></div><div
style="float:left; width:95px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <a
href="http://twitter.com/share" class="twitter-share-button" data-url="http://davybrion.com/blog/2010/08/silverlight-getting-worse-when-it-comes-to-memory-leaks/"  data-text="Silverlight Getting Worse When It Comes To Memory Leaks" data-count="horizontal" data-via="davybrion"></a></div><div
style="float:left; width:105px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script type="in/share" data-url="http://davybrion.com/blog/2010/08/silverlight-getting-worse-when-it-comes-to-memory-leaks/" data-counter="right"></script></div><div
style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script src="http://www.stumbleupon.com/hostedbadge.php?s=1&amp;r=http://davybrion.com/blog/2010/08/silverlight-getting-worse-when-it-comes-to-memory-leaks/"></script></div></div><div
style="clear:both"></div><div
style="padding-bottom:4px;"></div>]]></content:encoded> <wfw:commentRss>http://davybrion.com/blog/2010/08/silverlight-getting-worse-when-it-comes-to-memory-leaks/feed/</wfw:commentRss> <slash:comments>15</slash:comments> </item> <item><title>The MVVM Pattern Is Highly Overrated</title><link>http://davybrion.com/blog/2010/07/the-mvvm-pattern-is-highly-overrated/</link> <comments>http://davybrion.com/blog/2010/07/the-mvvm-pattern-is-highly-overrated/#comments</comments> <pubDate>Wed, 21 Jul 2010 14:23:58 +0000</pubDate> <dc:creator>Davy Brion</dc:creator> <category><![CDATA[Architecture]]></category> <category><![CDATA[Code Quality]]></category> <category><![CDATA[Silverlight]]></category><guid
isPermaLink="false">http://davybrion.com/blog/?p=2392</guid> <description><![CDATA[Update: check out my MVP In Silverlight/WPF series which discusses the MVP approach as an alternative to MVVM If you're doing Silverlight or WPF, you've no doubt come across the MVVM (Model-View-ViewModel) pattern. It seems to be the most popular client-side architecture pattern used among Silverlight/WPF developers. I find the pattern to be highly overrated, [...]]]></description> <content:encoded><![CDATA[<p>Update: check out my <a
href="http://davybrion.com/blog/2010/08/mvp-in-silverlightwpf-series/">MVP In Silverlight/WPF series</a> which discusses the MVP approach as an alternative to MVVM</p><p>If you're doing Silverlight or WPF, you've no doubt come across the MVVM (Model-View-ViewModel) pattern.  It seems to be the most popular client-side architecture pattern used among Silverlight/WPF developers.  I find the pattern to be highly overrated, and actually have some big issues with the whole thing.</p><p>First, let's briefly cover what MVVM is about for those of you who don't know yet.  MVVM virtually eliminates all of the code that would typically be placed in the code-behind file of your View (a user control, a screen, whatever) by putting all of that logic in the ViewModel.  The ViewModel itself is never tightly coupled to the View. If it does have a reference to it, it's typically through an interface that the View implements instead of a reference of the actual type of the View.  This increases, or better yet, introduces testability to a large part of your UI code that you normally wouldn't be able to cover with unit tests if you'd go with the traditional "put it all in the code-behind"-approach.</p><p>The ViewModel typically contains properties for the data that is to be shown in the View, and also raises notification events when the data in those properties changes.  The View uses the powerful data-binding capabilities of Silverlight/WPF to bind the properties of the ViewModel to other user controls that the View is composed of.  User-events that are captured by the View are sent to the ViewModel through Commands.  Typically, these commands execute a method in the ViewModel which contains some kind of logic... usually to either send the updated data in the ViewModel's properties to the Model (usually a Service Layer in Silverlight, in WPF it could be either a true Domain Model or also a Service Layer), to perform some business logic in the Model, or to retrieve data from the Model so it can be placed in the ViewModel's properties so the View can bind to it.</p><p>That is, in a nutshell, how the MVVM pattern works.  So why do i have issues with this? You can develop and test most of the application's logic without being dependent on a physical View and that is typically a Good Thing, no? It sure is!  However, my problem with this approach is that  too many responsibilities are concentrated within the ViewModel.  Its main responsibilities are to facilitate databinding <em>and</em> to interact with the Model.  And that, in my opinion, isn't very clean.  In some ways, you could actually think of the ViewModel as a glorified code-behind, with the only difference being that it's not tightly coupled to the (physical) View.</p><p>In most (if not all) MVVM implementations, a ViewModel has many possible reasons to be changed.  It might need to be changed because of different data-binding requirements.  Then again, it might also require changes when a part of the Model is modified.  Now, i'm sure many of you can agree with me when i say that two of the most important principles in software development are <a
href="http://en.wikipedia.org/wiki/Separation_of_concerns">Seperation of Concerns (SoC)</a> and the <a
href="http://en.wikipedia.org/wiki/Single_responsibility_principle">Single Responsibility Principle (SRP)</a>.  Obviously, the ViewModel doesn't fare well when it comes to both of these principles.</p><p>Lets forget about MVVM for a second and focus on the concerns and responsibilities that a user control can have... say, a user control that shows customer information and allows the user to edit that data so it can be persisted:</p><ul><li>visualization of the actual control (its own layout as well drawing other user controls that it is composed of)</li><li>communication/interaction with the Model</li><li>making data (from the Model) available so it can be displayed</li><li>outputting data in the correct user controls (for instance: various textboxes)</li><li>(simple validation) of modified/inputted data (for instance: no string values for numeric fields, etc...)</li></ul><p>Without MVVM, all of these would be taken care of in the View.  Obviously, not a good idea right?  After all, if it were a good idea, we'd never have had a reason to start using MVVM in the first place.</p><p>Now, with MVVM, a lot of people would divide these concerns and responsibilities like this:</p><p>View:</p><ul><li>visualization of the actual control (its own layout as well drawing other user controls that it is composed of)</li><li>outputting data in the correct user controls (for instance: various textboxes)</li><li>(simple validation) of modified/inputted data (for instance: no string values for numeric fields, etc...)</li></ul><p>ViewModel:</p><ul><li>communication/interaction with the Model</li><li>making data (from the Model) available so it can be displayed</li></ul><p>In this case, the View still has 3 responsibilities which is still too much according to 'the guidelines', but it's not that big of a deal (though plenty of people would argue that the simple validation would be better placed in the ViewModel).  You're highly unlikely to actually want to write automated tests for pure visualization anyway and the SRP is not something that you absolutely need to follow to the extreme in every single place.  For the View, this is really not a problem and very much acceptable.</p><p>The ViewModel however has 2 important responsibilities in this case, and i'd argue that these 2 things should not be done in the same place.  Making data available is done through data-binding.  To do this, you need a set of properties and you need to raise the necessary events.  In most cases, raising those events is very straightforward, but in more complex controls you might need a bit of additional logic to determine which event should be raised at what point.  The other important responsibility is the communication/interaction with the Model.  In most Silverlight applications, the Model will be a Service Layer.  To communicate with this Service Layer, you need Service Proxies.  That means that your ViewModel is essentially responsible for communicating with the Service Layer, dealing with business exceptions that might be thrown by some service calls, and dealing with technical exceptions that can occur simply because of network-related problems.  Group all of those together and i don't think i'm going out on a limb here by saying that that is a lot of logic to put in <em>one</em> class, no?</p><p>(Sidenote: what i don't really understand is that many people who vigorously advocate adherence to SRP and SoC in their domain and business code don't seem to hold their UI code to the same standards. I do.)</p><p>At work, we do <em>a lot</em> of Silverlight development.  We typically have around 5 Silverlight projects in active development at the same time.  And it's been that way for over a year now.  That equals a lot of Silverlight code that we've written and experience and knowledge that we've built up.  And we haven't used MVVM for any of it.  All this time, we've been using the MVP pattern (Supervising Controller variant) with a slight twist.  That twist being a slimmed down version of a <a
href="http://www.martinfowler.com/eaaDev/PresentationModel.html">Presentation Model</a>.  Our Presentation Model's sole responsibility is to facilitate data-binding, and in some cases, a touch of validation is added as well.</p><p>If we go back to our previous example of the customer screen, the responsibilities and concerns would be divided like this in our MVP-PMlight approach:</p><p>View:</p><ul><li>visualization of the actual control (its own layout as well drawing other user controls that it is composed of)</li><li>outputting data in the correct user controls (for instance: various textboxes)</li><li>(simple validation) of modified/inputted data (for instance: no string values for numeric fields, etc...)</li></ul><p>Presenter:</p><ul><li>communication/interaction with the Model based on the contents of the Presentation Model</li></ul><p>Presentation Model:</p><ul><li>making data (from the Model) available so it can be displayed</li></ul><p>Which leads to classes which are more focused on their task instead of trying to focus on too many things at the same time.  In my opinion, this approach is much better/cleaner than MVVM.  Not only is there a noticeable benefit in code quality (classes are more focused), there is also increased potential to reuse our 'light Presentation Models' in multiple controls.  Testability is increased over MVVM as well since it's always easier to test classes which are focused versus testing classes which have too many responsibilities.  All in all, a couple of important benefits and we still haven't thought of a real drawback compared to MVVM.</p><div
class="bottomcontainerBox" style=""><div
style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <iframe
src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fdavybrion.com%2Fblog%2F2010%2F07%2Fthe-mvvm-pattern-is-highly-overrated%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:85px; height:21px;"></iframe></div><div
style="float:left; width:80px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <g:plusone size="medium" href="http://davybrion.com/blog/2010/07/the-mvvm-pattern-is-highly-overrated/"></g:plusone></div><div
style="float:left; width:95px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <a
href="http://twitter.com/share" class="twitter-share-button" data-url="http://davybrion.com/blog/2010/07/the-mvvm-pattern-is-highly-overrated/"  data-text="The MVVM Pattern Is Highly Overrated" data-count="horizontal" data-via="davybrion"></a></div><div
style="float:left; width:105px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script type="in/share" data-url="http://davybrion.com/blog/2010/07/the-mvvm-pattern-is-highly-overrated/" data-counter="right"></script></div><div
style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script src="http://www.stumbleupon.com/hostedbadge.php?s=1&amp;r=http://davybrion.com/blog/2010/07/the-mvvm-pattern-is-highly-overrated/"></script></div></div><div
style="clear:both"></div><div
style="padding-bottom:4px;"></div>]]></content:encoded> <wfw:commentRss>http://davybrion.com/blog/2010/07/the-mvvm-pattern-is-highly-overrated/feed/</wfw:commentRss> <slash:comments>102</slash:comments> </item> <item><title>Introducing AgUnit: Silverlight Unit Testing With Resharper</title><link>http://davybrion.com/blog/2010/05/introducing-agunit-silverlight-unit-testing-with-resharper/</link> <comments>http://davybrion.com/blog/2010/05/introducing-agunit-silverlight-unit-testing-with-resharper/#comments</comments> <pubDate>Mon, 31 May 2010 07:29:30 +0000</pubDate> <dc:creator>Davy Brion</dc:creator> <category><![CDATA[resharper]]></category> <category><![CDATA[Silverlight]]></category> <category><![CDATA[testing]]></category><guid
isPermaLink="false">http://davybrion.com/blog/2010/05/introducing-agunit-silverlight-unit-testing-with-resharper/</guid> <description><![CDATA[A couple of months ago, i showed a sneak preview of a Silverlight unit testing Resharper plugin that one of my coworkers was working on.&#160; I’m glad to say it’s finally been released and you can get it here Those are Silverlight tests, executed through Resharper within the Silverlight runtime]]></description> <content:encoded><![CDATA[<p>A couple of months ago, i showed a <a
href="http://davybrion.com/blog/2009/12/unit-tests-and-silverlight/" target="_blank">sneak preview</a> of a Silverlight unit testing Resharper plugin that one of my coworkers was working on.&#160; I’m glad to say it’s finally been released and you can get it <a
href="http://agunit.codeplex.com/" target="_blank">here</a> <img
src='http://d18sni7re4ly7f.cloudfront.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p><p><a
href="http://davybrion.com/pictures/IntroducingAgUnitSilverlightUnitTestingW_8615/agunit.png" rel="prettyPhoto[2327]"><img
style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="agunit" border="0" alt="agunit" src="http://davybrion.com/pictures/IntroducingAgUnitSilverlightUnitTestingW_8615/agunit_thumb.png" width="644" height="226" /></a></p><p>Those are Silverlight tests, executed through Resharper within the Silverlight runtime <img
src='http://d18sni7re4ly7f.cloudfront.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p><div
class="bottomcontainerBox" style=""><div
style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <iframe
src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fdavybrion.com%2Fblog%2F2010%2F05%2Fintroducing-agunit-silverlight-unit-testing-with-resharper%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:85px; height:21px;"></iframe></div><div
style="float:left; width:80px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <g:plusone size="medium" href="http://davybrion.com/blog/2010/05/introducing-agunit-silverlight-unit-testing-with-resharper/"></g:plusone></div><div
style="float:left; width:95px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <a
href="http://twitter.com/share" class="twitter-share-button" data-url="http://davybrion.com/blog/2010/05/introducing-agunit-silverlight-unit-testing-with-resharper/"  data-text="Introducing AgUnit: Silverlight Unit Testing With Resharper" data-count="horizontal" data-via="davybrion"></a></div><div
style="float:left; width:105px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script type="in/share" data-url="http://davybrion.com/blog/2010/05/introducing-agunit-silverlight-unit-testing-with-resharper/" data-counter="right"></script></div><div
style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script src="http://www.stumbleupon.com/hostedbadge.php?s=1&amp;r=http://davybrion.com/blog/2010/05/introducing-agunit-silverlight-unit-testing-with-resharper/"></script></div></div><div
style="clear:both"></div><div
style="padding-bottom:4px;"></div>]]></content:encoded> <wfw:commentRss>http://davybrion.com/blog/2010/05/introducing-agunit-silverlight-unit-testing-with-resharper/feed/</wfw:commentRss> <slash:comments>2</slash:comments> </item> <item><title>Unit Tests And Silverlight</title><link>http://davybrion.com/blog/2009/12/unit-tests-and-silverlight/</link> <comments>http://davybrion.com/blog/2009/12/unit-tests-and-silverlight/#comments</comments> <pubDate>Wed, 16 Dec 2009 13:03:31 +0000</pubDate> <dc:creator>Davy Brion</dc:creator> <category><![CDATA[Silverlight]]></category> <category><![CDATA[testing]]></category><guid
isPermaLink="false">http://davybrion.com/blog/2009/12/unit-tests-and-silverlight/</guid> <description><![CDATA[This is something that Steven De Kock and Tom Ceulemans (two coworkers of mine without a blog, so no link) have been working on.&#160; Those are Silverlight tests, executing in the Silverlight runtime, within a full browser context. And yes, they will release it as an open source project soon]]></description> <content:encoded><![CDATA[<p><a
href="http://davybrion.com/blog/wp-content/uploads/2009/12/Capture.png" rel="prettyPhoto[2074]"><img
style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Capture" border="0" alt="Capture" src="http://davybrion.com/blog/wp-content/uploads/2009/12/Capture_thumb.png" width="644" height="255" /></a></p><p>This is something that Steven De Kock and Tom Ceulemans (two coworkers of mine without a blog, so no link) have been working on.&#160; Those are Silverlight tests, executing in the Silverlight runtime, within a full browser context.</p><p>And yes, they will release it as an open source project soon <img
src='http://d18sni7re4ly7f.cloudfront.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p><div
class="bottomcontainerBox" style=""><div
style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <iframe
src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fdavybrion.com%2Fblog%2F2009%2F12%2Funit-tests-and-silverlight%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:85px; height:21px;"></iframe></div><div
style="float:left; width:80px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <g:plusone size="medium" href="http://davybrion.com/blog/2009/12/unit-tests-and-silverlight/"></g:plusone></div><div
style="float:left; width:95px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <a
href="http://twitter.com/share" class="twitter-share-button" data-url="http://davybrion.com/blog/2009/12/unit-tests-and-silverlight/"  data-text="Unit Tests And Silverlight" data-count="horizontal" data-via="davybrion"></a></div><div
style="float:left; width:105px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script type="in/share" data-url="http://davybrion.com/blog/2009/12/unit-tests-and-silverlight/" data-counter="right"></script></div><div
style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script src="http://www.stumbleupon.com/hostedbadge.php?s=1&amp;r=http://davybrion.com/blog/2009/12/unit-tests-and-silverlight/"></script></div></div><div
style="clear:both"></div><div
style="padding-bottom:4px;"></div>]]></content:encoded> <wfw:commentRss>http://davybrion.com/blog/2009/12/unit-tests-and-silverlight/feed/</wfw:commentRss> <slash:comments>9</slash:comments> </item> <item><title>Integrated Security With Silverlight And WCF</title><link>http://davybrion.com/blog/2009/11/integrated-security-with-silverlight-and-wcf/</link> <comments>http://davybrion.com/blog/2009/11/integrated-security-with-silverlight-and-wcf/#comments</comments> <pubDate>Tue, 03 Nov 2009 11:41:32 +0000</pubDate> <dc:creator>Davy Brion</dc:creator> <category><![CDATA[Silverlight]]></category> <category><![CDATA[WCF]]></category><guid
isPermaLink="false">http://davybrion.com/blog/?p=1856</guid> <description><![CDATA[I lost some time yesterday trying to get a Silverlight client to use Integrated Security with a WCF service so i figured i'd post the steps necessary to make it work here. First of all, you need to make sure that your IIS installation has support for Windows Authentication. Go to Add/Remove Programs (appwiz.cpl), click [...]]]></description> <content:encoded><![CDATA[<p>I lost some time yesterday trying to get a Silverlight client to use Integrated Security with a WCF service so i figured i'd post the steps necessary to make it work here.</p><p>First of all, you need to make sure that your IIS installation has support for Windows Authentication.  Go to Add/Remove Programs (appwiz.cpl), click on Turn Windows Features on or off, select Internet Information Services - World Wide Web Services - Security and make sure that Windows Authentication is checked.</p><p>Next, you need to make sure that the virtual directory where you're hosting the WCF service has Windows Authentication enabled.  Open Internet Information Services Manager (inetmgr), select the virtual directory where the WCF service is hosted, click on the Authentication icon and enable Windows Authentication.</p><p>After that, you need to add the following to the binding configuration of the service endpoint (in the host, obviously):</p><div><pre class="brush: xml; title: ; notranslate">
          &lt;security mode=&quot;TransportCredentialOnly&quot;&gt;
            &lt;transport clientCredentialType=&quot;Windows&quot; /&gt;
          &lt;/security&gt;
</pre></div><p>I only got it working with basicHttpBinding, so unfortunately i can no longer use the customBinding to use binary XML...</p><p>In your Silverlight project, open the ServiceReferences.ClientConfig file and add the following to the binding configuration:</p><div><pre class="brush: xml; title: ; notranslate">
          &lt;security mode=&quot;TransportCredentialOnly&quot; /&gt;
</pre></div><p>After that, you should be able to do this in your WCF service:</p><div><pre class="brush: csharp; title: ; notranslate">
            WindowsIdentity myuser = ServiceSecurityContext.Current.WindowsIdentity;
</pre></div><p>And that should return the Windows user of the user running the Silverlight client.</p><p>For the record: this is with Silverlight 3... i have no idea if it'll work with Silverlight 2</p><div
class="bottomcontainerBox" style=""><div
style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <iframe
src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fdavybrion.com%2Fblog%2F2009%2F11%2Fintegrated-security-with-silverlight-and-wcf%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:85px; height:21px;"></iframe></div><div
style="float:left; width:80px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <g:plusone size="medium" href="http://davybrion.com/blog/2009/11/integrated-security-with-silverlight-and-wcf/"></g:plusone></div><div
style="float:left; width:95px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <a
href="http://twitter.com/share" class="twitter-share-button" data-url="http://davybrion.com/blog/2009/11/integrated-security-with-silverlight-and-wcf/"  data-text="Integrated Security With Silverlight And WCF" data-count="horizontal" data-via="davybrion"></a></div><div
style="float:left; width:105px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script type="in/share" data-url="http://davybrion.com/blog/2009/11/integrated-security-with-silverlight-and-wcf/" data-counter="right"></script></div><div
style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script src="http://www.stumbleupon.com/hostedbadge.php?s=1&amp;r=http://davybrion.com/blog/2009/11/integrated-security-with-silverlight-and-wcf/"></script></div></div><div
style="clear:both"></div><div
style="padding-bottom:4px;"></div>]]></content:encoded> <wfw:commentRss>http://davybrion.com/blog/2009/11/integrated-security-with-silverlight-and-wcf/feed/</wfw:commentRss> <slash:comments>1</slash:comments> </item> <item><title>Event Aggregation</title><link>http://davybrion.com/blog/2009/10/event-aggregation/</link> <comments>http://davybrion.com/blog/2009/10/event-aggregation/#comments</comments> <pubDate>Fri, 09 Oct 2009 14:12:52 +0000</pubDate> <dc:creator>Davy Brion</dc:creator> <category><![CDATA[Patterns]]></category> <category><![CDATA[Silverlight]]></category><guid
isPermaLink="false">http://davybrion.com/blog/?p=1708</guid> <description><![CDATA[We're experimenting at work with a bit of a different approach as to how we structure our views and how they will interact with each other. We already know that our views will be reused in many different contexts so having them communicate with other views is something that needs to be done in a [...]]]></description> <content:encoded><![CDATA[<p>We're experimenting at work with a bit of a different approach as to how we structure our views and how they will interact with each other.  We already know that our views will be reused in many different contexts so having them communicate with other views is something that needs to be done in a very loosely coupled manner.  I don't want any of the views to even know about the existence of other views, let alone having them know about specific instances of them.</p><p>But these views do have to interact with each other.  I didn't want to use typical events because that would require either a certain view to know about another view to be able to subscribe to its events, or you'd need some other component which knows which views need to be hooked to each other.  We really need maximum flexibility for what we have in mind with our views, so it only made sense to finally start using the <a
href="http://martinfowler.com/eaaDev/EventAggregator.html">Event Aggregation pattern</a>.  The idea is that a view can basically publish events, without knowing who is subscribed to these events, and that suscribers will be notified whenever these events occur.  However, subscribers don't know anything about who is publishing the events.  Instead, both publishers and subscribers only know of the Event Aggregator.  A publisher tells the aggregator to publish an event to all subscribed listeners for that event.  Each subscribers simply tells the aggregator "i'd like to be notified whenever this event occurs, and i don't care where it comes from".<br
/> Plenty of implementations of this pattern can be found online already, so i figured: why not add my own? :p</p><p>Fist of all, an event is nothing more than a class that inherits from this class:</p><div><pre class="brush: csharp; title: ; notranslate">
    public abstract class Event {}
</pre></div><p>Every event should inherit from this class, and add whatever necessary properties that are important for that particular type of event.</p><p>If a class is interested in listening to a specific event, it needs to implement the following interface:</p><div><pre class="brush: csharp; title: ; notranslate">
    public interface IListener { }
 
    public interface IListener&lt;TEvent&gt; : IListener
        where TEvent : Event
    {
        void Handle(TEvent receivedEvent);
    }
</pre></div><p>If a class is interested in multiple events, it simply needs to implement the generic IListener interface for each type of event that it wants to handle.</p><p>Then we obviously need the Event Aggregator.  I wanted an aggregator that allowed listeners to either subscribe/unsubscribe to/from very specific events, or just subscribe/unsubscribe to/from whatever it supports.  So i have the following IEventAggregator interface:</p><div><pre class="brush: csharp; title: ; notranslate">
    public interface IEventAggregator
    {
        void Publish&lt;TEvent&gt;(TEvent message) where TEvent : Event;
        void Publish&lt;TEvent&gt;() where TEvent : Event, new();
 
        void Subscribe(IListener listener);
        void Unsubscribe(IListener listener);
 
        void Subscribe&lt;TEvent&gt;(IListener&lt;TEvent&gt; listener) where TEvent : Event;
        void Unsubscribe&lt;TEvent&gt;(IListener&lt;TEvent&gt; listener) where TEvent : Event;
    }
</pre></div><p>The Subscribe and Unsubscribe methods that simply take an IListener reference will either subscribe or unsubscribe the given listener to/from every event that it can handle.  In other words, for every generic IListener interface that it implements.  Yet you also have the ability to subscribe/unsubscribe from a specific event type.</p><p>And here's the implementation:</p><div><pre class="brush: csharp; title: ; notranslate">
    public class EventAggregator : IEventAggregator
    {
        private readonly object listenerLock = new object();
        protected readonly Dictionary&lt;Type, List&lt;IListener&gt;&gt; listeners = new Dictionary&lt;Type, List&lt;IListener&gt;&gt;();
        private readonly IDispatcher dispatcher;
 
        public EventAggregator(IDispatcher dispatcher)
        {
            this.dispatcher = dispatcher;
        }
 
        public virtual void Subscribe(IListener listener)
        {
            ForEachListenerInterfaceImplementedBy(listener, Subscribe);
        }
 
        public virtual void Unsubscribe(IListener listener)
        {
            ForEachListenerInterfaceImplementedBy(listener, Unsubscribe);
        }
 
        private static void ForEachListenerInterfaceImplementedBy(IListener listener, Action&lt;Type, IListener&gt; action)
        {
            var listenerTypeName = typeof(IListener).Name;
 
            foreach (var interfaceType in listener.GetType().GetInterfaces().Where(i =&gt; i.Name.StartsWith(listenerTypeName)))
            {
                Type typeOfEvent = GetEventType(interfaceType);
 
                if (typeOfEvent != null)
                {
                    action(typeOfEvent, listener);
                }
            }
        }
 
        private static Type GetEventType(Type type)
        {
            if (type.GetGenericArguments().Count() &gt; 0)
            {
                return type.GetGenericArguments()[0];
            }
 
            return null;
        }
 
        public virtual void Subscribe&lt;TEvent&gt;(IListener&lt;TEvent&gt; listener) where TEvent : Event
        {
            Subscribe(typeof(TEvent), listener);
        }
 
        protected virtual void Subscribe(Type typeOfEvent, IListener listener)
        {
            lock (listenerLock)
            {
                if (!listeners.ContainsKey(typeOfEvent))
                {
                    listeners.Add(typeOfEvent, new List&lt;IListener&gt;());
                }
 
                if (listeners[typeOfEvent].Contains(listener))
                {
                    throw new InvalidOperationException(&quot;You're not supposed to register to the same event twice&quot;);
                }
 
                listeners[typeOfEvent].Add(listener);
            }
        }
 
        public virtual void Unsubscribe&lt;TEvent&gt;(IListener&lt;TEvent&gt; listener) where TEvent : Event
        {
            Unsubscribe(typeof(TEvent), listener);
        }
 
        protected virtual void Unsubscribe(Type typeOfEvent, IListener listener)
        {
            lock(listenerLock)
            {
                if (listeners.ContainsKey(typeOfEvent))
                {
                    listeners[typeOfEvent].Remove(listener);
                }
            }
        }
 
        public virtual void Publish&lt;TEvent&gt;(TEvent message) where TEvent : Event
        {
            var typeOfEvent = typeof(TEvent);
 
            lock (listenerLock)
            {
                if (!listeners.ContainsKey(typeOfEvent)) return;
 
                foreach (var listener in listeners[typeOfEvent])
                {
                    var typedReference = (IListener&lt;TEvent&gt;)listener;
                    dispatcher.BeginInvoke(() =&gt; typedReference.Handle(message));
                }
            }
        }
 
        public virtual void Publish&lt;TEvent&gt;() where TEvent : Event, new()
        {
            Publish(new TEvent());
        }
    }
</pre></div><p>In case you're wondering... the IDispatcher interface is merely a way to wrap Silverlight's real Dispatcher.  We wrap it so we can use a different implementation of the IDispatcher in our automated tests.  Other than that, the implementation is very straightforward.</p><p>We started using this very recently, so this implementation might change in the upcoming weeks, but for now it does what it needs to do and it does so pretty well.  In our case, every view's Presenter automatically has an IEventAggregator property so whenever we need to publish an event, we can simply do something like EventAggregator.Publish(new SomeEvent(someParameter)).  Or, Presenters that need to listen to events can simply say EventAggregator.Subscribe(this) or only subscribe to some specific events whenever they need to and their specific Handle method will be called whenever someone publishes the event.  This also allowed us to get rid of the somewhat awkward syntax when testing events (subscription, unsubscription and the actual handing of events) with mocking frameworks.</p><p>And as a last bonus, i put a call to the Unsubscribe(IListener) method in the Dispose method of our base Presenter implementation.  Which means that none of them will be left subscribed to events by accident anymore <img
src='http://d18sni7re4ly7f.cloudfront.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p><div
class="bottomcontainerBox" style=""><div
style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <iframe
src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fdavybrion.com%2Fblog%2F2009%2F10%2Fevent-aggregation%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:85px; height:21px;"></iframe></div><div
style="float:left; width:80px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <g:plusone size="medium" href="http://davybrion.com/blog/2009/10/event-aggregation/"></g:plusone></div><div
style="float:left; width:95px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <a
href="http://twitter.com/share" class="twitter-share-button" data-url="http://davybrion.com/blog/2009/10/event-aggregation/"  data-text="Event Aggregation" data-count="horizontal" data-via="davybrion"></a></div><div
style="float:left; width:105px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script type="in/share" data-url="http://davybrion.com/blog/2009/10/event-aggregation/" data-counter="right"></script></div><div
style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script src="http://www.stumbleupon.com/hostedbadge.php?s=1&amp;r=http://davybrion.com/blog/2009/10/event-aggregation/"></script></div></div><div
style="clear:both"></div><div
style="padding-bottom:4px;"></div>]]></content:encoded> <wfw:commentRss>http://davybrion.com/blog/2009/10/event-aggregation/feed/</wfw:commentRss> <slash:comments>7</slash:comments> </item> <item><title>5 Reasons Why Silverlight Is My Preferred Web Development Platform</title><link>http://davybrion.com/blog/2009/09/5-reasons-why-silverlight-is-my-preferred-web-development-platform/</link> <comments>http://davybrion.com/blog/2009/09/5-reasons-why-silverlight-is-my-preferred-web-development-platform/#comments</comments> <pubDate>Sat, 05 Sep 2009 12:57:50 +0000</pubDate> <dc:creator>Davy Brion</dc:creator> <category><![CDATA[Opinions]]></category> <category><![CDATA[Silverlight]]></category><guid
isPermaLink="false">http://davybrion.com/blog/?p=1616</guid> <description><![CDATA[NOTE: if you landed on this post while doing research as to whether or not Silverlight is a technology worth learning or using, please read the following posts as well, which i wrote about a year after writing the one below: Keep Your Eyes On The Road and Learn To Work With The Web Instead [...]]]></description> <content:encoded><![CDATA[<p><strong>NOTE: if you landed on this post while doing research as to whether or not Silverlight is a technology worth learning or using, please read the following posts as well, which i wrote about a year after writing the one below: <a
href="http://davybrion.com/blog/2010/09/keep-your-eyes-on-the-road/">Keep Your Eyes On The Road</a> and <a
href="http://davybrion.com/blog/2011/01/learn-to-work-with-the-web-instead-of-against-it/">Learn To Work With The Web Instead Of Against It</a>. Simply put, Silverlight is no longer my preferred web development platform for a variety of reasons i mention in those two posts.</strong></p><p>The company where i work has been using Silverlight ever since the first version came out, and by now we have quite a bit of experience and dare i say expertise in it.  We generally suggest using Silverlight for every new project that we do, and the only time we don't use it is when customers don't want us to use it.  This happens very rarely though.</p><p>While i generally don't get involved in most of the UI stuff, i'm pretty happy with this because i seriously like Silverlight as a platform.  Below is my list of top 5 reasons why Silverlight is my preferred platform for Web Development nowadays:</p><ol><li><p><strong>The ability to create an excellent UIX which definitely matters to customers.</strong></p><p> We have some projects at work where the Silverlight UI definitely receives a "wow" response from customers.  Not only because the UI is extremely responsive and snappy, but also because we can use new ways of visualizing data and enabling user actions in the UI in ways that are either completely new for web applications, or just new in general.  We can easily create much more intuitive user interfaces with a responsiveness that can easily compete with that of desktop applications.</p></li><li><p><strong>Low bandwidth overhead</strong></p><p> Downloading the XAP file can sometimes be painfully slow, depending on your bandwidth obviously, but once it's downloaded it's also cached by the user's browser.  Everything that happens after that consumes very little bandwidth.  There is no CSS, no HTML markup, no javascript, ... the only thing that goes over the wire is the data that you actually need.  And with Silverlight's Binary XML feature you're also using less bandwidth than before.  This might not seem like a big deal to you, but bandwidth has a huge impact on the client-side responsiveness as well as your server-side ability to process requests.</p></li><li><p><strong>The client is stateful again</strong></p><p> This one is huge to me.  We don't have to deal with things like ViewState or SessionState or anything like that.  If a client has retrieved a set of data, it can just keep it in memory if it makes sense to do so.  This is especially useful for things like user-profiles, or static data that never changes but it has an impact on pretty much everything you develop.  You can simply keep whatever data you need in memory, and it has no impact on the server at all.  Well, it actually reduces the amount of data that you need to send to the server (or receive), and the number of requests you need the server to handle to implement the functionality you need client-side.  This is pretty much a win-win for both the client and the server whereas with typical ASP.NET development, either the client or the server has to take some kind of a hit when it comes to maintaining state (even if it's only a little).</p></li><li><p><strong>The ability to write the client almost entirely in C#</strong></p><p> I don't know about you, but my HTML, CSS and Javascript skills are extremely limited.  This seriously reduces my effectiveness when i need to make changes in the presentation layer in typical ASP.NET applications.  And while my XAML skills aren't what they should be, my C# skills are sufficient for me to be effective in client-side changes.  I can easily look at a piece of client-side code and make whatever change i need to make without having to consult a reference guide.  That's not the biggest advantage to being able to write the client in C# though.  Existing C# skills are very easily transferable to the Silverlight side of things, which means that a larger pool of developers is available to work on your front-end.  True, there is a bit of a learning curve when it comes to Silverlight, but i'd argue that there is a much steeper learning curve to doing traditional client-side web development <strong>effectively</strong>.</p></li><li><p><strong>It's only going to get better</strong></p><p> As much as i like Silverlight, it is by no means perfect and there is plenty of room for improvement.  That's normal though for such a young platform.  In the future we'll see plenty of new libraries and tools that will become available to Silverlight developers which should enable us to create even better web applications.  Microsoft is investing a lot of money and effort into it, and i'm pretty sure that others will follow.</p></li></ol><p>Now, you won't hear me say that Silverlight is the perfect solution for every web application.  SEO is still a problem, as well as acceptance of the Silverlight plugin in corporate environments (though this will only improve over time).  But, in the situations where you can use Silverlight, it certainly pays off to do so.</p><div
class="bottomcontainerBox" style=""><div
style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <iframe
src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fdavybrion.com%2Fblog%2F2009%2F09%2F5-reasons-why-silverlight-is-my-preferred-web-development-platform%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:85px; height:21px;"></iframe></div><div
style="float:left; width:80px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <g:plusone size="medium" href="http://davybrion.com/blog/2009/09/5-reasons-why-silverlight-is-my-preferred-web-development-platform/"></g:plusone></div><div
style="float:left; width:95px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <a
href="http://twitter.com/share" class="twitter-share-button" data-url="http://davybrion.com/blog/2009/09/5-reasons-why-silverlight-is-my-preferred-web-development-platform/"  data-text="5 Reasons Why Silverlight Is My Preferred Web Development Platform" data-count="horizontal" data-via="davybrion"></a></div><div
style="float:left; width:105px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script type="in/share" data-url="http://davybrion.com/blog/2009/09/5-reasons-why-silverlight-is-my-preferred-web-development-platform/" data-counter="right"></script></div><div
style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script src="http://www.stumbleupon.com/hostedbadge.php?s=1&amp;r=http://davybrion.com/blog/2009/09/5-reasons-why-silverlight-is-my-preferred-web-development-platform/"></script></div></div><div
style="clear:both"></div><div
style="padding-bottom:4px;"></div>]]></content:encoded> <wfw:commentRss>http://davybrion.com/blog/2009/09/5-reasons-why-silverlight-is-my-preferred-web-development-platform/feed/</wfw:commentRss> <slash:comments>18</slash:comments> </item> <item><title>Finding Memory Leaks In Silverlight With WinDbg</title><link>http://davybrion.com/blog/2009/08/finding-memory-leaks-in-silverlight-with-windbg/</link> <comments>http://davybrion.com/blog/2009/08/finding-memory-leaks-in-silverlight-with-windbg/#comments</comments> <pubDate>Sat, 08 Aug 2009 17:00:15 +0000</pubDate> <dc:creator>Davy Brion</dc:creator> <category><![CDATA[Memory Management]]></category> <category><![CDATA[Silverlight]]></category><guid
isPermaLink="false">http://davybrion.com/blog/?p=1496</guid> <description><![CDATA[As i mentioned in a previous post, you can attach WinDbg to a browser to find memory leaks in your Silverlight applications. I figured it would be a good idea to write down how this process works, since i always end up having to look it up again whenever i need to do this. I [...]]]></description> <content:encoded><![CDATA[<p>As i mentioned in a <a
href="http://davybrion.com/blog/2009/08/tracking-dangling-object-references-in-silverlight/">previous post</a>, you can attach WinDbg to a browser to find memory leaks in your Silverlight applications.  I figured it would be a good idea to write down how this process works, since i always end up having to look it up again whenever i need to do this.</p><p>I wrote a very simple Silverlight application which has a rather typical memory leak. Here's the actual code:</p><div><pre class="brush: csharp; title: ; notranslate">
        public event EventHandler&lt;MyEventArgs&gt; MyEvent = delegate { };
 
        private void CreateNewViewButton_OnClick(object sender, RoutedEventArgs e)
        {
            ViewContainer.Children.Clear();
 
            var newView = new MyView();
            MyEvent += newView.EventHandler;
 
            ViewContainer.Children.Add(newView);
        }
</pre></div><p>For some of you, the memory leak is already very clear.  Like i said, it's a very simple example <img
src='http://d18sni7re4ly7f.cloudfront.net/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /></p><p>Let's go through the process of finding and fixing the memory leak using WinDbg. First of all, download Debugging Tools For Windows (which contains the WinDbg executable) <a
href="http://www.microsoft.com/whdc/devtools/debugging/installx86.mspx">here</a> and install it.</p><p>Then we start our application in Internet Explorer (for some reason i can't use WinDbg to inspect the managed memory heap with Firefox, so i just use Internet Explorer for this stuff) and use it.  In the case of my example, that means clicking the button which creates a new view a couple of times.</p><p>Open WinDbg.exe and select the 'Attach to a Process' menu item in the 'File' menu and select the iexplore.exe process.</p><p>Then you need to load the correct version of sos.dll:</p><p> <img
src="http://davybrion.com/blog/wp-content/uploads/2009/08/step1.png" alt="step1" title="step1" width="606" height="15" class="size-full wp-image-1498" /></p><p>After that we can see which types of our MySilverlightApplication namespace are present in the managed heap, including how many instances of them:</p><p> <img
src="http://davybrion.com/blog/wp-content/uploads/2009/08/step2.png" alt="step2" title="step2" width="952" height="122" class="size-full wp-image-1499" /></p><p>As you can see, there are 13 instances of our MyView type present in the heap.  Using the value in the MT column, we can drill down further:</p><p> <img
src="http://davybrion.com/blog/wp-content/uploads/2009/08/step3.png" alt="step3" title="step3" width="512" height="266" class="size-full wp-image-1500" /></p><p>This shows the memory address of each instance of the MyView type in the heap.  Now we can see if there are any live references to these instances:</p><p> <img
src="http://davybrion.com/blog/wp-content/uploads/2009/08/step4.png" alt="step4" title="step4" width="831" height="192" class="size-full wp-image-1501" /></p><p>This is actually for the first address that was listed.  As you can see, it is still a reachable reference, which means it will not be collected by the garbage collector. The chain of references clearly indicates that the instance is still referenced from our event in the MainPage instance.  All of the previously listed instances show the same reference chain, so this is clearly a memory leak.  Even though we should only have one active reference of MyView at any point in time of this application, the MyEvent event on MainPage clearly keeps each instance of MyView alive.</p><p>The correct way to fix this is to make sure that whenever we remove an instance of MyView, we need to unsubscribe it from the MainPage's MyEvent handler.  Always remember this rule when it comes to dealing with events: if the publisher of the event has a longer lifetime than the subscriber of the event, then you absolutely have to unsubscribe each subscriber from the event or the publisher will keep references to each subscriber (preventing them from being garbage collected) for as long as the publisher is alive.</p><p>Here's the modified version of the above code which avoids the memory leak:</p><div><pre class="brush: csharp; title: ; notranslate">
        public event EventHandler&lt;MyEventArgs&gt; MyEvent = delegate { };
 
        private void CreateNewViewButton_OnClick(object sender, RoutedEventArgs e)
        {
            CleanUpPreviousView();
 
            var newView = new MyView();
            MyEvent += newView.EventHandler;
 
            ViewContainer.Children.Add(newView);
        }
 
        private void CleanUpPreviousView()
        {
            if (ViewContainer.Children.Count &gt; 0)
            {
                var myView = ViewContainer.Children[0] as MyView;
                if (myView != null) MyEvent -= myView.EventHandler;
                ViewContainer.Children.Clear();
            }
        }
</pre></div><p>Let's see if this really fixed the memory leak.  If we fire up the application and press the button a couple of times, the application should normally only have one live reference of MyView in memory.</p><p> <img
src="http://davybrion.com/blog/wp-content/uploads/2009/08/step5.png" alt="step5" title="step5" width="952" height="125" class="size-full wp-image-1502" /></p><p>I clicked the button 5 times, and the above output shows that there are 5 instances of MyView on the heap.  So did we fix the leak or not?  Check the output below:</p><p> <img
src="http://davybrion.com/blog/wp-content/uploads/2009/08/step6.png" alt="step6" title="step6" width="622" height="604" class="size-full wp-image-1497" /></p><p>As you can see, only the last instance of MyView is actively referenced somewhere.  That means that the first 4 instances are ready to be collected during the next garbage collection.</p><p>One thing i don't understand though, is that the reference chain of the last instance doesn't mention MainPage or the event handler anymore.  But when i attached Visual Studio's debugger to the browser instance i could clearly see that the MyEvent of MainPage indeed contained an event handler that pointed to this MyView instance.  I'm far from a WinDbg and SOS expert so i have no idea why the reference chain doesn't reflect this.  Perhaps someone with more WinDbg and SOS knowledge can shed some light on this?</p><p>Either way, this approach is a pretty good way of finding memory leaks in your Silverlight code.  In a real application it's obviously a bit more complicated to find the exact cause of a leak compared to this simple example, but it's still pretty doable.  Just execute the !dumpheap -stat -type YourRootNameSpaceHere and look for unusually high numbers of instances of your types.  Then you can start looking at each instance to figure out what's going on.  And for a nice list of commands that you can execute in WinDbg with SOS, be sure to check <a
href="http://msdn.microsoft.com/en-us/library/bb190764.aspx">this</a> out.</p><p>Also, keep in mind that you can do this for every .NET process, and not just Silverlight.  Though you would need to load the sos.dll file of your particular .NET version.</p><div
class="bottomcontainerBox" style=""><div
style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <iframe
src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fdavybrion.com%2Fblog%2F2009%2F08%2Ffinding-memory-leaks-in-silverlight-with-windbg%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:85px; height:21px;"></iframe></div><div
style="float:left; width:80px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <g:plusone size="medium" href="http://davybrion.com/blog/2009/08/finding-memory-leaks-in-silverlight-with-windbg/"></g:plusone></div><div
style="float:left; width:95px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <a
href="http://twitter.com/share" class="twitter-share-button" data-url="http://davybrion.com/blog/2009/08/finding-memory-leaks-in-silverlight-with-windbg/"  data-text="Finding Memory Leaks In Silverlight With WinDbg" data-count="horizontal" data-via="davybrion"></a></div><div
style="float:left; width:105px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script type="in/share" data-url="http://davybrion.com/blog/2009/08/finding-memory-leaks-in-silverlight-with-windbg/" data-counter="right"></script></div><div
style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script src="http://www.stumbleupon.com/hostedbadge.php?s=1&amp;r=http://davybrion.com/blog/2009/08/finding-memory-leaks-in-silverlight-with-windbg/"></script></div></div><div
style="clear:both"></div><div
style="padding-bottom:4px;"></div>]]></content:encoded> <wfw:commentRss>http://davybrion.com/blog/2009/08/finding-memory-leaks-in-silverlight-with-windbg/feed/</wfw:commentRss> <slash:comments>17</slash:comments> </item> <item><title>Refactor Safe Implementation Of INotifyPropertyChanged</title><link>http://davybrion.com/blog/2009/08/refactor-safe-implementation-of-inotifypropertychanged/</link> <comments>http://davybrion.com/blog/2009/08/refactor-safe-implementation-of-inotifypropertychanged/#comments</comments> <pubDate>Wed, 05 Aug 2009 09:34:31 +0000</pubDate> <dc:creator>Davy Brion</dc:creator> <category><![CDATA[Silverlight]]></category><guid
isPermaLink="false">http://davybrion.com/blog/?p=1483</guid> <description><![CDATA[One thing that always annoyed the hell out of me when implementing INotifyPropertyChanged for Silverlight (or WPF) databinding was the fact that you have to provide the name of the property as a string. There are some cool AOP solutions to this, but if you can't use those for whatever reason, you could use LINQ's [...]]]></description> <content:encoded><![CDATA[<p>One thing that always annoyed the hell out of me when implementing INotifyPropertyChanged for Silverlight (or WPF) databinding was the fact that you have to provide the name of the property as a string.  There are some cool AOP solutions to this, but if you can't use those for whatever reason, you could use LINQ's Expressions to avoid having to use strings.</p><p>We already have a base PresentationModel which has the following method:</p><p><code></p><div
style="font-family: Consolas; font-size: 9pt; color: black; background: white;"><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
style="color: blue;">protected</span> <span
style="color: blue;">void</span> NotifyPropertyChanged(<span
style="color: blue;">string</span> propertyName)</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; PropertyChanged(<span
style="color: blue;">this</span>, <span
style="color: blue;">new</span> <span
style="color: #2b91af;">PropertyChangedEventArgs</span>(propertyName));</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p></div><p></code></p><p>We also have a generic PresentationModel class which inherits from this class:</p><p><code></p><div
style="font-family: Consolas; font-size: 9pt; color: black; background: white;"><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; <span
style="color: blue;">public</span> <span
style="color: blue;">abstract</span> <span
style="color: blue;">class</span> <span
style="color: #2b91af;">PresentationModel</span>&lt;TPresentationModel&gt; : <span
style="color: #2b91af;">PresentationModel</span></p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
style="color: blue;">where</span> TPresentationModel : <span
style="color: #2b91af;">PresentationModel</span>&lt;TPresentationModel&gt;</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; {</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
style="color: blue;">protected</span> <span
style="color: blue;">void</span> NotifyPropertyChanged(<span
style="color: #2b91af;">Expression</span>&lt;<span
style="color: #2b91af;">Func</span>&lt;TPresentationModel, <span
style="color: blue;">object</span>&gt;&gt; expression)</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
style="color: blue;">var</span> memberExpression = expression.Body <span
style="color: blue;">as</span> <span
style="color: #2b91af;">MemberExpression</span>;</p><p
style="margin: 0px;">&nbsp;</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
style="color: blue;">if</span> (memberExpression == <span
style="color: blue;">null</span>)</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
style="color: blue;">throw</span> <span
style="color: blue;">new</span> <span
style="color: #2b91af;">InvalidOperationException</span>(<span
style="color: #a31515;">&quot;You must specify a property!&quot;</span>);</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p><p
style="margin: 0px;">&nbsp;</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; NotifyPropertyChanged(memberExpression.Member.Name);</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; }</p></div><p></code></p><p>Notice that you pass an expression to the NotifyPropertyChanged method.  It can be used like this:</p><p><code></p><div
style="font-family: Consolas; font-size: 9pt; color: black; background: white;"><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; <span
style="color: blue;">public</span> <span
style="color: blue;">class</span> <span
style="color: #2b91af;">MyTestPresentationModel</span> : <span
style="color: #2b91af;">PresentationModel</span>&lt;<span
style="color: #2b91af;">MyTestPresentationModel</span>&gt;</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; {</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
style="color: blue;">private</span> <span
style="color: blue;">string</span> myString;</p><p
style="margin: 0px;">&nbsp;</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
style="color: blue;">public</span> <span
style="color: blue;">string</span> MyString</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
style="color: blue;">get</span></p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
style="color: blue;">return</span> myString;</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
style="color: blue;">set</span></p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; myString = <span
style="color: blue;">value</span>;</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; NotifyPropertyChanged(t =&gt; t.MyString);</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; }</p></div><p></code></p><p>That's pretty cool, but you should be able to test this easily, right? That's pretty easy to do as well:</p><p><code></p><div
style="font-family: Consolas; font-size: 9pt; color: black; background: white;"><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; <span
style="color: blue;">public</span> <span
style="color: blue;">class</span> <span
style="color: #2b91af;">PresentationModelTest</span>&lt;TPresentationModel&gt; <span
style="color: blue;">where</span> TPresentationModel : <span
style="color: #2b91af;">PresentationModel</span>&lt;TPresentationModel&gt;</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; {</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
style="color: blue;">protected</span> <span
style="color: blue;">void</span> AssertThatPropertyChangedIsCorrect&lt;TArgument&gt;(TPresentationModel model,</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
style="color: #2b91af;">Expression</span>&lt;<span
style="color: #2b91af;">Func</span>&lt;TPresentationModel, TArgument&gt;&gt; property, TArgument value)</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
style="color: blue;">var</span> memberInfo = ((<span
style="color: #2b91af;">MemberExpression</span>)property.Body).Member;</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
style="color: blue;">var</span> propertyName = memberInfo.Name;</p><p
style="margin: 0px;">&nbsp;</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
style="color: blue;">bool</span> eventProperlyTriggered = <span
style="color: blue;">false</span>;</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; model.PropertyChanged += (s, e) =&gt; eventProperlyTriggered = e.PropertyName.Equals(propertyName);</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
style="color: blue;">typeof</span>(TPresentationModel).GetProperty(propertyName).SetValue(model, value, <span
style="color: blue;">null</span>);</p><p
style="margin: 0px;">&nbsp;</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
style="color: #2b91af;">Assert</span>.IsTrue(eventProperlyTriggered);</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; }</p><p
style="margin: 0px;">&nbsp;</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; [<span
style="color: #2b91af;">TestClass</span>]</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; <span
style="color: blue;">public</span> <span
style="color: blue;">class</span> <span
style="color: #2b91af;">PresentationModelTests</span> : <span
style="color: #2b91af;">PresentationModelTest</span>&lt;<span
style="color: #2b91af;">MyTestPresentationModel</span>&gt;</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; {</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; [<span
style="color: #2b91af;">TestMethod</span>]</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
style="color: blue;">public</span> <span
style="color: blue;">void</span> NotifyPropertyChanged_WithExpression_TriggersCorrectPropertyChangedEvent()</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
style="color: blue;">var</span> model = <span
style="color: blue;">new</span> <span
style="color: #2b91af;">MyTestPresentationModel</span>();</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; AssertThatPropertyChangedIsCorrect(model, m =&gt; m.MyString, <span
style="color: #a31515;">&quot;blah&quot;</span>);</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; }</p></div><p></code></p><p>There we go... no more strings so refactoring won't break anything, and it's easy to test as well.</p><div
class="bottomcontainerBox" style=""><div
style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <iframe
src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fdavybrion.com%2Fblog%2F2009%2F08%2Frefactor-safe-implementation-of-inotifypropertychanged%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:85px; height:21px;"></iframe></div><div
style="float:left; width:80px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <g:plusone size="medium" href="http://davybrion.com/blog/2009/08/refactor-safe-implementation-of-inotifypropertychanged/"></g:plusone></div><div
style="float:left; width:95px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <a
href="http://twitter.com/share" class="twitter-share-button" data-url="http://davybrion.com/blog/2009/08/refactor-safe-implementation-of-inotifypropertychanged/"  data-text="Refactor Safe Implementation Of INotifyPropertyChanged" data-count="horizontal" data-via="davybrion"></a></div><div
style="float:left; width:105px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script type="in/share" data-url="http://davybrion.com/blog/2009/08/refactor-safe-implementation-of-inotifypropertychanged/" data-counter="right"></script></div><div
style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script src="http://www.stumbleupon.com/hostedbadge.php?s=1&amp;r=http://davybrion.com/blog/2009/08/refactor-safe-implementation-of-inotifypropertychanged/"></script></div></div><div
style="clear:both"></div><div
style="padding-bottom:4px;"></div>]]></content:encoded> <wfw:commentRss>http://davybrion.com/blog/2009/08/refactor-safe-implementation-of-inotifypropertychanged/feed/</wfw:commentRss> <slash:comments>8</slash:comments> </item> <item><title>Tracking Dangling Object References In Silverlight</title><link>http://davybrion.com/blog/2009/08/tracking-dangling-object-references-in-silverlight/</link> <comments>http://davybrion.com/blog/2009/08/tracking-dangling-object-references-in-silverlight/#comments</comments> <pubDate>Tue, 04 Aug 2009 15:39:58 +0000</pubDate> <dc:creator>Davy Brion</dc:creator> <category><![CDATA[Memory Management]]></category> <category><![CDATA[Silverlight]]></category><guid
isPermaLink="false">http://davybrion.com/blog/?p=1478</guid> <description><![CDATA[One of the downsides of working with a young platform like Silverlight is that the tool support isn't quite 'there' yet, particularly when it comes to profiling for performance and memory usage. And as you may or may not know, Silverlight makes it very easy to introduce memory leaks into your code. Since you can't [...]]]></description> <content:encoded><![CDATA[<p>One of the downsides of working with a young platform like Silverlight is that the tool support isn't quite 'there' yet, particularly when it comes to profiling for performance and memory usage.  And as you may or may not know, Silverlight makes it very easy to introduce memory leaks into your code.  Since you can't just attach a memory profiler to your Silverlight application, optimizing memory usage or tracking down a leak can be a real pain in the ass.</p><p>In the past i have resorted to grabbing a memory dump of the browser and analyzing the content of the managed heap with windbg to track down which instances where being kept in memory.  While this works, it's pretty time consuming and can quite easily lead you down the wrong path.  One of the most important things that you want to know in this specific case is: which types are being kept in memory, and how many of them?</p><p>In this case, being able to query something during debugging regarding which instances are still kept alive in memory at certain times is sufficient for me.  So i came up with the following class:</p><p><code></p><div
style="font-family: Consolas; font-size: 9pt; color: black; background: white;"><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; <span
style="color: blue;">public</span> <span
style="color: blue;">static</span> <span
style="color: blue;">class</span> <span
style="color: #2b91af;">ObjectTracker</span></p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; {</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
style="color: blue;">private</span> <span
style="color: blue;">static</span> <span
style="color: blue;">readonly</span> <span
style="color: blue;">object</span> monitor = <span
style="color: blue;">new</span> <span
style="color: blue;">object</span>();</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
style="color: blue;">private</span> <span
style="color: blue;">static</span> <span
style="color: blue;">readonly</span> <span
style="color: #2b91af;">List</span>&lt;<span
style="color: #2b91af;">WeakReference</span>&gt; objects = <span
style="color: blue;">new</span> <span
style="color: #2b91af;">List</span>&lt;<span
style="color: #2b91af;">WeakReference</span>&gt;();</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
style="color: blue;">private</span> <span
style="color: blue;">static</span> <span
style="color: blue;">bool</span>? shouldTrack;</p><p
style="margin: 0px;">&nbsp;</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
style="color: blue;">public</span> <span
style="color: blue;">static</span> <span
style="color: blue;">void</span> Track(<span
style="color: blue;">object</span> objectToTrack)</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
style="color: blue;">if</span> (ShouldTrack())</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
style="color: blue;">lock</span> (monitor)</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; objects.Add(<span
style="color: blue;">new</span> <span
style="color: #2b91af;">WeakReference</span>(objectToTrack));</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p><p
style="margin: 0px;">&nbsp;</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
style="color: blue;">private</span> <span
style="color: blue;">static</span> <span
style="color: blue;">bool</span> ShouldTrack()</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
style="color: blue;">if</span> (shouldTrack == <span
style="color: blue;">null</span>)</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; shouldTrack = <span
style="color: #2b91af;">Debugger</span>.IsAttached;</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p><p
style="margin: 0px;">&nbsp;</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
style="color: blue;">return</span> shouldTrack.Value;</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p><p
style="margin: 0px;">&nbsp;</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
style="color: blue;">public</span> <span
style="color: blue;">static</span> <span
style="color: #2b91af;">IEnumerable</span>&lt;<span
style="color: blue;">object</span>&gt; GetAllLiveTrackedObjects()</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
style="color: blue;">lock</span> (monitor)</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
style="color: #2b91af;">GC</span>.Collect();</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
style="color: blue;">return</span> objects.Where(o =&gt; o.IsAlive).Select(o =&gt; o.Target);</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; }</p></div><p></code></p><p>The idea is basically to just keep a list of WeakReferences of objects you want to track (only if a debugger is attached), and later on you can 'query' the live instances through the GetAllLiveTrackedObjects method.  This method obviously performs a full garbage collect to make sure only objects that are really still alive are returned.  Again, you should almost never do a GC.Collect() manually, but in this case the method will only be called while you're debugging.</p><p>Then, you strategically put the following line in the constructor of every kind of type you'd like to track:</p><p><code></p><div
style="font-family: Consolas; font-size: 9pt; color: black; background: white;"><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
style="color: #2b91af;">ObjectTracker</span>.Track(<span
style="color: blue;">this</span>);</p></div><p></code></p><p>I have that line in the constructor of my base View class, my base Controller class and in my base Disposable class.  So now, when i want to check if there are any dangling references to instances of types that i really don't want hanging around, i can just do something like this:</p><p><code></p><div
style="font-family: Consolas; font-size: 9pt; color: black; background: white;"><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
style="color: blue;">var</span> liveObjects = <span
style="color: #2b91af;">ObjectTracker</span>.GetAllLiveTrackedObjects();</p><p
style="margin: 0px;">&nbsp;</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
style="color: blue;">if</span> (<span
style="color: #2b91af;">Debugger</span>.IsAttached)</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
style="color: #2b91af;">Debugger</span>.Break();</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p></div><p></code></p><p>And then manually inspect the content of the liveObjects collection.  It's far from perfect, but at least it's an easy way to at least know which instances (that i care about) are being kept in memory.  It'll do until we get better tool support :p</p><div
class="bottomcontainerBox" style=""><div
style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <iframe
src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fdavybrion.com%2Fblog%2F2009%2F08%2Ftracking-dangling-object-references-in-silverlight%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:85px; height:21px;"></iframe></div><div
style="float:left; width:80px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <g:plusone size="medium" href="http://davybrion.com/blog/2009/08/tracking-dangling-object-references-in-silverlight/"></g:plusone></div><div
style="float:left; width:95px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <a
href="http://twitter.com/share" class="twitter-share-button" data-url="http://davybrion.com/blog/2009/08/tracking-dangling-object-references-in-silverlight/"  data-text="Tracking Dangling Object References In Silverlight" data-count="horizontal" data-via="davybrion"></a></div><div
style="float:left; width:105px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script type="in/share" data-url="http://davybrion.com/blog/2009/08/tracking-dangling-object-references-in-silverlight/" data-counter="right"></script></div><div
style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script src="http://www.stumbleupon.com/hostedbadge.php?s=1&amp;r=http://davybrion.com/blog/2009/08/tracking-dangling-object-references-in-silverlight/"></script></div></div><div
style="clear:both"></div><div
style="padding-bottom:4px;"></div>]]></content:encoded> <wfw:commentRss>http://davybrion.com/blog/2009/08/tracking-dangling-object-references-in-silverlight/feed/</wfw:commentRss> <slash:comments>12</slash:comments> </item> <item><title>Hosting Silverlight Client Apps In A Silverlight Host App</title><link>http://davybrion.com/blog/2009/08/hosting-silverlight-client-apps-in-a-silverlight-host-app/</link> <comments>http://davybrion.com/blog/2009/08/hosting-silverlight-client-apps-in-a-silverlight-host-app/#comments</comments> <pubDate>Sun, 02 Aug 2009 13:23:28 +0000</pubDate> <dc:creator>Davy Brion</dc:creator> <category><![CDATA[Silverlight]]></category><guid
isPermaLink="false">http://davybrion.com/blog/?p=1468</guid> <description><![CDATA[For one of our customers, we need to be able to host multiple Silverlight applications within one dedicated Silverlight 'host' application. Prism offers this ability, but we already have our own implementations for pretty much all of the other stuff that Prism offers (and that we need), so we figured we might as well implement [...]]]></description> <content:encoded><![CDATA[<p>For one of our customers, we need to be able to host multiple Silverlight applications within one dedicated Silverlight 'host' application. <a
href="http://compositewpf.codeplex.com/">Prism</a> offers this ability, but we already have our own implementations for pretty much all of the other stuff that Prism offers (and that we need), so we figured we might as well implement this hosting feature ourselves.  It turns out it's pretty easy to do this.</p><p>The general idea is to be able to implement each client application in its own Silverlight Application Project, and to have the ability to download each client aplication's XAP file into the Host application and display it within the designated visual area for the currently active client application.</p><p>First, we need an interface that each client application needs to contain an implementation of:</p><p><code><style type="text/css">.cf{font-family:Consolas;font-size:9pt;color:black;background:white}.cl{margin:0px}.cb1{color:blue}.cb2{color:#2b91af}</style></p><div
class="cf"><p
class="cl">&nbsp;&nbsp;&nbsp; <span
class="cb1">public</span> <span
class="cb1">interface</span> <span
class="cb2">IClientApplication</span></p><p
class="cl">&nbsp;&nbsp;&nbsp; {</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
class="cb1">void</span> Initialize();</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
class="cb1">void</span> Cleanup();</p><p
class="cl">&nbsp;</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
class="cb2">UIElement</span> VisualContainer { <span
class="cb1">get</span>; }</p><p
class="cl">&nbsp;&nbsp;&nbsp; }</p></div><p></code></p><p>The VisualContainer property needs to return a UIElement which is basically the main visual container element of the client application.  This could be its main page or just a grid or just about any graphical component.</p><p>Then we need a class to download XAP files based on their URI. Since you have to do all of these things asynchronously in Silverlight, and the generally used approach seems to be the event-based async pattern, i use the following base eventargs class for all of my asynchronous operations:</p><p><code><style type="text/css">.cf{font-family:Consolas;font-size:9pt;color:black;background:white}.cl{margin:0px}.cb1{color:blue}.cb2{color:#2b91af}.cb3{color:#a31515}</style></p><div
class="cf"><p
class="cl">&nbsp;&nbsp;&nbsp; <span
class="cb1">public</span> <span
class="cb1">abstract</span> <span
class="cb1">class</span> <span
class="cb2">AsyncOperationCompletedEventArgs</span>&lt;T&gt; : <span
class="cb2">EventArgs</span></p><p
class="cl">&nbsp;&nbsp;&nbsp; {</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
class="cb1">protected</span> AsyncOperationCompletedEventArgs(T result, <span
class="cb2">Exception</span> error)</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
class="cb1">this</span>.result = result;</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Error = error;</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p><p
class="cl">&nbsp;</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
class="cb1">public</span> <span
class="cb2">Exception</span> Error { <span
class="cb1">get</span>; <span
class="cb1">set</span>; }</p><p
class="cl">&nbsp;</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
class="cb1">private</span> <span
class="cb1">readonly</span> T result;</p><p
class="cl">&nbsp;</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
class="cb1">public</span> T Result</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
class="cb1">get</span></p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
class="cb1">if</span> (Error != <span
class="cb1">null</span>)</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
class="cb1">throw</span> <span
class="cb1">new</span> <span
class="cb2">InvalidOperationException</span>(<span
class="cb3">&quot;The operation did not complete succesfully, please retrieve the Error property&quot;</span>);</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p><p
class="cl">&nbsp;</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
class="cb1">return</span> result;</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p><p
class="cl">&nbsp;&nbsp;&nbsp; }</p></div><p></code></p><p>And then we have the DownloadCompletedEventArgs class:</p><p><code><style type="text/css">.cf{font-family:Consolas;font-size:9pt;color:black;background:white}.cl{margin:0px}.cb1{color:blue}.cb2{color:#2b91af}</style></p><div
class="cf"><p
class="cl">&nbsp;&nbsp;&nbsp; <span
class="cb1">public</span> <span
class="cb1">class</span> <span
class="cb2">DownloadCompletedEventArgs</span> : <span
class="cb2">AsyncOperationCompletedEventArgs</span>&lt;<span
class="cb2">Stream</span>&gt;</p><p
class="cl">&nbsp;&nbsp;&nbsp; {</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
class="cb1">public</span> DownloadCompletedEventArgs(<span
class="cb2">Stream</span> result, <span
class="cb2">Exception</span> e) : <span
class="cb1">base</span>(result, e) {}</p><p
class="cl">&nbsp;&nbsp;&nbsp; }</p></div><p></code></p><p>Now we can write our simple FileDownloader class:</p><p><code><style type="text/css">.cf{font-family:Consolas;font-size:9pt;color:black;background:white}.cl{margin:0px}.cb1{color:blue}.cb2{color:#2b91af}</style></p><div
class="cf"><p
class="cl">&nbsp;&nbsp;&nbsp; <span
class="cb1">public</span> <span
class="cb1">interface</span> <span
class="cb2">IFileDownloader</span></p><p
class="cl">&nbsp;&nbsp;&nbsp; {</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
class="cb1">event</span> <span
class="cb2">EventHandler</span>&lt;<span
class="cb2">ProgressChangedEventArgs</span>&gt; ProgressChanged;</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
class="cb1">event</span> <span
class="cb2">EventHandler</span>&lt;<span
class="cb2">DownloadCompletedEventArgs</span>&gt; DownloadCompleted;</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
class="cb1">void</span> StartDownloading(<span
class="cb2">Uri</span> locationOfResource);</p><p
class="cl">&nbsp;&nbsp;&nbsp; }</p><p
class="cl">&nbsp;</p><p
class="cl">&nbsp;&nbsp;&nbsp; <span
class="cb1">public</span> <span
class="cb1">class</span> <span
class="cb2">FileDownloader</span> : <span
class="cb2">IFileDownloader</span></p><p
class="cl">&nbsp;&nbsp;&nbsp; {</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
class="cb1">public</span> <span
class="cb1">event</span> <span
class="cb2">EventHandler</span>&lt;<span
class="cb2">ProgressChangedEventArgs</span>&gt; ProgressChanged = <span
class="cb1">delegate</span> { };</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
class="cb1">public</span> <span
class="cb1">event</span> <span
class="cb2">EventHandler</span>&lt;<span
class="cb2">DownloadCompletedEventArgs</span>&gt; DownloadCompleted = <span
class="cb1">delegate</span> { };</p><p
class="cl">&nbsp;</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
class="cb1">public</span> <span
class="cb1">void</span> StartDownloading(<span
class="cb2">Uri</span> locationOfResource)</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
class="cb1">var</span> webClient = <span
class="cb1">new</span> <span
class="cb2">WebClient</span>();</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; webClient.DownloadProgressChanged += webClient_DownloadProgressChanged;</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; webClient.OpenReadCompleted += webClient_OpenReadCompleted;</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; webClient.OpenReadAsync(locationOfResource);</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p><p
class="cl">&nbsp;</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
class="cb1">private</span> <span
class="cb1">void</span> webClient_OpenReadCompleted(<span
class="cb1">object</span> sender, <span
class="cb2">OpenReadCompletedEventArgs</span> e)</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
class="cb2">DownloadCompletedEventArgs</span> eventArgs;</p><p
class="cl">&nbsp;</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
class="cb1">if</span> (!e.Cancelled &amp;&amp; e.Error == <span
class="cb1">null</span>)</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; eventArgs = <span
class="cb1">new</span> <span
class="cb2">DownloadCompletedEventArgs</span>(e.Result, <span
class="cb1">null</span>);</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
class="cb1">else</span></p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; eventArgs = <span
class="cb1">new</span> <span
class="cb2">DownloadCompletedEventArgs</span>(<span
class="cb1">null</span>, e.Error);</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p><p
class="cl">&nbsp;</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; DownloadCompleted(<span
class="cb1">this</span>, eventArgs);</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p><p
class="cl">&nbsp;</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
class="cb1">private</span> <span
class="cb1">void</span> webClient_DownloadProgressChanged(<span
class="cb1">object</span> sender, <span
class="cb2">DownloadProgressChangedEventArgs</span> e)</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ProgressChanged(<span
class="cb1">this</span>, <span
class="cb1">new</span> <span
class="cb2">ProgressChangedEventArgs</span>(e.ProgressPercentage, <span
class="cb1">null</span>));</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p><p
class="cl">&nbsp;&nbsp;&nbsp; }</p></div><p></code></p><p>We also need something to extract the assemblies from a downloaded XAP file:</p><p><code><style type="text/css">.cf{font-family:Consolas;font-size:9pt;color:black;background:white}.cl{margin:0px}.cb1{color:blue}.cb2{color:#2b91af}.cb3{color:#a31515}</style></p><div
class="cf"><p
class="cl">&nbsp;&nbsp;&nbsp; <span
class="cb1">public</span> <span
class="cb1">interface</span> <span
class="cb2">IXapReader</span></p><p
class="cl">&nbsp;&nbsp;&nbsp; {</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
class="cb2">IEnumerable</span>&lt;<span
class="cb2">Assembly</span>&gt; GetAssemblies(<span
class="cb2">Stream</span> stream);</p><p
class="cl">&nbsp;&nbsp;&nbsp; }</p><p
class="cl">&nbsp;</p><p
class="cl">&nbsp;&nbsp;&nbsp; <span
class="cb1">public</span> <span
class="cb1">class</span> <span
class="cb2">XapReader</span> : <span
class="cb2">IXapReader</span></p><p
class="cl">&nbsp;&nbsp;&nbsp; {</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
class="cb1">public</span> <span
class="cb2">IEnumerable</span>&lt;<span
class="cb2">Assembly</span>&gt; GetAssemblies(<span
class="cb2">Stream</span> stream)</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
class="cb1">var</span> assemblies = <span
class="cb1">new</span> <span
class="cb2">List</span>&lt;<span
class="cb2">Assembly</span>&gt;();</p><p
class="cl">&nbsp;</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
class="cb1">foreach</span> (<span
class="cb1">var</span> deploymentPart <span
class="cb1">in</span> GetDeploymentParts(stream))</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; assemblies.Add(LoadAssembly(deploymentPart, stream));</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p><p
class="cl">&nbsp;</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
class="cb1">return</span> assemblies;</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p><p
class="cl">&nbsp;</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
class="cb1">private</span> <span
class="cb1">static</span> <span
class="cb2">Assembly</span> LoadAssembly(<span
class="cb2">XElement</span> deploymentPart, <span
class="cb2">Stream</span> stream)</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
class="cb1">var</span> assemblyPart = <span
class="cb1">new</span> <span
class="cb2">AssemblyPart</span>();</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
class="cb1">var</span> source = deploymentPart.Attribute(<span
class="cb3">&quot;Source&quot;</span>).Value;</p><p
class="cl">&nbsp;</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
class="cb1">var</span> streamResourceInfo = <span
class="cb2">Application</span>.GetResourceStream(</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
class="cb1">new</span> <span
class="cb2">StreamResourceInfo</span>(stream, <span
class="cb3">&quot;application/binary&quot;</span>),</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
class="cb1">new</span> <span
class="cb2">Uri</span>(source, <span
class="cb2">UriKind</span>.Relative));</p><p
class="cl">&nbsp;</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
class="cb1">return</span> assemblyPart.Load(streamResourceInfo.Stream);</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p><p
class="cl">&nbsp;</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
class="cb1">private</span> <span
class="cb1">static</span> <span
class="cb2">IEnumerable</span>&lt;<span
class="cb2">XElement</span>&gt; GetDeploymentParts(<span
class="cb2">Stream</span> stream)</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
class="cb1">var</span> appManifest = GetApplicationManifest(stream);</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
class="cb1">var</span> deploymentRoot = <span
class="cb2">XDocument</span>.Parse(appManifest).Root;</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
class="cb1">return</span> deploymentRoot.Elements().First().Elements();</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p><p
class="cl">&nbsp;</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
class="cb1">private</span> <span
class="cb1">static</span> <span
class="cb1">string</span> GetApplicationManifest(<span
class="cb2">Stream</span> stream)</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
class="cb1">return</span> <span
class="cb1">new</span> <span
class="cb2">StreamReader</span>(<span
class="cb2">Application</span>.GetResourceStream(</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
class="cb1">new</span> <span
class="cb2">StreamResourceInfo</span>(stream, <span
class="cb1">null</span>),</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
class="cb1">new</span> <span
class="cb2">Uri</span>(<span
class="cb3">&quot;AppManifest.xaml&quot;</span>, <span
class="cb2">UriKind</span>.Relative)).Stream)</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; .ReadToEnd();</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p><p
class="cl">&nbsp;&nbsp;&nbsp; }</p></div><p></code></p><p>And then we can write a class which can retrieve the type which implements the IClientApplication interface from a downloaded XAP file:</p><p><code><style type="text/css">.cf{font-family:Consolas;font-size:9pt;color:black;background:white}.cl{margin:0px}.cb1{color:blue}.cb2{color:#2b91af}</style></p><div
class="cf"><p
class="cl">&nbsp;&nbsp;&nbsp; <span
class="cb1">public</span> <span
class="cb1">interface</span> <span
class="cb2">IClientApplicationTypeLoader</span></p><p
class="cl">&nbsp;&nbsp;&nbsp; {</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
class="cb1">event</span> <span
class="cb2">EventHandler</span>&lt;<span
class="cb2">ClientApplicationLoadedEventArgs</span>&gt; LoadCompleted;</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
class="cb1">event</span> <span
class="cb2">EventHandler</span>&lt;<span
class="cb2">ProgressChangedEventArgs</span>&gt; ProgressChanged;</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
class="cb1">void</span> Load(<span
class="cb2">Uri</span> xapLocation);</p><p
class="cl">&nbsp;&nbsp;&nbsp; }</p><p
class="cl">&nbsp;</p><p
class="cl">&nbsp;&nbsp;&nbsp; <span
class="cb1">public</span> <span
class="cb1">class</span> <span
class="cb2">ClientApplicationTypeLoader</span> : <span
class="cb2">IClientApplicationTypeLoader</span></p><p
class="cl">&nbsp;&nbsp;&nbsp; {</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
class="cb1">public</span> <span
class="cb1">event</span> <span
class="cb2">EventHandler</span>&lt;<span
class="cb2">ClientApplicationLoadedEventArgs</span>&gt; LoadCompleted = <span
class="cb1">delegate</span> { };</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
class="cb1">public</span> <span
class="cb1">event</span> <span
class="cb2">EventHandler</span>&lt;<span
class="cb2">ProgressChangedEventArgs</span>&gt; ProgressChanged = <span
class="cb1">delegate</span> { };</p><p
class="cl">&nbsp;</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
class="cb1">private</span> <span
class="cb2">IFileDownloader</span> fileDownloader;</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
class="cb1">private</span> <span
class="cb2">IXapReader</span> xapReader;</p><p
class="cl">&nbsp;</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
class="cb1">public</span> ClientApplicationTypeLoader(<span
class="cb2">IFileDownloader</span> fileDownloader, <span
class="cb2">IXapReader</span> xapReader)</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
class="cb1">this</span>.fileDownloader = fileDownloader;</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
class="cb1">this</span>.xapReader = xapReader;</p><p
class="cl">&nbsp;</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; fileDownloader.ProgressChanged += downloader_ProgressChanged;</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; fileDownloader.DownloadCompleted += downloader_DownloadCompleted;</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p><p
class="cl">&nbsp;</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
class="cb1">public</span> <span
class="cb1">void</span> Load(<span
class="cb2">Uri</span> xapLocation)</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; fileDownloader.StartDownloading(xapLocation);</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p><p
class="cl">&nbsp;</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
class="cb1">private</span> <span
class="cb1">void</span> downloader_ProgressChanged(<span
class="cb1">object</span> sender, <span
class="cb2">ProgressChangedEventArgs</span> e)</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ProgressChanged(<span
class="cb1">this</span>, e);</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p><p
class="cl">&nbsp;</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
class="cb1">private</span> <span
class="cb1">void</span> downloader_DownloadCompleted(<span
class="cb1">object</span> sender, <span
class="cb2">DownloadCompletedEventArgs</span> e)</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
class="cb1">if</span> (e.Error != <span
class="cb1">null</span>)</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; LoadCompleted(<span
class="cb1">this</span>, <span
class="cb1">new</span> <span
class="cb2">ClientApplicationLoadedEventArgs</span>(<span
class="cb1">null</span>, e.Error));</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
class="cb1">return</span>;</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p><p
class="cl">&nbsp;</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
class="cb1">var</span> assemblies = xapReader.GetAssemblies(e.Result);</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
class="cb1">var</span> clientApplicationType = FindClientApplicationType(assemblies);</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; LoadCompleted(<span
class="cb1">this</span>, <span
class="cb1">new</span> <span
class="cb2">ClientApplicationLoadedEventArgs</span>(clientApplicationType, <span
class="cb1">null</span>));</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p><p
class="cl">&nbsp;</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
class="cb1">private</span> <span
class="cb2">Type</span> FindClientApplicationType(<span
class="cb2">IEnumerable</span>&lt;<span
class="cb2">Assembly</span>&gt; assemblies)</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
class="cb1">foreach</span> (<span
class="cb1">var</span> assembly <span
class="cb1">in</span> assemblies)</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
class="cb1">foreach</span> (<span
class="cb1">var</span> type <span
class="cb1">in</span> assembly.GetTypes())</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
class="cb1">if</span> (type.GetInterfaces().Contains(<span
class="cb1">typeof</span>(<span
class="cb2">IClientApplication</span>)))</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
class="cb1">return</span> type;</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p><p
class="cl">&nbsp;</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
class="cb1">return</span> <span
class="cb1">null</span>;</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p><p
class="cl">&nbsp;&nbsp;&nbsp; }</p></div><p></code></p><p>Obviously, this code doesn't deal with the possibility of multiple or no IClientApplication implementations within the same XAP file.  Not really relevant for this post though <img
src='http://d18sni7re4ly7f.cloudfront.net/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /></p><p>And now, we can simply do something like this within our host application:</p><p><code><style type="text/css">.cf{font-family:Consolas;font-size:9pt;color:black;background:white}.cl{margin:0px}</style></p><div
class="cf"><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; clientApplicationTypeLoader.LoadCompleted += loader_LoadCompleted;</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; clientApplicationTypeLoader.ProgressChanged += loader_ProgressChanged;</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; clientApplicationTypeLoader.Load(xapUri);</p></div><p></code></p><p>and the LoadCompleted event handler could look like this:</p><p><code><style type="text/css">.cf{font-family:Consolas;font-size:9pt;color:black;background:white}.cl{margin:0px}.cb1{color:blue}.cb2{color:#2b91af}.cb3{color:#a31515}</style></p><div
class="cf"><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
class="cb1">void</span> loader_LoadCompleted(<span
class="cb1">object</span> sender, <span
class="cb2">ClientApplicationLoadedEventArgs</span> e)</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
class="cb1">if</span> (e.Error != <span
class="cb1">null</span>)</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
class="cb1">throw</span> <span
class="cb1">new</span> <span
class="cb2">Exception</span>(<span
class="cb3">&quot;error while retrieving client application&quot;</span>, e.Error);</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p><p
class="cl">&nbsp;</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; CleanupCurrentClientApp();</p><p
class="cl">&nbsp;</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
class="cb1">var</span> clientApp = (<span
class="cb2">IClientApplication</span>)<span
class="cb2">Activator</span>.CreateInstance(e.Result);</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; clientApp.Initialize();</p><p
class="cl">&nbsp;</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; AppContainer.Children.Add(clientApp.VisualContainer);</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p><p
class="cl">&nbsp;</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
class="cb1">private</span> <span
class="cb1">void</span> CleanupCurrentClientApp()</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
class="cb1">if</span> (AppContainer.Children.Count == 0)</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
class="cb1">return</span>;</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p><p
class="cl">&nbsp;</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
class="cb1">var</span> currentClientApp = (<span
class="cb2">IClientApplication</span>)AppContainer.Children[0];</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; currentClientApp.Cleanup();</p><p
class="cl">&nbsp;</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; AppContainer.Children.Clear();</p><p
class="cl">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p></div><p></code></p><p>And that's all there is to it.</p><p>Update: download a sample of this <a
href="http://davybrion.com/blog/wp-content/uploads/2009/08/SilverlightHost.zip">here</a>.</p><div
class="bottomcontainerBox" style=""><div
style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <iframe
src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fdavybrion.com%2Fblog%2F2009%2F08%2Fhosting-silverlight-client-apps-in-a-silverlight-host-app%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:85px; height:21px;"></iframe></div><div
style="float:left; width:80px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <g:plusone size="medium" href="http://davybrion.com/blog/2009/08/hosting-silverlight-client-apps-in-a-silverlight-host-app/"></g:plusone></div><div
style="float:left; width:95px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <a
href="http://twitter.com/share" class="twitter-share-button" data-url="http://davybrion.com/blog/2009/08/hosting-silverlight-client-apps-in-a-silverlight-host-app/"  data-text="Hosting Silverlight Client Apps In A Silverlight Host App" data-count="horizontal" data-via="davybrion"></a></div><div
style="float:left; width:105px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script type="in/share" data-url="http://davybrion.com/blog/2009/08/hosting-silverlight-client-apps-in-a-silverlight-host-app/" data-counter="right"></script></div><div
style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script src="http://www.stumbleupon.com/hostedbadge.php?s=1&amp;r=http://davybrion.com/blog/2009/08/hosting-silverlight-client-apps-in-a-silverlight-host-app/"></script></div></div><div
style="clear:both"></div><div
style="padding-bottom:4px;"></div>]]></content:encoded> <wfw:commentRss>http://davybrion.com/blog/2009/08/hosting-silverlight-client-apps-in-a-silverlight-host-app/feed/</wfw:commentRss> <slash:comments>4</slash:comments> </item> <item><title>Silverlight Localization Gotcha</title><link>http://davybrion.com/blog/2009/03/silverlight-localization-gotcha/</link> <comments>http://davybrion.com/blog/2009/03/silverlight-localization-gotcha/#comments</comments> <pubDate>Fri, 27 Mar 2009 13:09:36 +0000</pubDate> <dc:creator>Davy Brion</dc:creator> <category><![CDATA[Silverlight]]></category><guid
isPermaLink="false">http://davybrion.com/blog/?p=1196</guid> <description><![CDATA[Wasted a bit of time figuring this out, so i'm posting it here for future reference. We have this multi-language silverlight app where the UI needs to be shown in either English or Dutch. So you know, i copied my TextResources.resx file (which contains the translated strings in English) and created a TextResources.nl.resx file where [...]]]></description> <content:encoded><![CDATA[<p>Wasted a bit of time figuring this out, so i'm posting it here for future reference.  We have this multi-language silverlight app where the UI needs to be shown in either English or Dutch.  So you know, i copied my TextResources.resx file (which contains the translated strings in English) and created a TextResources.nl.resx file where i replaced the English strings with the Dutch strings.</p><p>In the output folder of the Silverlight project, you can clearly see that the Our.KickAss.Silverlight.Project.resources.dll file is located in the 'nl' folder.  The XAP file that is being copied to the actual web project however, doesn't contain the dutch resources.</p><p>Apparantly, the key to 'fixing' this is opening the .csproj file of your Silverlight project, and then you need to modify the SupportedCultures element so it contains the cultures you're supporting:</p><p><code></p><div
style="font-family: Consolas; font-size: 9pt; color: black; background: white;"><p
style="margin: 0px;"><span
style="color: blue;">&lt;</span><span
style="color: #a31515;">SupportedCultures</span><span
style="color: blue;">&gt;</span>en;nl<span
style="color: blue;">&lt;/</span><span
style="color: #a31515;">SupportedCultures</span><span
style="color: blue;">&gt;</span></p></div><p></code></p><p>There might be a way to do this from the UI within Visual Studio, but i sure didn't find it anywhere.</p><p>And now you can simply switch between the translations setting the generated resource class's static Culture property to the culture you want, for instance:</p><p><code></p><div
style="font-family: Consolas; font-size: 9pt; color: black; background: white;"><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
style="color: #2b91af;">TextResources</span>.Culture = <span
style="color: blue;">new</span> <span
style="color: #2b91af;">CultureInfo</span>(<span
style="color: #a31515;">&quot;nl-BE&quot;</span>);</p></div><p></code></p><div
class="bottomcontainerBox" style=""><div
style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <iframe
src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fdavybrion.com%2Fblog%2F2009%2F03%2Fsilverlight-localization-gotcha%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:85px; height:21px;"></iframe></div><div
style="float:left; width:80px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <g:plusone size="medium" href="http://davybrion.com/blog/2009/03/silverlight-localization-gotcha/"></g:plusone></div><div
style="float:left; width:95px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <a
href="http://twitter.com/share" class="twitter-share-button" data-url="http://davybrion.com/blog/2009/03/silverlight-localization-gotcha/"  data-text="Silverlight Localization Gotcha" data-count="horizontal" data-via="davybrion"></a></div><div
style="float:left; width:105px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script type="in/share" data-url="http://davybrion.com/blog/2009/03/silverlight-localization-gotcha/" data-counter="right"></script></div><div
style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script src="http://www.stumbleupon.com/hostedbadge.php?s=1&amp;r=http://davybrion.com/blog/2009/03/silverlight-localization-gotcha/"></script></div></div><div
style="clear:both"></div><div
style="padding-bottom:4px;"></div>]]></content:encoded> <wfw:commentRss>http://davybrion.com/blog/2009/03/silverlight-localization-gotcha/feed/</wfw:commentRss> <slash:comments>2</slash:comments> </item> <item><title>Cross-Platform .NET Business Applications?</title><link>http://davybrion.com/blog/2009/03/cross-platform-net-business-applications/</link> <comments>http://davybrion.com/blog/2009/03/cross-platform-net-business-applications/#comments</comments> <pubDate>Thu, 19 Mar 2009 07:59:48 +0000</pubDate> <dc:creator>Davy Brion</dc:creator> <category><![CDATA[Silverlight]]></category><guid
isPermaLink="false">http://davybrion.com/blog/?p=1155</guid> <description><![CDATA[Was just going over the new Silverlight 3 features. One thing in particular that i find very interesting: the out-of-browser capabilities: The new out of browser experience in Silverlight 3 enables users to place their favorite Silverlight applications directly onto their PC and Mac, with links on the desktop and start menu—all without the need [...]]]></description> <content:encoded><![CDATA[<p>Was just going over the new <a
href="http://silverlight.net/getstarted/silverlight3/default.aspx">Silverlight 3 features</a>.  One thing in particular that i find very interesting: the out-of-browser capabilities:</p><blockquote> The new out of browser experience in Silverlight 3 enables users to place their favorite Silverlight applications directly onto their PC and Mac, with links on the desktop and start menu—all without the need to download an additional runtime or browser plug-in.</blockquote><p>So we can create .NET applications that run on the Mac now <img
src='http://d18sni7re4ly7f.cloudfront.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p><p>Sure, they'll be sandboxed and you can't do everything a real native application could do, but this could still be a pretty compelling deployment choice.</p><div
class="bottomcontainerBox" style=""><div
style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <iframe
src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fdavybrion.com%2Fblog%2F2009%2F03%2Fcross-platform-net-business-applications%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:85px; height:21px;"></iframe></div><div
style="float:left; width:80px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <g:plusone size="medium" href="http://davybrion.com/blog/2009/03/cross-platform-net-business-applications/"></g:plusone></div><div
style="float:left; width:95px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <a
href="http://twitter.com/share" class="twitter-share-button" data-url="http://davybrion.com/blog/2009/03/cross-platform-net-business-applications/"  data-text="Cross-Platform .NET Business Applications?" data-count="horizontal" data-via="davybrion"></a></div><div
style="float:left; width:105px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script type="in/share" data-url="http://davybrion.com/blog/2009/03/cross-platform-net-business-applications/" data-counter="right"></script></div><div
style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script src="http://www.stumbleupon.com/hostedbadge.php?s=1&amp;r=http://davybrion.com/blog/2009/03/cross-platform-net-business-applications/"></script></div></div><div
style="clear:both"></div><div
style="padding-bottom:4px;"></div>]]></content:encoded> <wfw:commentRss>http://davybrion.com/blog/2009/03/cross-platform-net-business-applications/feed/</wfw:commentRss> <slash:comments>10</slash:comments> </item> <item><title>Silverlight&#8217;s ProgressBar And Possible Memory Leaks</title><link>http://davybrion.com/blog/2009/02/silverlights-progressbar-and-possible-memory-leaks/</link> <comments>http://davybrion.com/blog/2009/02/silverlights-progressbar-and-possible-memory-leaks/#comments</comments> <pubDate>Wed, 25 Feb 2009 15:42:44 +0000</pubDate> <dc:creator>Davy Brion</dc:creator> <category><![CDATA[Memory Management]]></category> <category><![CDATA[Silverlight]]></category><guid
isPermaLink="false">http://davybrion.com/blog/?p=1012</guid> <description><![CDATA[This has got to be the weirdest memory leak i've ever investigated. We have this kick-ass Silverlight application, but unfortunately it suffered from very high memory usage that went up rather rapidly. So i attached windbg to the browser's process, took a memory dump and checked out which objects were still available in the heap. [...]]]></description> <content:encoded><![CDATA[<p>This has got to be the weirdest memory leak i've ever investigated.  We have this kick-ass Silverlight application, but unfortunately it suffered from very high memory usage that went up rather rapidly.  So i attached windbg to the browser's process, took a memory dump and checked out which objects were still available in the heap.  Much to my surprise, pretty much everything we instantiated was retained in memory and never got removed from the heap.</p><p>So i started looking into the usual things: making sure disposable instances where disposed of properly, that evenhandlers were unregistered properly, etc.  I went over the code and it seemed to be alright.  Stepping through the code with a debugger verified that disposables were indeed disposed of, and that all event handlers were unregistered.</p><p>So why was pretty much everything kept in memory?  Further research with windbg showed that every ProgressBar instance that was ever created (and we use a lot of them, basically every time we make a call to the application server) kept a reference to the UserControl it was placed on and thus, kept the UserControl and all the references it contained alive.  In our case, that includes our presentation models and obviously all of the contained child UserControls.</p><p>The ProgressBar is defined like this:</p><div><pre class="brush: xml; title: ; notranslate">
&lt;ProgressBar Height=&quot;40&quot; Style=&quot;{StaticResource ourKickAssStyle}&quot; VerticalAlignment=&quot;Center&quot; Width=&quot;40&quot; IsIndeterminate=&quot;True&quot;/&gt;
</pre></div><p>The key here is the usage of the IsIndeterminate property... setting this to true causes the ProgressBar to move continuously without respecting any current Value property.  You know, basic stuff.  The thing is... if i change the definition of the ProgressBar to this:</p><div><pre class="brush: xml; title: ; notranslate">
&lt;ProgressBar Height=&quot;40&quot; Style=&quot;{StaticResource ourKickAssStyle}&quot; VerticalAlignment=&quot;Center&quot; Width=&quot;40&quot; /&gt;
</pre></div><p>The memory leak suddenly went away <img
src='http://d18sni7re4ly7f.cloudfront.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p><p>Obviously, this isn't a solution because the ProgressBar now doesn't really indicate any progress and we need our kick ass custom animation to retain the coolness of the application.</p><p>So for some reason, when you set the ProgressBar's IsIndeterminate property to true, it actually keeps all of its references alive even when the ProgressBar control is removed from its parent control.  Happy times.</p><p>We now have the following ugly method in one of our base UI classes:</p><div><pre class="brush: csharp; title: ; notranslate">
        private static void StopProgressBars(DependencyObject dependencyObject)
        {
            var count = VisualTreeHelper.GetChildrenCount(dependencyObject);
 
            for (int i = 0; i &lt; count; i++)
            {
                var child = VisualTreeHelper.GetChild(dependencyObject, i);
                if (child != null)
                {
                    var progressBar = child as ProgressBar;
 
                    if (progressBar != null)
                    {
                        progressBar.IsIndeterminate = false;
                    }
 
                    StopProgressBars(child);
                }
            }
        }
</pre></div><div
class="bottomcontainerBox" style=""><div
style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <iframe
src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fdavybrion.com%2Fblog%2F2009%2F02%2Fsilverlights-progressbar-and-possible-memory-leaks%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:85px; height:21px;"></iframe></div><div
style="float:left; width:80px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <g:plusone size="medium" href="http://davybrion.com/blog/2009/02/silverlights-progressbar-and-possible-memory-leaks/"></g:plusone></div><div
style="float:left; width:95px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <a
href="http://twitter.com/share" class="twitter-share-button" data-url="http://davybrion.com/blog/2009/02/silverlights-progressbar-and-possible-memory-leaks/"  data-text="Silverlight&#8217;s ProgressBar And Possible Memory Leaks" data-count="horizontal" data-via="davybrion"></a></div><div
style="float:left; width:105px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script type="in/share" data-url="http://davybrion.com/blog/2009/02/silverlights-progressbar-and-possible-memory-leaks/" data-counter="right"></script></div><div
style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script src="http://www.stumbleupon.com/hostedbadge.php?s=1&amp;r=http://davybrion.com/blog/2009/02/silverlights-progressbar-and-possible-memory-leaks/"></script></div></div><div
style="clear:both"></div><div
style="padding-bottom:4px;"></div>]]></content:encoded> <wfw:commentRss>http://davybrion.com/blog/2009/02/silverlights-progressbar-and-possible-memory-leaks/feed/</wfw:commentRss> <slash:comments>6</slash:comments> </item> <item><title>Excellent Tool For Silverlight Developers</title><link>http://davybrion.com/blog/2009/02/excellent-tool-for-silverlight-developers/</link> <comments>http://davybrion.com/blog/2009/02/excellent-tool-for-silverlight-developers/#comments</comments> <pubDate>Tue, 24 Feb 2009 07:15:49 +0000</pubDate> <dc:creator>Davy Brion</dc:creator> <category><![CDATA[Silverlight]]></category><guid
isPermaLink="false">http://davybrion.com/blog/?p=1003</guid> <description><![CDATA[A coworker of mine pointed this out... if you're doing Silverlight development, make sure you install Silverlight Spy!]]></description> <content:encoded><![CDATA[<p>A coworker of mine pointed this out... if you're doing Silverlight development, make sure you install <a
href="http://firstfloorsoftware.com/silverlightspy/">Silverlight Spy</a>!</p><div
class="bottomcontainerBox" style=""><div
style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <iframe
src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fdavybrion.com%2Fblog%2F2009%2F02%2Fexcellent-tool-for-silverlight-developers%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:85px; height:21px;"></iframe></div><div
style="float:left; width:80px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <g:plusone size="medium" href="http://davybrion.com/blog/2009/02/excellent-tool-for-silverlight-developers/"></g:plusone></div><div
style="float:left; width:95px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <a
href="http://twitter.com/share" class="twitter-share-button" data-url="http://davybrion.com/blog/2009/02/excellent-tool-for-silverlight-developers/"  data-text="Excellent Tool For Silverlight Developers" data-count="horizontal" data-via="davybrion"></a></div><div
style="float:left; width:105px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script type="in/share" data-url="http://davybrion.com/blog/2009/02/excellent-tool-for-silverlight-developers/" data-counter="right"></script></div><div
style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script src="http://www.stumbleupon.com/hostedbadge.php?s=1&amp;r=http://davybrion.com/blog/2009/02/excellent-tool-for-silverlight-developers/"></script></div></div><div
style="clear:both"></div><div
style="padding-bottom:4px;"></div>]]></content:encoded> <wfw:commentRss>http://davybrion.com/blog/2009/02/excellent-tool-for-silverlight-developers/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Poll: What Will Silverlight&#8217;s Future Look Like?</title><link>http://davybrion.com/blog/2009/02/poll-what-will-silverlights-future-look-like/</link> <comments>http://davybrion.com/blog/2009/02/poll-what-will-silverlights-future-look-like/#comments</comments> <pubDate>Sun, 08 Feb 2009 09:59:03 +0000</pubDate> <dc:creator>Davy Brion</dc:creator> <category><![CDATA[Silverlight]]></category><guid
isPermaLink="false">http://davybrion.com/blog/?p=942</guid> <description><![CDATA[I'm currently working on a project at work where we're using Silverlight for the UI. I wasn't a big fan of Silverlight before i started working with it, but you can consider me converted from now on. It truly is a compelling development platform, and i believe it will be the best choice for a [...]]]></description> <content:encoded><![CDATA[<p>I'm currently working on a project at work where we're using Silverlight for the UI.  I wasn't a big fan of Silverlight before i started working with it, but you can consider me converted from now on.  It truly is a compelling development platform, and i believe it will be the best choice for a lot of web applications (note that i'm not saying it would be the best choice for all web applications) for the next couple of years.</p><p>But it appears that the people who feel this way about Silverlight's future are in the minority.  You don't see a lot of the really big name .NET bloggers talking about Silverlight (although there are a few), though i'm hoping that will change over time.  In the meantime, i'd like to know what you think Silverlight's future will look like.  I've put up a new poll with the following possible answers:</p><ul><li>It's never going to take off in a meaningful way</li><li>It might pick up some steam for media-related purposes, but that's about it</li><li>It will pick up more adopters as the platform matures and offers more out-of-the-box capabilities for typical business applications</li><li>It's too different from traditional web development to appeal to most web developers</li><li>It will reach wide adoption, but never more than that of typical web apps</li><li>Someday it will be the default development platform for .NET web developers</li></ul><p>(NOTE: for those of you reading this through the RSS feed, the poll is only accessible on my site and is located at the top right corner of the page)</p><p>There will obviously be some missing options, so feel free to point them out in the comments. I'm looking forward to the results and your thoughts on this topic <img
src='http://d18sni7re4ly7f.cloudfront.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p><div
class="bottomcontainerBox" style=""><div
style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <iframe
src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fdavybrion.com%2Fblog%2F2009%2F02%2Fpoll-what-will-silverlights-future-look-like%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:85px; height:21px;"></iframe></div><div
style="float:left; width:80px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <g:plusone size="medium" href="http://davybrion.com/blog/2009/02/poll-what-will-silverlights-future-look-like/"></g:plusone></div><div
style="float:left; width:95px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <a
href="http://twitter.com/share" class="twitter-share-button" data-url="http://davybrion.com/blog/2009/02/poll-what-will-silverlights-future-look-like/"  data-text="Poll: What Will Silverlight&#8217;s Future Look Like?" data-count="horizontal" data-via="davybrion"></a></div><div
style="float:left; width:105px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script type="in/share" data-url="http://davybrion.com/blog/2009/02/poll-what-will-silverlights-future-look-like/" data-counter="right"></script></div><div
style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script src="http://www.stumbleupon.com/hostedbadge.php?s=1&amp;r=http://davybrion.com/blog/2009/02/poll-what-will-silverlights-future-look-like/"></script></div></div><div
style="clear:both"></div><div
style="padding-bottom:4px;"></div>]]></content:encoded> <wfw:commentRss>http://davybrion.com/blog/2009/02/poll-what-will-silverlights-future-look-like/feed/</wfw:commentRss> <slash:comments>15</slash:comments> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced
Database Caching 2/85 queries in 0.053 seconds using disk: basic
Object Caching 1536/1715 objects using disk: basic
Content Delivery Network via Amazon Web Services: CloudFront: d18sni7re4ly7f.cloudfront.net

Served from: davybrion.com @ 2012-05-23 14:21:07 -->
