# Tuesday, August 28, 2007

I imagine that most developers when presented with the concept of Silverlight have a very joyous first response. And then the next thought is a pragmatic one of wondering how much code (source or binaries) can be shared between Orcas and Silverlight. In the past, I've come across some pretty interesting uses of ASP.NET to share experiences across both the server and the offline client. Today, I'm pretty sure that we can offer a better scenario than that.

Before we go into details, let's talk scenarios. My dream scenario is that TurboTax would move their web-based version to Silverlight, and their client version to full WPF. For the Silverlight version, I'm thinking of a pretty immersive application, along the lines of the nibbles tutorial or the new Tafiti search app. I can easily see a major improvement in customer experience, including for me, a multi-year TurboTax customer.

The question on the table is the degree to which Turbotax developers (for my dream scenario) could share code across those two presentations of Silverlight. There are two parts of that: the UI layer (WPF code, xaml and other assets), and then the business logic. Although possibly the most interesting topic, I won't address the UI at this point since the WPF and Jolt teams are still working out the kinks on that issue. The business logic aspect of the issue is well within the purview of what I've been working on.

Our goal for business logic has been pretty simple: subset the existing Orcas stack for the BCL, XML and other base technologies in a very, very compatible way. We want folks to be able to take their Silverlight business logic, and re-use it on the desktop. For Turbotax, you could imagine them being able to port all the code that calculates your taxes against the static IRS tax tables to Orcas. At this point, we're focussed on making source re-use work really well. Binary porting is definitely something that's on our list, but not what we consider to be the mainline scenario since you'll need to re-compile your UI code anyway. I'd like your feedback on it if you have a differing opinion.

You might notice that I'm talking about porting code from Silverlight *to* Orcas. The reverse direction isn't nearly as compelling. By definition, Silverlight will always be a subset of Orcas, and your Orcas code may have a lot of dependencies on types that are only part of Orcas. Starting from Silverlight, you know that all of the APIs that you use will also be on Orcas, and you're experience porting to Orcas will be straightforward.

One kink is that we've added APIs to Silverlight that are not in Orcas. So, my story as described above is actually a little flawed. Naturally, we'll add those to the next desktop release after Orcas, but there is a question of how to deal with that in the meantime. We do have a solution for that that we're working on. I'll post on that when I have firm details available.

Tuesday, August 28, 2007 6:00:00 AM (GMT Daylight Time, UTC+01:00)  #    Disclaimer  |  Comments [0]  | 

Judging by the search engine traffic to my blog, it appears like folks are still looking for gacutil!

I wrote this post almost 2 years ago, relating to Whidbey, and the location of gacutil at that time.

Gacutil, and the rest of the SDK, has moved again. You can install it with VS 2008 or separately. In either case, once installed, you'll find it on your disk @ C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\gacutil.exe.

BTW: The .NET Framework SDK now has a new name, so searching for the .NET Framework SDK doesn't work as well now. It is now called "Microsoft® Windows® Software Development Kit (SDK) for Windows Server® 2008 and .NET Framework 3.5".

Tuesday, August 28, 2007 5:45:21 AM (GMT Daylight Time, UTC+01:00)  #    Disclaimer  |  Comments [5]  | 
# Wednesday, August 15, 2007

I've been using Terminal Services (AKA 'Remote Desktop') since I started working at Microsoft in 2000. Back then, we were using Windows 2000, natually. After having used the 9x family of Windows since Win 3.1 (and DOS before that), the whole concept of 'TS' seemed pretty incredible. Yes, I'd used similar facilities on other OSes, such as Solaris, but never on Windows.

Windows Server 2008 brings along with it another similar and related breakthrough. It's called RemoteApp. Instead of remoting a whole desktop, it remotes an application. The initial logon process is very similar to Remote Desktop, but after that, you really do have a window that operates just like any other window on your desktop. There are some aspects of 'remote-ness' that leak through, but they are far, far, overpowered by the utility of the feature. Also, you don't need to logon for each window, just once for the machine from which the RemoteApps are remoted.

I've been dogfooding this feature for a while, and I find it incredibly useful and productive when working from home (which I do a fair bit -- like right now). Imagine having a RemoteApp IE window on your desktop that is on your corporate network. You have your regular IE on your desktop that you use to view random web content, and the RemoteApp IE that you use to browse your corporate network. This is super useful for sharepoint sites on your corporate network.

Next step is to convince (A) your CFO to buy a bunch of Windows Server 2008 boxen, and (B) get your admins to turn on this feature.

