Tag Archives: Silverlight

Silverlight 2.0 provides better remote debugging experience

Some months ago, I did some remote debugging of a Silverlight app on a Mac. To say the least, it wasn’t all that intuitive, and it required a lot of trying and guessing to achieve the desired goal. Personally I think remote debugging is cool, but I can’t really see the great need of it. Silverlight is cross-browser, cross-platform compatible – so when it works in a browser on Windows, shouldn’t it work on a Mac as well?

The release of Silverlight 2.0 has some great news in respect to remote debugging. It is no longer necessary to edit config files, and so on to authenticate the remote debugging session. This is all done from a nice user interface. JrzyShr Dev Guy has a excellent blog post describing the process of setting up remote debugging on a Mac on Silverlight 2.0. Furthermore, he suggests I mark my post as obsolete:

I ended up relying on a couple of random blog posts I came across on Live Search & Google to figure it out.  If your search turns up any of these links, know that they are now obsolete:

Old 1.1 Alpha Way of Doing Things:
http://www.martinnormark.com/post/Windows-Vista-Mac-debugging-a-Silverlight-app-using-Visual-Studio-2008.aspx

So that I’ll do. Confusing information is all over the place, and I’d rather point someone in the right direction.

Windows Vista / Mac debugging a Silverlight app using Visual Studio 2008

[obsolete]
As I wrote here, this is no longer the way to do it as Silverlight 2.0 provides a much better experience.

As I wrote recently in another blog post about a .NET Rocks interview with Brad Abrams, I was very impressed with his keynote at ReMix Boston, where he did the Linux / Vista / Mac debugging. I referred to Richard Campbell‘s opinion that he didn’t believe it would work. At the end of the post, I wrote that I want to try it for myself, to see if it really works. Brad Abrams posted a comment to my blog post, saying that it should work just fine. Well. This post tells the story.

Prerequisites

  • A Windows machine with Visual Studio 2008 and Silverlight Tools Alpha for Visual Studio 2008 installed.
  • A Macintosh with the Silverlight 1.1 Alpha installed.
  • A network connection on both machines and a way to transfer files between the Vista box and the Mac. (A USB flash drive/stick is fine)
  • A Silverlight 1.1 Alpha project linked to a website, ready to run.
  • The website has to be remotely accessible. (Otherwise you can copy the website to the Mac as static HTML files, and run it locally from there.)

Debugging environment

This is the environment I will use for the debugging. For starters, I want to concentrate on the Vista / Mac debugging, so I won’t set up a Linux box with Apache and serve the Silverlight app on a PHP page. But there really should be no problem to it. You can even copy a static HTML page with the XAML page, and the assemblies to the Mac, and run the Silverlight app locally, and attach the Visual Studio debugger to the Safari process on the Mac. Let’s save the Linux box for another time.

The mac: Basically just a Macbook with default configurations, and no special software.

The Vista box: This is my development box. Windows Vista with Visual Studio 2008, IIS 7 and an ASP.NET website set up at localhost.

Before we get started, locate your Visual Studio 2008 folder on the Vista box (usually: C:\Program Files\Microsoft Visual Studio 9.0), and find the Silverlight folder. This folder contains the necessary files to do the initial set-up. You’ll also find a guide to set-up and start debugging, but I’ve found a few mistakes in there, and you can find yourself confused.

Setting up the Mac for Silverlight debugging

Remote debugging is not as easy as pointing Visual Studio to a remote computer, and selecting a process to debug. You have to authenticate against the remote machine. This is done via an SSL encrypted TCP channel between the debugger (The Vista box) and the target machine (The Mac). You will need to set-up the TCP port along with a private/public key pair. This is done in 6 easy steps:

  1. Copy the contents of the C:\Program Files\Microsoft Visual Studio 9.0\Silverlight\MacIntel folder to a destination on the Mac of your choosing.
  2. Start up a Terminal on the Mac, and execute the ‘configcoreclrdebug’ using an absolute filepath. e.g.: /MacIntel/configcoreclrdebug.
  3. First, your private/public key pair will be generated, and then you have to specify a TCP port in the range of 49152 – 65535. Just pick a number.
  4. Then you need to enter a password, and confirm it. Choose a password of at least 8 characters.
  5. A hidden directory is created in your Users folder, located here: /Users/username/.coreclrdbg – copy the “ConfigureWindowsCoreCLRDebugging.exe” file to the Vista box, in a destination of your choosing.
  6. Execute the ‘core_clr_proxy’ file on the Mac from the Terminal, using an absolute filepath like this: /MacIntel/coreclr_dbg_proxy

