Work

Windows Azure

The Windows Azure Platform has a rich diagnostics infrastructure to enable logging and performance monitoring in the cloud.

When you run a cloud app locally in the DevFabric you can view diagnostics trace output in the console window that is part of the DevFabric UI. For example, say I have the line

System.Diagnostics.Trace.TraceInformation("Old Trace called at {0}.", DateTime.Now);

That line gives a result like this in the DevFabric UI:

Screenshot of DevFabric UI

If you can’t see the DevFabric UI, you can enable it here after starting your cloud app from Visual Studio:

image 

Using the DevFabric UI is the most basic form of viewing Trace output. Looking at each individual console window doesn’t really scale well if you have many instances and, furthermore, the console window of an instance is not available in the cloud. For this, there is a special TraceListener derived class: Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener. It sends the trace output to a Windows Azure diagnostics monitor process that is able to store the messages in Windows Azure Storage. Here is a look at a trace message using the Azure Storage Explorer:

Screenshot of Azure Storage Explorer

This trace listener is enabled through web.config:

  <system.diagnostics>
    <sources>
      <source name="Diag">
        <listeners>
          <add name="AzureDiagnostics" />
        </listeners>
      </source>
    </sources>
    <sharedListeners>
      <add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
          name="AzureDiagnostics" />
    </sharedListeners>
    <trace>
      <listeners>
        <add name="AzureDiagnostics" />
      </listeners>
    </trace>
  </system.diagnostics>

You can also see a message “TraceSource called at …”. This message was output using a TraceSource instance:

private static readonly TraceSource ts = new System.Diagnostics.TraceSource("Diag", SourceLevels.All);

protected void TraceMeButton_Click(object sender, EventArgs e)
{
    ts.TraceEvent(TraceEventType.Information, 2, "TraceSource called at {0}.", DateTime.Now);
    System.Diagnostics.Trace.TraceInformation("Old Trace called at {0}.", DateTime.Now);
}

However, note that a similar message “TraceSource called at …” didn’t show up in the DevFabric UI. You might wonder what is going on. And you might wonder why I want to use a TraceSource instead of Trace? Because this MSDN article states:

One of the new features in the .NET Framework version 2.0 is an enhanced tracing system. The basic premise is unchanged: tracing messages are sent through switches to listeners, which report the data to an associated output medium. A primary difference for version 2.0 is that traces can be initiated through instances of the TraceSource class. TraceSource is intended to function as an enhanced tracing system and can be used in place of the static methods of the older Trace and Debug tracing classes. The familiar Trace and Debug classes still exist, but the recommended practice is to use the TraceSource class for tracing.

Also check out this blog post.

The reason you don’t see the message for the TraceSource in the DevFabric UI is that the DevFabric magically adds a special TraceListener for the “old fashioned” Trace class, but not for your TraceSource instance. I put together a cloud app solution (Visual Studio 2010) that shows this through a simple web role. This web role has the configuration you see above in its web.config file. If you run this simple web role in the DevFabric you’ll see:

Screenshot of sample web role app

Note that Trace has a Microsoft.ServiceHosting.Tools.DevelopmentFabric.Runtime.DevelopmentFabricTraceListener instance registered, while the TraceSource hasn’t. To remedy this, I’ve created a small class that adds a DevFabricTraceListener to a TraceSource if it is registered for Trace:

public static class TraceSourceFixer
{
    private const string DevFabricTraceListenerFullName = "Microsoft.ServiceHosting.Tools.DevelopmentFabric.Runtime.DevelopmentFabricTraceListener";

    public static void AddDevFabricTraceListener(TraceSource traceSource)
    {
        var alreadyInTraceSource = GetDevFabricTraceListeners(traceSource.Listeners);

        if (alreadyInTraceSource.Count() > 0)
            return;

        var alreadyInTrace = GetDevFabricTraceListeners(Trace.Listeners);

        var devFabricTraceListener = alreadyInTrace.FirstOrDefault();
        if (devFabricTraceListener != null)
        {
            traceSource.Listeners.Add(devFabricTraceListener);
        }
    }

    private static IEnumerable<TraceListener> GetDevFabricTraceListeners(TraceListenerCollection listeners)
    {
        var result = from TraceListener listener in listeners.Cast<TraceListener>()
                where IsDevFabricTraceListener(listener)
                select listener;

        return result;
    }

    private static bool IsDevFabricTraceListener(TraceListener listener)
    {
        return (listener.GetType().FullName == DevFabricTraceListenerFullName);
    }
}

