As you may have heard, Silverlight 2 beta 2 came out. This post for me is necessary because I wrote a two part series on getting a Silverlight application to work in SharePoint, and since beta 2 came out, a few things need to be updated in that walkthrough of mine. Before I get started, MSDN has a nice article on all the main things that changed that could cause your applications to break – it's a laundry list so prepare for a heavy read.
Here's my laundry list of updates to my steps:
STEP 1: You need to install the beta 2 extensions for visual studio, not beta 1 as I mentioned in Step 1. After you install it, just load your beta 1 project and it will prompt you to upgrade it. After it is upgraded, rebuild and redeploy the XAP file and now your application is beta 2. But there's a few more things to note…
STEP 4: If you installed your Silverlight application like how I did, you just inputted the necessary HTML into a content editor web part. That HTML needs to be updated. The red highlighted text notes the updates from what was noted in step 4 of my 10 steps:
<div id="container">
<div id="header">
<div id='errorLocation' style="font-size: small;color: Gray;"></div>
<div id="silverlightControlHost">
<object data="data:application/x-silverlight," type="application/x-silverlight-2-b2" width="100%" height="200px">
<param name="source" value="/clientbin/SilverlightApplication1.xap"/>
<param name="onerror" value="onSilverlightError" />
<param name="background" value="white" />
<a href="http://go.microsoft.com/fwlink/?LinkID=115261" style="text-decoration: none;">
<img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style: none"/>
</a>
</object>
<iframe style='visibility:hidden;height:0;width:0;border:0px'></iframe>
</div>
STEP 9: Lastly, the error handling code also needs to be updated to be as follows:
<script type="text/javascript">
function onSilverlightError(sender, args) {
var appSource = "";
if (sender != null && sender != 0) {
appSource = sender.getHost().Source;
}
var errorType = args.ErrorType;
var iErrorCode = args.ErrorCode;
var errMsg = "Unhandled Error in Silverlight 2 Application " + appSource + "\n" ;
errMsg += "Code: "+ iErrorCode + " \n";
errMsg += "Category: " + errorType + " \n";
errMsg += "Message: " + args.ErrorMessage + " \n";
if (errorType == "ParserError")
{
errMsg += "File: " + args.xamlFile + " \n";
errMsg += "Line: " + args.lineNumber + " \n";
errMsg += "Position: " + args.charPosition + " \n";
}
else if (errorType == "RuntimeError")
{
if (args.lineNumber != 0)
{
errMsg += "Line: " + args.lineNumber + " \n";
errMsg += "Position: " + args.charPosition + " \n";
}
errMsg += "MethodName: " + args.methodName + " \n";
}
throw new Error(errMsg);
}
</script>
That's all that needs to be updated to get our simple little Silverlight application to work. As I mentioned in the beginning, there are a lot of other things that changed, but our app is just a Hello World app, most of it isn't relevant to us.
Good luck!
Phil