Wednesday, August 15, 2007 6:08:45 AM (GMT Daylight Time, UTC+01:00)  #    Disclaimer  |  Comments [0]  | 
# Thursday, August 09, 2007

The comments on yesterday's post on compatibility are pretty interesting.

There are effectively four options available when you find yourself a few versions into a platform and realize that you've made mistakes:

  1. Keep the mistakes, and potentially propogate those mistakes into other parts of the platform
  2. Rip out the mistakes, re-design the feature (sans mistakes) and accept the breaking change and broken apps
  3. Re-design the feature without the mistakes, add that re-designed feature to the product, deprecate the old broken feature, and accept duplication for some period of time until the older feature is ripped from the product
  4. Re-design the feature, add some elaborate compatibility mechanism to emulate the old behaviour, and sign up to maintain the elaborate compatibility mechanism for a long time

There may be some other options, but these are the ones that come to mind.

The comments from yesterday were in favour of (2).

I'm in favour of (3) as the primary model for making the product better, with a little bit of (2). I'm also willing to accept some of (1). I really dislike (4), as it doesn't benefit anyone in the long-term. (3) works well for individual APIs, but doesn't work well for whole sub-systems, such as the loader. If you change the loader in an incompatible way, you're really looking at options (2) or (4).

We've actually made a bunch of changes in Silverlight to improve the platform. As examples, we've removed non-generic collections, and have changed the way String comparisons work. We also changed the binder pretty significantly. Not to mention a new security system ... Oh, and we also included a stripped down XMLReader/Writer!

Compatibility is a tough balance relative to product evolution. We've been discussing this exact issue a lot over the last year, and the best way to evolve the project forward. The trick is coming up with a model that you really life, doesn't hugely impact the engineering process, doesn't inhibit product evolution going forward, and is explainable to customers. Taking submissions now ...

Thursday, August 09, 2007 6:45:33 AM (GMT Daylight Time, UTC+01:00)  #    Disclaimer  |  Comments [0]  | 
# Wednesday, August 08, 2007

I was just reading an Old New Thing blog entry about compatibility. I get the point that Raymond is making about compatibility. It reminds me of a lot of conversations that we have in building 42.

I talk to folks with the same proposal of pulling out the 'compat crap' to make the product better. I have two thoughts on that:

  • We'll be having this same conversation one release from now when we've implemented and shipped another set of designs that you don't like, when looked at in hind-sight
  • There are a ton of folks that have invested a ton of time and their livelihood into the apps that they've bet on our platform. What do you want me to tell them?

Compatibility is feature number 1. Without it, you don't have a product, at least for very long.

Wednesday, August 08, 2007 7:16:31 AM (GMT Daylight Time, UTC+01:00)  #    Disclaimer  |  Comments [3]  | 

I noticed that my last posts were about Vista 2005 SP1 on Vista. I had a bunch of trouble with that experience. I'm sure that the rough edges were polished out later on, but my initial experience could have been better.

I've been running Visual Studio 2008 (AKA 'Orcas') B1 and now B2 on Vista SP1 builds to write Silverlight v1.1 apps. I've got to say that the experience has been great. A bunch of work has been done to support UAC (the fundamental issue) by the VS and .NET Framework teams, and this on its own will be worth a big part of the price of admission.

I've also been building/debugging DasBlog (the blog software used to run this site) in VS 2008 B2 on Vista SP1 with IIS7. IIS7 is a pretty big change. After a few tweaks, help from the ASP.NET/IIS team and a bunch of help from the DasBlog team, I got it working. See Scott's post and post for more info.

There was only one problem in VS 2008 B2 w/IIS7 integration. That issue will be fixed in the next public release.

All in all, it's great to see a quality product, one that I'll be using a lot, coming from the VS team.

Wednesday, August 08, 2007 6:03:17 AM (GMT Daylight Time, UTC+01:00)  #    Disclaimer  |  Comments [0]  | 

I've been working on various aspects of Silverlight since sometime last year. The project has been going on much longer than that. It took a while for the managed API to come online and then even longer for good tools support, and all of this is before the product was announced. And all that time, you'd think that folks close to the product were generating a ton of samples and cool apps. Well, not really. There were some, but most folks (including me) were just cranking on getting the thing ready for Mix and then the refresh/RC that followed.

So, I'm now happily playing with the product. I'm in the middle of creating a photo gallery website for myself to replace the lame DHTML site that I wrote back in 2003 on ASP.NET v1.1.