This helper class gets called when you press the Register DevFabric Listener button. If you click the Trace Me button after that, you’ll see two trace messages show up in the DevFabric UI:

Screenshot of DevFabric UI detail

You can download my solution DiagnosticsService.zip to try it yourself.

Wow, April 2010 proves to be a jam-packed month of releases from Microsoft. A short list, that is bound to be incomplete:

  • .NET Framework 4
  • Visual Studio 2010
  • Office 2010
  • SharePoint 2010
  • Data Protection Manager 2010
  • System Center Essentials 2010
  • Dynamics GP 2010
  • Enterprise Library 5.0
  • SQL Server 2008 R2

R2 Banner

The trial versions of SQL Server 2008 R2 are now available for download. Here are the highlights of what’s new in 2008 R2:

  • PowerPivot: a managed self-service analysis solution that empowers end users to access, analyze and share data across the enterprise in an IT managed environment using Excel 2010 and SharePoint Sever 2010.
  • Master Data Services: helps IT organizations centrally manage critical data assets companywide and across diverse systems, and enables more people to securely manage master data directly, and ensure the integrity of information over time.
  • Application and Multi-server Management: helps organizations proactively manage database environments efficiently at scale through centralized visibility into resource utilization and streamlined consolidation and upgrade initiatives across the application lifecycle.
  • Report Builder 3.0: report authoring component with support for geospatial visualization. This new release provides capabilities to further increase end user productivity with enhanced wizards, more powerful visualizations, and intuitive authoring.
  • StreamInsight: a low latency complex event processing platform to help IT monitor, analyze and act on the data in motion to make more informed business decisions in near real-time.

More details about the release can be found on the team blog.

1 Comment

The Microsoft Enterprise Library has always been one of the most popular things to come out of the patterns & practices team. Yesterday p&p reached a major milestone by releasing version 5.0 of EntLib.

The improvements are too numerous to sum up here, but let me mention one: this release has full .NET 3.5 SP1 and .NET 4 compatibility and works great from both Visual Studio 2008 SP1 and Visual Studio 2010 RTM.

Full details can be found in Grigori Melnik’s blog post on this release. Or you can go straight to the download page or the documentation.

.NET Frameworkin Windows Azure 

As you will probably know, Visual Studio 2010 and .NET Framework 4 will RTM on April 12, 2010 and will be available for download on MSDN Subscriptions Downloads the same day.

The Windows Azure team is committed to making .NET Framework 4 available in Windows Azure within 90 days of the RTM date.

A lesser known fact is that the latest available Windows Azure build already has a .NET 4 version installed, namely the RC bits. Although this version cannot be used to run applications on (because .NET 4 is not yet exposed in the Windows Azure dev tools), you can use this build to test if the presence of .NET 4 has impact on existing .NET 3.5 apps running on Windows Azure.

Read the official announcement here.

VS2010-Ult_h_rgb

Last week we published a new major version of the Visual Studio Performance Testing Quick Reference Guide. The effort of creating this document was lead by Geoff Gray. Geoff is a senior consultant in the Microsoft Services Labs in the US that specializes in performance testing using Visual Studio. I was part of the Rangers team that contributed articles to this guide.

From time to time I do performance testing engagements. Last week for example I worked for a customer and load tested their new Internet facing website before it goes live later this month. Performance testing uncovers issues in the software and the infrastructure that might otherwise go unnoticed until the public hits the site. And that is a bad time to discover performance issues.

Creating and executing real-world performance testing can be a tricky job and this quick reference guide gives lots of tricks & tips from consultants from Microsoft Services and the Visual Studio product team on how to tackle challenges you might encounter.

Visual Studio has a rich extensibility model for performance testing and that’s why it is interesting for development minded people like me. You can create plug-ins in C# to do  advanced parameterization of web tests and load tests (example on MSDN). The QRG has lots of examples of when and how this is useful.

Load testing is part of Visual Studio 2008 Team Suite or Test Edition and of Visual Studio 2010 Ultimate. With VS2010, if you need to simulate more than 1000 users, you can purchase “virtual user packs”. This will enable you to simulate higher loads using a test rig consisting of one test controller and several test agents. Previously with VS2008 you had to license each agent. You can’t be sure in advance how many users you can simulate with one agent because it depends on many factors like hardware and complexity of the application and the test itself.

Many organizations forego the effort of performance testing and take a “wait and see” stance. This reactive approach can lead to costly repairs and bad publicity. My advice is to take a proactive stance and be confident about the performance of your application before it goes live. In many cases there are quick wins to improve the performance by enabling better caching (blob caching for SharePoint). Even simple things like enabling HTTP compression are still often forgotten.