image image

That was all the set-up needed on the Mac for now. Next up is setting up the Vista box.

Setting up the Vista machine for Silverlight debugging

This is the easy part.

  1. From a command prompt, run the “ConfigureWindowsCoreCLRDebugging.exe” which you just copied from the Mac.
  2. Enter the password you created on the Mac in step 4, and hit Enter.

Starting the debugger

Now to the exciting part. Will it work, or not?

  1. Launch Safari on the Mac, and point the address to the URL of your Silverlight application you wish to debug.
  2. Launch Visual Studio 2008 on the Vista box, and open the Silverlight project that you wish to debug.
  3. Open up a source file, and set a breakpoint.
  4. From the Debug menu, click Attach to Process. (Or hit Ctrl + Alt + P)
  5. From the Transport drop down menu, select ‘CoreCLR Remote Cross-platform Debugging’.
  6. Enter the IP address or hostname of the Mac in the Qualifier box bellow and hit Enter.
  7. Now you should see a list of processes running on the Mac. Anyone that has CoreCLR Remote in the Type column can be attached.
  8. Select the Safari process and hit Attach.
  9. There you go. You’ve just attached the Safari process on the Mac to the Visual Studio debugger.

image image image

Now. Perform whatever action on the Mac that makes you hit the breakpoint you set before, and take a moment to enjoy real-time cross-platform remote debugging.

Screenshots of the Mac showing the webpage with the Silverlight app:

image image

The second picture above, has the SetDefaultView() Button highlighted as if I was holding down the mouse bottom. This is because the screenshot is taken when I hit the breakpoint you can see on the third picture of Visual Studio further above.

One thing I noticed while using the Silverlight charts from the Mac, was the speed. When I paste the serialized string in to the textbox and click LoadData() – the Silverlight loads the string and deserializes it to some custom classes I made. On Vista it takes less than a second. On the Mac it takes about two seconds or maybe a bit more. And it is not because of network latency. Silverlight runs in the browser, which means the app is downloaded to the Mac, and when I click the buttons, all the logic handling events and doing stuff runs locally. So Silverlight is lot slower on the Mac than on Windows. Maybe this will get better when Silverlight 1.1 is officially released.

kick it on DotNetKicks.com

Recommended listening: .NET Rocks with Brad Abrams

If you haven't heard .NET Rocks before, now is a good time to do it. In their last show, they interviewed Brad Abrams during Remix Boston where he did a keynote. So who is Brad Abrams.

Quote from his own blog:

Brad Abrams was a founding member of both the Common Language Runtime, and .NET Framework teams at Microsoft Corporation where he is currently the Group Program Manager for the UI Framework and Services team which is responsible for delivering the developer platform that spans both clients and web based applications as well as the common services that are available to all applications. Specific technologies owned by this team include ASP.NET and ASP.NET AJAX, parts of Silverlight, and Windows Forms.

In the interview, they talk a lot about Silverlight, what they are trying to do and how open the technology actually is. And they talk a lot about that openness Microsoft has recently approached, and how the Silverlight technology could be adapted by a developer of any of the three major platforms. (Windows, Mac & Linux). I really like that approach, and the result is clear. Already – even though Silverlight just hit the 1.0 RTM recently, there's a huge amount of applications running live from notable companies.

They also talk a lot about Brad Abrams' keynote at Remix Boston, where he did a demo on debugging a Silverlight 1.1 app.

And he didn't do it the easy way! He had a Linux box with a small PHP page, hosting the Silverlight 1.1 app. That worked great. The he fired up a Mac, and hit that page from Safari. And to achieve the debugging experience of Visual Studio, he attached the VS debugger to the Safari process on the Mac, set a breakpoint in the code, and refreshed the page on the Mac, to hit the breakpoint. And there you go. A Mac hitting a breakpoint on a Vista box, and the website being hosted on a Linux box – how cool is that?

During the show Richard Campbell said that he didn't believe it would work. I don't know – but I want to try the same thing, and se if it really works.

Technorati Tags: , ,

Silverlight 1.0 officially released

slpenguin-thumb This morning, I just read over at Scott Hanselmans blog, that Silverlight 1.0 was released and it support Linux. So that means Silverlight support all major platforms now, and it is out in the open so your apps can get going. To get some inspiration, you can have a look at these Silverlight apps that Scott posted on his blog: (posted from ScottGu’s blog)