I'm left with some random thoughts on the product and how it affects and empowers developers:

  • Compatibility between the server, the web-client (Silverlight) and the client (WPF/Winforms) is incredibly important
    • At the very least, developers benefit from knowledge transfer across the platform
    • Compatibility makes life easier for developers
    • More importantly, it opens up a ton of interesting scenarios between the different parts of the platform
  • A highly flexible and easy to target ActiveX control is liberating
    • I've written a bunch of javascript to improve user experience in the browser. I'd be happy to never do that again, given that the development experience is pretty bad.
    • You can create amazing visuals and immersize experiences that would never be possible with Javascript.
  • Silverlight also opens up a lot of questions for its use in the browser
    • Do you use Silverlight for your entire site, or only the parts that make sense?
    • What do you about navigation, particularly as it relates to forward and back buttons?
    • What do you do about folks that what a URL for a specific part of your site to send around, or return to later (bookmark)?
    • Flash has been around for a while, and has all of these same problems. Some sites use Flash for ads, others for widgets and still others that do the whole site thing. I've always disliked the whole site thing as a user.
  • Silverlight has an opportunity to hugely improve on the current Web experience
    • Most importantly, we've just let lose all those managed developers out on that ;)
    • This is the start of real internet applications, and of much more interesting web sites. Cannot wait to see what Amazon chooses to do.
    • This opens up a new x-browser (and OS) application platform to developers
    • Flash isn't always the best experience. It does crash and you sometimes get this dialog about 'waiting for a long-running script'.
  • Is this yet another Microsoft technology that developers have to learn?
    • Yes and no. If you know WPF already, then you'll be at home.
    • If you don't know the .NET Framework, then Silverlight is a great way to learn an impressive set of basics.
    • There are some differences to learn, but it's all minor
  • Is Microsoft serious about x-brower and x-OS?
    • Yes.
  • Are .NET Framework teams stoked about Silverlight?
    • Last time I checked ;)

As I work more on my photo gallery site, I'm pretty sure I'll develop more thoughts and hopefully some answers to some of the questions that I've raised.

Wednesday, August 08, 2007 5:46:30 AM (GMT Daylight Time, UTC+01:00)  #    Disclaimer  |  Comments [3]  | 
# Thursday, December 28, 2006

For those of you out there that are smarter than me ... and after yesterday's post, I'm thinking that there are a *lot* of you ... You probably noticed that I was a little confused between the effects of IE7 protected mode (Low Rights IE or LoRIE), the VS 2005 SP1 release and the debugging problems that I was experiencing on Vista.

I've known about IE7 protected mode, sandboxing and virtualization for many months now and was even cognizant of that when I was having my debugging problems. I even glanded down at the bottom bit of the IE chrome and noticed "Protected Mode: On", but for some reason I thought http://localhost would *not* be affected by the protected mode. I was dead wrong. Arghh.

So, the answer to the basic debugging problems that I was having w/IE7 on Vista are entirely solved by adding http://localhost as a trusted site in IE7. Remember to uncheck the "https://" checkbox when adding the site, or else you won't be able to add http://localhost.

There are a bunch of other blog posts on the subject if you are interested.

Thursday, December 28, 2006 10:37:57 PM (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [0]  | 
# Wednesday, December 27, 2006

I decided to re-build dasblog (the blog software that I use) on Whidbey (VS 2005) over the holidays. It is something that I had always wanted to do and it seems like the dasblog folks have not yet publicly taken that on. Before anyone gets any strange ideas, I have no desire for a thinkjot-like schism, but wanted to move the codebase to Whidbey and work on getting the software to run under partial-trust. If this all works out, and the dasblog team wants to adopt my changes, cool, otherwise, I'm going to just use it myself.

Anyway, I decided to tackle this task over the holidays. Believe it or not, I almost exclusively use the free VS Express SKUs for my coding work. The "free" part isn't a big deal for me as I have a full copy of VS team suite a couple meters away from me, and I can download and install any program (including "Microsoft Bob") from the MS network that I want. Still, the Express SKUs are super convenient since I can download and install them in about 10mins and they satisfy most of my needs. Anyway, I downloaded the dasblog source and started playing with it. It became clear that I needed to use both VS express C# and VS express Web to get this done since the Web product didn't appear to support multiple projects in a single solution; in fact, it didn't appear to support the solution concept at all. And I then realized that since VS C# doesn't support JIT attach debugging (due to licensing issues), that the whole thing wasn't going to work at all. That's when I reached over for the quite large (requires two hands) VS team suite box to do some "real developlment" ;)