I ran into an issue with a Windows Azure project created from scratch in Visual Studio 2010 Beta 1 with the May CTP of the Windows Azure Tools.Azure_Logo

When trying to create tables in the local development storage, I got the error “Invalid image format”. This issue occurred both from VS (using the Create Test Storage Tables option) and when running DevTableGen.exe manually from a command prompt. It didn’t occur when doing the same in VS2008.

DevTableGen.exe is a tool from the Windows Azure SDK. This tools loads an assembly, reflects over it and then tries to create tables in the local development storage.

After some head scratching I figured out the cause: in Dev10 the default target platform for executables was changed from AnyCPU to x86. In Beta 1 a bug snuck in, so that x86 is also the default for class libraries (DLLs). This will be changed back to AnyCPU in Beta 2. This blog post from Rick Byers has a lot of detail on why the default has changed.

DevTableGen.exe is an AnyCPU executable, so it will run as a 64-bit process on an 64-bit version of Windows. As such it cannot load assemblies marked as 32-bit only when run on 64-bit Windows. The solution was to change the assembly to AnyCPU.

This issue would have been prevented if DevTableGen.exe was marked as 32-bit only. That way it would always run in a 32-bit process and could load x86 and AnyCPU assemblies. According to the blog post linked to above, it is now considered best practice to explicitly mark an executable as x86 or x64. For most applications x86 is the best option.

I’ve suggested this change to the product team.

Update: I've been informed that DevTableGen.exe will not be changed. This is because this issue is temporary and will go away when VS2010 Beta 2 is released. Also the web role and worker role processes in Windows Azure are 64-bit, so trying to load x86 assemblies will fail anyway. So if you use Beta 1 make sure you explicitly change the platform for any assemblies you create for the cloud to AnyCPU.

We have created a new logo for the Microsoft .NET brand.

It will be used widely starting next week at PDC08 in Los Angeles. Expect lots of great announcements at this event.

For those attending PDC08, have fun, I am sure you will be amazed! For the not so fortunate who stay at home, the keynote sessions will be streamed live. All other sessions will be available as webcasts within 24 hours.

Keep an eye on the PDC site next week.

Details on why we are reinvigorating the .NET brand with a new logo can be found here.

It depends on the situation if I self-identify as a geek or not. Today, I thought it would be fine, so I signed up for the Geek Dinner organized by Scott Hanselman in Bellevue, WA.

Quite a lot of people showed up. I went there with my colleague Erwin van der Valk. He was a Development Consultant, like I currently am, at Microsoft Services in the Netherlands. Erwin now works on the Patterns & Practices team at Microsoft in Redmond.

I took this picture of the entire group:

Microsoft Geek Dinner 

After dinner, a large portion of the group went to the Rock Bottom Restaurant and Brewery in Bellevue to continue the conversation. I had some really interesting discussions, over beer, with guys from several different product teams and a fellow MCS consultant based in Denver, CO. And not even all about Microsoft technology 😉

Too bad, I won't be able to attend this event in the near future again, unless I just happen to be in the neighborhood.

You probably already noticed that Microsoft has enabled access to the source code of parts of the .NET Framework 3.5. Here is the announcement of availability in case you missed it. And there are detailed instructions on how to enable this as well.

This morning I started stepping into the Windows Presentation Foundation. Before I knew it I was deep down into the internals of dependency properties and the Dispatcher object. The dispatcher has a nice old-fashioned message pump. I stepped into the dispatch of a message call onto a non-UI thread. Even though I already knew this, it is still startling to see that this translates into old-fashioned User32 Windows messages being send.

What really surprised me was to see a bit of VB code in a file that is called ExceptionFilterHelper.vb. According to the comment this file was needed because C#, unlike VB, does not support exception filters. However, the filter always returns true. According to the comment in the source code it is a "dummy stub to keep compiler happy, will not be replaced".

Something weird is going on here. The debugger shows I am in WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.TryCatchWhen. The source code file shows the class MS.Internal.Threading.ExceptionWrapper.TryCatchWhen. Reflector can only find the former class. The disassembly of this class shows source code that is very different than what the MS source code server gives me.

This doesn't make much sense to me. Is the source code for this class deliberately hidden or is there some error in the source code lookup?

Since I haven't had my lawyer take a look at the license agreement that governs the source code access, I will not add a screen shot of the VB code 😉