Quote Scott Hanselman

  • Recreating ITunes in Silverlight: Jose Fajardo has an absolutely fantastic blog with a ton of Silverlight content on it.  One of the projects he has been working on has been recreating Apple’s ITunes Media Player using Silverlight.  Check out his multi-part blog series that discusses step-by-step how he built it.  Absolutely brilliant.

  • Sudoku for Silverlight: David Anson has built a cool online sample using Silverlight that helps you play the popular Sudoku game.  Useful for both Sudoku addicts and developers wanting to learn Silverlight.  

  • Font Embedding and RSS data in Silverlight: Tim Heuer has a cool blog post that shows how you can create your own font-type and embed it within your Silverlight 1.0 application.  He then has his application retrieve dynamic content from an RSS feed and use the custom font to display it.  You can run the finished application online here (all of the text here is dynamic – not a screen-shot).

  • Silverlight Drag and Drop JavaScript Framework: Roberto Hernandez-Pou has a nice article and sample that describes how to implement a drag/drop mechanism for Silverlight 1.0 (using JavaScript).  This article is in both Spanish and English – scroll down if you are looking for the English version.

  • Pascal Support for Silverlight: RemObjects Software now has a project template for VS 2008 that enables you to write Silverlight 1.1 .NET applications using Pascal.  It is kinda wild to see a screenshot of FireFox on the Mac, running a Silverlight application, written with a Pascal code-behind file built with VS 2008.

 Also, have a look at the official Silverlight community website, where you’ll frind quickstarts, forums and recent blogposts from leading Silverlight developers and Microsoft people.

Technorati Tags:

Web services and Silverlight 1.1 C# gotchas

As anyone must know by now, Silverlight is Microsoft's cross-browser, cross-platform RIA (Rich Internet Application) technology – like Adobe's Flash. With Silverlight, they say the sky is the limit, and it's only up to yourself what to invent. Silverlight offers you a big chunck of the .NET CLR in the browser, when using Silverlight 1.1 Alpha (Refresh). As always, there are do's and don'ts when you work with new technology and in this not-known-yet-part series, I'm going to recap my experience using Silverlight 1.1 Alpha and later Silverlight 1.1 Alpha Refresh to develop some sophisticated charting components.

Before you begin – general info

For the current release of Silverlight (Silverlight 1.1 Alpha Refresh) you don't have the System.Data namespace (that means no DataSets nor DataTables). Also the System.Xml namespace is very small, you don't get the XmlDocument which would have been useful. I haven't heard anything reliable about whether or not those namespaces and classes will make it into the final release of Silverlight, but it doesn't seem like it.

Maybe 3rd party components will come to help here, but that's a drawback because then the users have to install something new on their machines to be able to use your app.

Mark your webservice as a ScriptService

If you're going to use any kind of data in your Silverlight apps, and you probably are, then you have to use a webservice. Calling a webservice from Silverlight is a bit different from calling a webservice from another ASP.NET page.

First of all, you have to mark your webservice as Scriptable. The Scriptable attribute excists in the System.Web.Script.Services namespace, and is part of the ASP.NET AJAX framework (also included in the .NET Framework 3.5). If you are developing on ASP.NET 2.0, you have to make sure you have ASP.NET AJAX installed on the server, and reference the correct assemblies in your ASP.NET 2.0 application.

This is how your class definition will look like:

[WebService(Namespace = http://tempuri.org/)]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
public class SilverchartDataService : System.Web.Services.WebService{
} 


Now your webservice can be called from Silverlight – and also JavaScript / AJAX.

Don't call a webservice on another domain

The security model of Silverlight, and also other client-side technologies, deny calling a webservice on another domain. That is also called cross-domain webservice calls, and if you do, you will get this exception when #debugging your Silverlight app using Visual Studio 2008:

image

I've seen ways to get around this problem, but it is beyond the purpose of this blog post. If you need info on this topic, try this: Using a proxy to access remote APIs (The article is for AJAX – should work for Silverlight)

JSON Serialization compatibillity with .NET

Whenever you use a webservice, all the objects transfered gets serialized. (Remember to mark your own classes as Serializable if you want to use them in your webservice.) And Silverlight uses the JSON Serialization 'engine'. This can result in some nasty errors, yet difficult to debug. I've found out, that some .NET classes cannot be used – these include:

  • decimal
  • enum (So don't use enum's with Silverlight – at least not until it is supported)

And there are probably more than those two…

Technorati Tags: , , ,