After a fairly lengthy install (and I didn't even install MSDN since I use the web mostly), I started back at it. I was able to get the web and class library projects into one solution in VS. Cool! I then hit F5 and it was immediately clear that something was terribly broken. The web project launched as expected, but was immediately detached from the debugger. Huh? I tried a couple more times, and I had the same experience. I was able to attach VS to WebDev.WebServer.Exe and then refresh the page, and then my breakpoints were hit. This approach though is anything but a good experience.

I had heard that there were some incompatibilities with VS on Vista, but I was under the impression that it was more niche issues, of which this is not. It is also very strange that I didn't have these same problems with the Express products, which I've been using on Vista for months. I wonder why the full product has some additional problems. I'm sure someone in building 41 knows.

Time to install VS 2005 SP1. I went to the following page. I downloaded the Vista-specific update. That didn't work, claiming that I was missing a file or two. I then downloaded and installed the non-Vista-specific SP1 package, which is just shy of 1/2 GB. Ouch! That worked. Upon launching VS, it claimed that I needed the Vista-specific update. Oh, I see, you need to install the generic VS 2005 service pack, and then the Vista-specific update. That was not at all clear to me from the VS 2005 SP1 page. Grrrr. Anyhow, now you can avoid the trouble that I had.

I then launch VS, but it claims that I need to launch the app elevated. I was actually expecting that, but thought that they would have manifested the application to force the elevation dialog. I guess not, or maybe that's still coming. Developers are going to go nuts if they have to remember to right click on the VS 2005 icon and hit "Run as administrator" every time, or just turn off UAC on their dev-boxes, which is a bad idea.

OK, launch VS again, but elevated, and voila, everything is working correctly again. Peace and harmony have now returned to my development experience.

I'm very thanksful that the VS team has pulled off this pretty significant service pack ... *before* Vista is generally available. I'm glad to be back and productive again. The directions on MSDN could use some improvement.

Wednesday, December 27, 2006 10:29:08 PM (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [1]  | 
# Wednesday, December 20, 2006

I wrote a recent post about getting the list of loaded assemblies. That’s a pretty straight-forward operation as shown by the code listed in that post. I’d like to step up the problem one notch by looking at getting the list of assemblies from another domain. Seems like a very reasonable thing to do ... Or we’ll see …

To properly setup this example, I need to create another domain and keep a reference to that domain. That’s easy:

            //Create new domain

            AppDomain domain = AppDomain.CreateDomain("domain2");

 

Next, we need to load some code in that domain, or else there won’t be any assemblies loaded there to actually query. Note that Host is one of my types, as you’ll see later. The method below loads the DomainHost assembly in domain2, creates an instance of the DomainHost.Host type in domain2 and also returns a reference to that instance in the current domain. That’s why you see the cast to Host.

            Host host = (Host)domain.CreateInstanceAndUnwrap("DomainHost", "DomainHost.Host");

 

OK … this is the part that where it gets interesting. It is actually a little non-obvious on how you are intended to get the list of loaded assemblies from the other domains. Let’s first look at the most intuitive approach for doing this. There is the same GetAssemblies() method on AppDomain that I used in the last post.  So, given that I have a reference to the domain2 AppDomain instance, why not just call GetAssemblies() on it? This is what the code would look like:

            domain.GetAssemblies();

 

For a variety of reasons, assemblies are not marked as serializable objects, which means that they cannot be remoted across an appdomain (or any other) boundary. You can get around this limitation by remoting and then loading an assembly as a Byte[], but that’s a different blog post. This call gets around the limitation by remoting an array of representative AssemblyName objects, as opposed to the actual assemblies. The loader then does the equivalent of the following, assuming the AssemblyName[]is called asmNames:

            foreach (AssemblyName asmName in asmNames)

            {

                Assembly.Load(asmName);

            }

This behavior is not really expected or desirable. First, you really want the AssemblyName objects, not the Assembly objects, and you definitely do not want to cause the assemblies to be loaded in this domain. In addition, if the assemblies are not located in the GAC, and the other domain has a different AppBase, then it is very likely that the assembly loads will fail, resulting in the loader throwing an exception that you might not be prepared to catch. Ouch. That’s really bad. It is also important that not all assemblies play nicely with this behavior. For example, Reflection.Emit assemblies cannot be re-loaded cross domain, for fairly obvious reasons. Mixed-mode assemblies have another set of problems. So, let’s skip that option.

Another option is to call AppDomain.GetAssemblies() in the other domain, and then to remote the Assembly[] back through to the current domain.  That will have the same effect as what I just discussed above.

 I’ve skipped over some important details that I need to explain. My DomainHost.Host type is a regular old that type that happens to inherit from System.MarshalByRefObject. The fact that it inherits from this type is more of a marking than anything else, as I don’t override any of MBRO’s methods, nor do I have to know what they are. This is very conceptually similar to marking a type with the [Serializable] attribute. The difference is that MBRO provides copy-by-ref semantics as opposed to copy-by-value across a boundary, which is what the [Serializable] attribute provides. This means that MBRO-inherited types can be remoted across a domain, process or even machine boundary as a reference that you can easily call across. The method calls only affect the domain in which the type actually resides (not where the reference resides), with the exception that return types (which must be either MBRO or [Serializable]) are returned to where the call was made from (the current domain). The reference is called a transparent proxy, and you can see that in the debugger when you try to peer into what turns out to be the largely opaque System.Runtime.Remoting.Proxies.__TransparentProxy type. Woah! The fact that DomainHost.Host is MBRO is going to turn out quite useful, as we’ll see.

OK, now to the real solution. I need to add a method to DomainHost.Host that I can call that returns AssemblyName[] and that does not interact with the loader in any way on this side of the domain boundary, as I want to avoid any assembly loads on these AssemblyName objects. Let’s see what the method would look like:

        public AssemblyName[] GetAssemblyNames()

        {

            AssemblyName[] names;

            Assembly[] asms;

 

            asms = AppDomain.CurrentDomain.GetAssemblies();

            names = new AssemblyName[asms.Length];

 

            for (Int32 i = 0; i < asms.Length; i++ )

            {

                names[i] = asms[i].GetName();

            }

 

            return names;

        }

This method uses the AppDomain.GetAssemblies() method to get the list of loaded assemblies, but doesn’t return that. It creates an equal length AssemblyName[] array to the Assembly[] that it already has.  It then populates that array with the assembly name of each of the assemblies. After the assembly name array is populated, the method returns that array of serializable objects back to the caller, which happens to be on the other side of the appdomain boundary. And how does one call such a method on the other side of the appdomain boundary? Easy:

            AssemblyName[] asmNames = host.GetAssemblyNames();

 

This ease of cross-boundary calls is the beauty of .NET Remoting. You just call methods as if the instances were located directly beside you. Cool.

Well, that’s now about it. Let’s take a look at the whole program:

Main program:

using System;

using System.Reflection;

using DomainHost;

 

namespace GetAssemblyNamesFromDomain

{

    class Program

    {

        static void Main(string[] args)

        {

            AppDomain domain;

            Host host;

            AssemblyName[] asmNames;

 

            //Create new domain

            domain = AppDomain.CreateDomain("domain2");

//Load assembly in domain2 and create instance of DomainHost.Host

//A reference to the instance of DomainHost.Host is returned

            host = (Host)domain.CreateInstanceAndUnwrap("DomainHost", "DomainHost.Host");

 

            //Most obvious method for getting the list of loaded assemblies.

            //This method will cause the assemblies in the remote domain to

            //be loaded in this domain, which frequently won't work. Ouch!

            //domain.GetAssemblies();

 

            asmNames = host.GetAssemblyNames();

            Console.WriteLine();

            Console.WriteLine("Printing assemblies:");

            foreach (AssemblyName asmName in asmNames)

            {

                Console.WriteLine(asmName.FullName);

            }

 

        }

    }

}

 

DomainHost.Host (in DomainHost.dll)

using System;

using System.Reflection;

 

namespace DomainHost

{

    public class Host : MarshalByRefObject

    {

        public Host()

        {

            Console.WriteLine("Loading host in domain {0}",AppDomain.CurrentDomain.FriendlyName);

        }

 

        public AssemblyName[] GetAssemblyNames()

        {

            AssemblyName[] names;

            Assembly[] asms;

 

            asms = AppDomain.CurrentDomain.GetAssemblies();

            names = new AssemblyName[asms.Length];

 

            for (Int32 i = 0; i < asms.Length; i++ )

            {

                names[i] = asms[i].GetName();

            }

 

            return names;

        }

 

    }

}

 

The output of the program looks like:

Loading host in domain domain2

Printing assemblies:

mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089

Microsoft.VisualStudio.HostingProcess.Utilities, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a

DomainHost, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null

 

The fact that I see “Microsoft.VisualStudio.HostingProcess.Utilities” loaded is a VS weirdness. VS is loading an assembly in domain2 to somehow “help me”, but I don’t know why. This only occurs when I’m running/debugging my app through VS. If I run the program outside of VS, I don’t see that assembly loaded. You have noticed executables ending in vshost.exe. That’s a similar issue, but for another day.

Wednesday, December 20, 2006 8:40:10 PM (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [0]  |