ScottGu ASP.NET Articles
RSS
Building a Windows Phone 7 Twitter Application using Silverlight
Published Fri, 19 Mar 2010 06:18:36 GMT

On Monday I had the opportunity to present the MIX 2010 Day 1 Keynote in Las Vegas (you can watch a video of it here).  In the keynote I announced the release of the Silverlight 4 Release Candidate (we’ll ship the final release of it next month) and the VS 2010 RC tools for Silverlight 4.  I also had the chance to talk for the first time about how Silverlight and XNA can now be used to build Windows Phone 7 applications.

During my talk I did two quick Windows Phone 7 coding demos using Silverlight – a quick “Hello World” application and a “Twitter” data-snacking application.  Both applications were easy to build and only took a few minutes to create on stage.  Below are the steps you can follow yourself to build them on your own machines as well.

[Note: In addition to blogging, I am also now using Twitter for quick updates and to share links. Follow me at: twitter.com/scottgu]

Building a “Hello World” Windows Phone 7 Application

First make sure you’ve installed the Windows Phone Developer Tools CTP – this includes the Visual Studio 2010 Express for Windows Phone development tool (which will be free forever and is the only thing you need to develop and build Windows Phone 7 applications) as well as an add-on to the VS 2010 RC that enables phone development within the full VS 2010 as well.

After you’ve downloaded and installed the Windows Phone Developer Tools CTP, launch the Visual Studio 2010 Express for Windows Phone that it installs or launch the VS 2010 RC (if you have it already installed), and then choose “File”->”New Project.”  Here, you’ll find the usual list of project template types along with a new category: “Silverlight for Windows Phone”. The first CTP offers two application project templates. The first is the “Windows Phone Application” template - this is what we’ll use for this example. The second is the “Windows Phone List Application” template - which provides the basic layout for a master‑details phone application:

image

After creating a new project, you’ll get a view of the design surface and markup. Notice that the design surface shows the phone UI, letting you easily see how your application will look while you develop. For those familiar with Visual Studio, you’ll also find the familiar ToolBox, Solution Explorer and Properties pane.

image

For our HelloWorld application, we’ll start out by adding a TextBox and a Button from the Toolbox. Notice that you get the same design experience as you do for Silverlight on the web or desktop. You can easily resize, position and align your controls on the design surface. Changing properties is easy with the Properties pane. We’ll change the name of the TextBox that we added to username and change the page title text to “Hello world.”

image

We’ll then write some code by double‑clicking on the button and create an event handler in the code-behind file (MainPage.xaml.cs).

image

We’ll start out by changing the title text of the application. The project template included this title as a TextBlock with the name textBlockListTitle (note that the current name incorrectly includes the word “list”; that will be fixed for the final release.)  As we write code against it we get intellisense showing the members available.  Below we’ll set the Text property of the title TextBlock to “Hello “ + the Text property of the TextBox username:

image

We now have all the code necessary for a Hello World application.  We have two choices when it comes to deploying and running the application. We can either deploy to an actual device itself or use the built‑in phone emulator:

image

Because the phone emulator is actually the phone operating system running in a virtual machine, we’ll get the same experience developing in the emulator as on the device. For this sample, we’ll just press F5 to start the application with debugging using the emulator.  Once the phone operating system loads, the emulator will run the new “Hello world” application exactly as it would on the device:

image

Notice that we can change several settings of the emulator experience with the emulator toolbar – which is a floating toolbar on the top right.  This includes the ability to re-size/zoom the emulator and two rotate buttons.  Zoom lets us zoom into even the smallest detail of the application:

image

The orientation buttons allow us easily see what the application looks like in landscape mode (orientation change support is just built into the default template):

image

Note that the emulator can be reused across F5 debug sessions - that means that we don’t have to start the emulator for every deployment. We’ve added a dialog that will help you from accidentally shutting down the emulator if you want to reuse it.  Launching an application on an already running emulator should only take ~3 seconds to deploy and run.

Within our Hello World application we’ll click the “username” textbox to give it focus.  This will cause the software input panel (SIP) to open up automatically.  We can either type a message or – since we are using the emulator – just type in text.  Note that the emulator works with Windows 7 multi-touch so, if you have a touchscreen, you can see how interaction will feel on a device just by pressing the screen.

image

We’ll enter “MIX 10” in the textbox and then click the button – this will cause the title to update to be “Hello MIX 10”:

image

We provide the same Visual Studio experience when developing for the phone as other .NET applications. This means that we can set a breakpoint within the button event handler, press the button again and have it break within the debugger:

image

Building a “Twitter” Windows Phone 7 Application using Silverlight

Rather than just stop with “Hello World” let’s keep going and evolve it to be a basic Twitter client application.

We’ll return to the design surface and add a ListBox, using the snaplines within the designer to fit it to the device screen and make the best use of phone screen real estate.  We’ll also rename the Button “Lookup”:

image

We’ll then return to the Button event handler in Main.xaml.cs, and remove the original “Hello World” line of code and take advantage of the WebClient networking class to asynchronously download a Twitter feed. This takes three lines of code in total: (1) declaring and creating the WebClient, (2) attaching an event handler and then (3) calling the asynchronous DownloadStringAsync method.

In the DownloadStringAsync call, we’ll pass a Twitter Uri plus a query string which pulls the text from the “username” TextBox. This feed will pull down the respective user’s most frequent posts in an XML format. When the call completes, the DownloadStringCompleted event is fired and our generated event handler twitter_DownloadStringCompleted will be called:

image

The result returned from the Twitter call will come back in an XML based format.  To parse this we’ll use LINQ to XML. LINQ to XML lets us create simple queries for accessing data in an xml feed. To use this library, we’ll first need to add a reference to the assembly (right click on the References folder in the solution explorer and choose “Add Reference):

image

We’ll then add a “using System.Xml.Linq” namespace reference at the top of the code-behind file at the top of Main.xaml.cs file:

image

We’ll then add a simple helper class called TwitterItem to our project. TwitterItem has three string members – UserName, Message and ImageSource:

image

We’ll then implement the twitter_DownloadStringCompleted event handler and use LINQ to XML to parse the returned XML string from Twitter.  What the query is doing is pulling out the three key pieces of information for each Twitter post from the username we passed as the query string. These are the ImageSource for their profile image, the Message of their tweet and their UserName. For each Tweet in the XML, we are creating a new TwitterItem in the IEnumerable<XElement> returned by the Linq query. 

We then assign the generated TwitterItem sequence to the ListBox’s ItemsSource property:

image

We’ll then do one more step to complete the application. In the Main.xaml file, we’ll add an ItemTemplate to the ListBox. For the demo, I used a simple template that uses databinding to show the user’s profile image, their tweet and their username.

<ListBox Height="521" HorizonalAlignment="Left" Margin="0,131,0,0" Name="listBox1" VerticalAlignment="Top" Width="476">
    <ListBox.ItemTemplate>
        <DataTemplate>
           <StackPanel Orientation="Horizontal" Height="132">
              <Image Source="{Binding ImageSource}" Height="73" Width="73" VerticalAlignment="Top" Margin="0,10,8,0"/>
              <StackPanel Width="370">
                 <TextBlock Text="{Binding UserName}" Foreground="#FFC8AB14" FontSize="28" />
                 <TextBlock Text="{Binding Message}" TextWrapping="Wrap" FontSize="24" />
              </StackPanel>
           </StackPanel>
        </DataTemplate>
     </ListBox.ItemTemplate>
</ListBox>

Now, pressing F5 again, we are able to reuse the emulator and re-run the application. Once the application has launched, we can type in a Twitter username and press the  Button to see the results. Try my Twitter user name (scottgu) and you’ll get back a result of TwitterItems in the Listbox:

image

Try using the mouse (or if you have a touchscreen device your finger) to scroll the items in the Listbox – you should find that they move very fast within the emulator.  This is because the emulator is hardware accelerated – and so gives you the same fast performance that you get on the actual phone hardware.

Summary

Silverlight and the VS 2010 Tools for Windows Phone (and the corresponding Expression Blend Tools for Windows Phone) make building Windows Phone applications both really easy and fun. 

At MIX this week a number of great partners (including Netflix, FourSquare, Seesmic, Shazaam, Major League Soccer, Graphic.ly, Associated Press, Jackson Fish and more) showed off some killer application prototypes they’ve built over the last few weeks.  You can watch my full day 1 keynote to see them in action. I think they start to show some of the promise and potential of using Silverlight with Windows Phone 7.  I’ll be doing more blog posts in the weeks and months ahead that cover that more.

Hope this helps,

Scott

[Read More]
ASP.NET MVC 2 Released
Published Fri, 12 Mar 2010 05:24:16 GMT

I’m happy to announce that the final release of ASP.NET MVC 2 is now available for VS 2008/Visual Web Developer 2008 Express with ASP.NET 3.5.  You can download and install it from the following locations:

The final release of VS 2010 and Visual Web Developer 2010 will have ASP.NET MVC 2 built-in – so you won’t need an additional install in order to use ASP.NET MVC 2 with them. 

ASP.NET MVC 2

We shipped ASP.NET MVC 1 a little less than a year ago.  Since then, almost 1 million developers have downloaded and used the final release, and its popularity has steadily grown month over month.

ASP.NET MVC 2 is the next significant update of ASP.NET MVC. It is a compatible update to ASP.NET MVC 1 – so all the knowledge, skills, code, and extensions you already have with ASP.NET MVC continue to work and apply going forward. Like the first release, we are also shipping the source code for ASP.NET MVC 2 under an OSI-compliant open-source license.

ASP.NET MVC 2 can be installed side-by-side with ASP.NET MVC 1 (meaning you can have some apps built with V1 and others built with V2 on the same machine).  We have instructions on how to update your existing ASP.NET MVC 1 apps to use ASP.NET MVC 2 using VS 2008 here.  Note that VS 2010 has an automated upgrade wizard that can automatically migrate your existing ASP.NET MVC 1 applications to ASP.NET MVC 2 for you.

ASP.NET MVC 2 Features

ASP.NET MVC 2 adds a bunch of new capabilities and features.  I’ve started a blog series about some of the new features, and will be covering them in more depth in the weeks ahead.  Some of the new features and capabilities include:

You can learn more about these features in the “What’s New in ASP.NET MVC 2” document on the www.asp.net/mvc web-site. 

We are going to be posting a lot of new tutorials and videos shortly on www.asp.net/mvc that cover all the features in ASP.NET MVC 2 release.  We will also post an updated end-to-end tutorial built entirely with ASP.NET MVC 2 (much like the NerdDinner tutorial that I wrote that covers ASP.NET MVC 1). 

Summary

The ASP.NET MVC team delivered regular V2 preview releases over the last year to get feedback on the feature set.  I’d like to say a big thank you to everyone who tried out the previews and sent us suggestions/feedback/bug reports. 

We hope you like the final release!

Scott

[Read More]
Some VS 2010 RC Updates (including patches for Intellisense and Web Designer fixes)
Published Mon, 08 Mar 2010 08:07:29 GMT

[In addition to blogging, I am also now using Twitter for quick updates and to share links. Follow me at: twitter.com/scottgu]

We are continuing to make progress on shipping Visual Studio 2010.  I’d like to say a big thank you to everyone who has downloaded and tried out the VS 2010 Release Candidate, and especially to those who have sent us feedback or reported issues with it. This data has been invaluable in helping us find and fix remaining bugs before we ship the final release.

Last month I blogged about a patch we released for the VS 2010 RC that fixed a bad intellisense crash issue.  This past week we released two additional patches that you can download and apply to the VS 2010 RC to immediately fix two other common issues we’ve seen people run into:

Patch that fixes crashes with Tooltip invocation and when hovering over identifiers

The Visual Studio team recently released a second patch that fixes some crashes we’ve seen when tooltips are displayed – most commonly when hovering over an identifier to view a QuickInfo tooltip.

You can learn more about this issue from this blog post, and download and apply the patch here.

Patch that fixes issues with the Web Forms designer not correctly adding controls to the auto-generated designer files

The Visual Web Developer team recently released a patch that fixes issues where web controls are not correctly added to the .designer.cs file associated with the .aspx file – which means they can’t be programmed against in the code-behind file. 

This issue is most commonly described as “controls are not being recognized in the code-behind” or “editing existing .aspx files regenerates the .aspx.designer.(vb or cs) file and controls are now missing” or “I can’t embed controls within the Ajax Control Toolkit TabContainer or the <asp:createuserwizard> control”.

You can learn more about the issue here, and download the patch that fixes it here.

Common Cause of Intellisense and IDE sluggishness on Windows XP, Vista, Win Server 2003/2008 systems

Over the last few months we’ve occasionally seen reports of people seeing tremendous slowness when typing and using intellisense within VS 2010 despite running on decent machines.  It took us awhile to track down the cause – but we have found that the common culprit seems to be that these machines don’t have the latest versions of the UIA (Windows Automation) component installed.

UIA 3 ships with Windows 7, and is a recommended Windows Update patch on XP and Vista (which is why we didn’t see the problem in our tests – since our machines are patched with all recommended updates).  Many systems (especially on XP) don’t automatically install recommended updates, though, and are running with older versions of UIA. This can cause significant performance slow-downs within the VS 2010 editor when large lists are displayed (for example: with intellisense).

If you are running on Windows XP, Vista, or Windows Server 2003 or 2008 and are seeing any performance issues with the editor or IDE, please install the free UIA 3 update that can be downloaded from this page.  If you scroll down the page you’ll find direct links to versions for each OS.

Note that we are making improvements to the final release of VS 2010 so that we don’t have big perf issues when UIA 3 isn’t installed – and we are also adding a message within the IDE that will warn you if you don’t have UIA 3 installed and accessibility is activated.

Improved Text Rendering with WPF 4 and VS 2010

We recently made some nice changes to WPF 4 which improve the text clarity and text crispness over what was in the VS 2010/.NET 4 Release Candidate.  In particular these changes improve scenarios where you have a dark background with light text.

You can learn more about these improvements in this WPF Team blog post.  These changes will be in the final release of VS 2010 and .NET 4.

Hope this helps,

Scott

[Read More]
A few announcements for those in the UK
Published Mon, 08 Mar 2010 07:04:30 GMT

[In addition to blogging, I am also now using Twitter for quick updates and to share links. Follow me at: twitter.com/scottgu]

This a quick post to announce a few upcoming events for those in the UK.

I’ll be presenting in Glasgow, Scotland on March 25th

I’m doing a free 5 hour presentation in Glasgow on March 25th. I’ll be covering VS 2010, ASP.NET 4, ASP.NET Web Forms 4, ASP.NET MVC 2, Silverlight and potentially show off a few new things that haven’t been announced yet.

You can learn more about the event and register for free here.  There are only a few spots left – so register quickly. 

When the event fills up there will be a wait-list – please add yourself to this as we’ll be encouraging people who won’t be able to attend to let us know ahead of time so that we can add more people to the event.

I’ll be presenting in Birmingham, England on March 26th

I’m doing a free 5 hour presentation in Birmingham (UK) on March 26th. I’ll be covering VS 2010, ASP.NET 4, ASP.NET Web Forms 4, ASP.NET MVC 2, Silverlight and also potentially show off a few new things that haven’t been announced yet.

You can learn more about the event and register for free here.

The event unfortunately filled up immediately (even before I had a chance to blog it) – but there is a waitlist.  If you’d like to attend please add yourself to it as hopefully a number of people will be able to attend off of it.

UK Party at MIX

If you are going to MIX and are from the UK send mail to phil@pixelprogramming.com (or tweet him @plip) for an invite to a party being organized for UK MIX attendees next Tuesday (March 16th).  Knowing the people involved I’m sure the party will be fun. <g>

Cool MIX10 iPhone App

Speaking of MIX (and UK developers), Chris Hardy has posted a cool new MIX10 iPhone application on the Apple AppStore.  The free application helps track sessions, rooms, etc.  You can learn more about it from Chris’ blog post here.  The app works for everyone – not just those from the UK. :-)

Hope this helps,

Scott

[Read More]
No Intellisense with VS 2010 RC (and how to fix it)
Published Sat, 27 Feb 2010 07:47:24 GMT

[In addition to blogging, I am also now using Twitter for quick updates and to share links. Follow me at: twitter.com/scottgu]

Patrick recently posted about something he found odd when installing the VS 2010 RC – which was that code intellisense for C# wasn’t working.  When he pulled up Tools->Options and checked under the Text Editor->C# settings he noticed that the reason Intellisense wasn’t working was because his profile had them turned off – and he couldn’t understand why it was configured to be off by default:

image

Why does this happen?

The above situation occurs because:

1) When you run VS 2010 the first time on a machine that has had VS 2008 installed on it, it asks you if you want to import your existing VS 2008 profile settings.  By default this checkbox is checked – which means you by default automatically import your existing settings.

2) Some VS plugins – for example Resharper – turn off the built-in C# code intellisense within VS and instead replace it with their own implementation.  If you’ve installed Resharper on VS 2008, the above VS code intellisense profile settings are turned off.  When you import your existing profile during VS 2010’s first time run experience the code intellisense settings import over in a disabled state.  If you haven’t installed Resharper on VS 2010 (which is a separate install) – then by default you’ll end up with intellisense turned off.

How to Fix this?

Fixing this situation with the VS 2010 RC is pretty easy.  Just do one of two things:

1) Use the Tools->Options menu command, select the Text Editor->C# settings, and then check the two circled check boxes above (Auto-list members and Parameter information).  Intellisense will then be turned on and work fine.

or:

2) Install the version of Resharper that works with the VS 2010 RC. It then enables intellisense using its own mechanism.

We are modifying the profile import behavior in the final release of VS 2010

We’ve heard reports of a few people running into this – and since the behavior is pretty confusing we are modifying the profile import behavior with the final release of VS 2010 to avoid it.  If a plugin has turned intellisense off with VS 2008, by default when you import the profile into VS 2010 we will re-enable it.  This will ensure that on a clean VS 2010 install intellisense always works by default. 

Hope this helps,

Scott

[Read More]
Patch for VS 2010 RC Intellisense Crash Issue Now Available
Published Mon, 15 Feb 2010 18:15:48 GMT

[In addition to blogging, I am also now using Twitter for quick updates and to share links. Follow me at: twitter.com/scottgu]

Last week I blogged about an intellisense crashing issue that is unfortunately in the VS 2010 RC. 

Crash Symptom

If you are encountering frequent VS 2010 crashes when you are typing in the editor while Intellisense is popping up and/or being dismissed then you are running into this issue.

Patch Now Available

This morning we made available a VS 2010 RC patch which fixes this issue.  You can download and run it here

Please apply it if you are encountering any crashes with the VS 2010 RC, or if you have a tablet, multi-touch, screen-reader or external devices attached (including Wacom tablets, phones/ipods, and others that connect via USB).

Please make sure to submit any issues you encounter with the VS 2010 RC to us via the connect.microsoft.com web-site.  Once you’ve entered the issue there please send me email (scottgu@microsoft.com) with a pointer to the issue and I’ll make sure the appropriate team follows up quickly.

Hope this helps,

Scott

[Read More]
Intellisense Crashing fix for VS 2010
Published Fri, 12 Feb 2010 00:41:49 GMT

[In addition to blogging, I am also now using Twitter for quick updates and to share links. Follow me at: twitter.com/scottgu]

We shipped the VS 2010 RC on Monday, and have seen some great feedback regarding performance and stability with it.

One issue, though, that we have seen a number of people run into is an intellisense crash that happens very frequently on machines that have UI Automation enabled and certain devices connected.

Crash Symptom

If you are encountering frequent VS 2010 crashes when you are typing in the editor while Intellisense is popping up and/or being dismissed then you are running into this issue.

Why does the crash happen?

The most common cause of the crash happening is that you are running a machine that:

  • Is a Tablet PC (even if you aren’t using the pen)
  • Has multi-touch screen drivers enabled
  • Has an external input device like a pen or Wacom tablet
  • Has a screen-reader enabled

It turns out that a late fix right before the RC shipped modified a UI input code path that unfortunately exposed this bug.

A patch is coming to fix this issue

We are working on shipping a VS 2010 RC patch that we’ll release next week that will fix the issue and prevent it from occurring.  I’ll blog a pointer to the patch once it is available.

How to work around the issue now

There are two ways you can work around the issue now.  One is to disable your Tablet services (read this article for details on how to do this) and/or disable Multi-touch/Pen drivers on your system.  The other is to set a registry key.

You can read about both of these workaround in this VS Team Blog Post.

What if you still see crashes?

Please send me email (scottgu@microsoft.com) if you are still seeing any crashes after trying out these steps (or encounter crashes for non-Intellisense scenarios) – we’d like to make sure we investigate and follow-up any others you encounter.

Hope this helps,

Scott

[Read More]
LIDNUG Online Chat with Me on Thursday Feb 11th
Published Thu, 11 Feb 2010 06:57:55 GMT

Today we opened up the VS 2010 RC for everyone to download.  You can download it here.  Jason Zander (who runs the Visual Studio team) has a good blog post that summarizes a lot of common questions about it here.

As I mentioned in my blog post about the RC on Monday, please send me email (scottgu@microsoft.com) about any bugs or issues you encounter – that way I can make sure to connect you with someone who can follow up and investigate them quickly.

Online Chat with Me Thursday February 11th at 10am PST

I’m doing a virtual webcast chat Thursday February 11th from 10am to 11:30am (PST timezone).  The chat is open to everyone and sponsored by the LIDNUG user group.  The format of the chat is open - and you can ask anything while you listen in as I try and answer as many questions as possible.  I expect I’ll spend a lot of time talking about VS 2010, .NET 4, Silverlight 4, ASP.NET 4 and ASP.NET MVC 2.

You can register and attend the chat for free here.

February 14th Update: You can download the audio version of my chat here.

Hope this helps,

Scott

[Read More]
VS 2010 / .NET 4 Release Candidate
Published Tue, 09 Feb 2010 07:39:56 GMT

[In addition to blogging, I am also now using Twitter for quick updates and to share links. Follow me at: twitter.com/scottgu]

This afternoon we made available the VS 2010 and .NET 4 release candidates.  You can find download links here.

Right now the downloads are available only to MSDN subscribers.  Starting Wednesday (Feb 10th) everyone will be able to download them (regardless of whether you are a MSDN subscriber or not).

Background on the Release Candidate

I blogged about us deciding to ship a public VS 2010 release candidate last December.  The primary motivation behind releasing a public RC was to ensure that we could get broad testing and feedback on the performance and stability work we’ve been doing since the last public VS 2010 Beta 2 release.

Over the last few months we’ve been releasing interim builds to a small set of folks who have been helping us validate fixes and measure very large projects and solutions.  The feedback from them has been extremely positive the last few weeks – which is why we are now opening up today’s build to a much wider set of people to people to try out.

The RC has only been out a few hours so far – but the feedback so far on Twitter has been nice to see:

  • @DanWahlin: The performance improvements with Visual Studio 2010 RC compared to previous builds are huge. Really happy with what I'm seeing so far.
  • @peterbromberg: VS2010 RC: I must admit, I am impressed. Major speed and performance improvements. They are obvious immediately!
  • @Nick_Craver: RC performance is ridiculously faster, can't wait to switch over full time!
  • @Rlz2cool: Just tried VS2010 RC. One word incredible. Super fast, great build with things I saw in earlier releases fixed. So awesome.
  • @ddotterer: Trying out VS2010 RC: Snappier UI, much faster intellisense, significant build time reduction, etc. Overall: AWESOME JOB
  • @tomkirbygreen: Oh my goodness, VS2010 RC is much, much faster. Kudos to the VS perf team and everyone else. Uninstalling Visual Studio 2008 :-)
  • @JoshODBrown The developers on the Visual Studio 2010 RC must have had their usual beverages replaced with unicorn tears or something. #VS2010 #awesome
  • @jbristowe: Holy Butterball! VS 2010 RC is crazy fast. It makes me feel like this: http://bit.ly/cPaOvE

Reporting Issues

Our goal with releasing the public RC build today is to get a lot of eyes on the product helping to find and report the remaining bugs we need to fix.  If you do find an issue, please submit a bug report via the Visual Studio Connect site and also please send me an email directly (scottgu@microsoft.com) with details about it.  I can then route your email to someone to investigate and follow-up directly (which can help expedite the investigation).

If you do install and use the VS 2010 RC we’d also really appreciate if you would fill out this survey about your experiences.

Answers to a few questions and known issues

Here are a few answers to some questions/known issues:

  • If you have previously installed VS 2010 Beta 2 on your computer you should use Add/Remove Programs (within Windows Control Panel) to remove VS 2010 Beta2 and .NET 4 Beta2 before installing the VS 2010 RC.  Note that VS 2010 RC can be installed on the same machine side-by-side with VS 2008 and VS 2005.
  • Silverlight 3 projects are supported with today’s VS 2010 RC build – however Silverlight 4 projects are not yet supported.  We will be adding VS 2010 RC support for SL4 with the next public Silverlight 4 drop. If you are doing active Silverlight 4 development today we recommend staying with the VS10 Beta 2 build for now.
  • We recently identified a crashing bug that can impact systems that have multi-touch and some screen-readers enabled.  We are working on a patch for people who are impacted by it.
  • We recently found an issue where project upgrades from VS 2008 can take a long time to complete if the project has .xsd files within them.  If you think VS is taking a long time on a project upgrade give it a few more minutes to complete before assuming it has hung – you might be running into this slow upgrade issue.  Note that once the project is upgraded the performance should return to normal. We are working to fix this with the final release.

Hope this helps,

Scott

[Read More]
jQuery 1.4.1 Intellisense with Visual Studio
Published Tue, 09 Feb 2010 06:30:30 GMT

[In addition to blogging, I am also now using Twitter for quick updates and to share links. Follow me at: twitter.com/scottgu]

A few people have emailed me recently asking about the availability of a Visual Studio –vsdoc intellisense hint file for jQuery 1.4.1. 

I blogged about –vsdoc files in the past – they provide additional intellisense help information for Visual Studio, and enable you to get a richer intellisense experience with dynamic Javascript libraries.  If you are using VS 2008 SP1 you’ll want to download and install this patch in order to have VS 2008 automatically use –vsdoc files with intellisense.  VS 2010 has support for –vsdoc files built-in.

jQuery 1.4.1 –vsdoc download

The good news is that you can download –vsdoc files for jQuery directly from the jQuery web-site (look for the “Documentation: Visual Studio” link under each major version).  Here is a direct pointer to the recently released –vsdoc file for jQuery 1.4.1 that you can use.

Hope this helps,

Scott

[Read More]
Built-in Charting Controls (VS 2010 and .NET 4 Series)
Published Mon, 08 Feb 2010 05:54:52 GMT

[In addition to blogging, I am also now using Twitter for quick updates and to share links. Follow me at: twitter.com/scottgu]

This is the fifteenth in a series of blog posts I’m doing on the upcoming VS 2010 and .NET 4 release.  Today’s post covers a nice addition to ASP.NET and Windows Forms with .NET 4 - built-in charting control support.

ASP.NET and Windows Forms Charting Controls

A little over 14 months ago I blogged about how Microsoft was making available a free download of charting controls for both ASP.NET 3.5 and Windows Forms 3.5. 

You can download and use these runtime controls for free within your web and client applications today.  You can also download VS 2008 tooling support for them.  They provide a rich set of charting capabilities that is easy to use.  To get a sense of what all you can do with them, I recommend downloading the ASP.NET and Windows Forms sample projects which provide more than 200 samples within them.  Below is a screen-shot of some pie and doughnut chart samples from the ASP.NET sample application:

image

Charting Controls Now Built-into .NET 4

With .NET 3.5 you had to separately download the chart controls and add them into your application.  With .NET 4 these controls are now built-into ASP.NET 4 and Windows Forms 4 – which means you can immediately take advantage of them out of the box (no separate download or registration required). 

Within ASP.NET 4 applications you’ll find that there is now a new built-in <asp:chart> control within the “Data” tab of the Toolbox:

image

You can use this control without having to register or wire-up any configuration file entries.  All of the charting control configuration is now pre-registered with ASP.NET 4 (meaning nothing has to be added to an application’s web.config file for them to work).  This enables you to maintain very clean and minimal Web.config files.

Learning more about the <asp:chart> control

Scott Mitchell has written a great series of articles on the www.4guysfromrolla.com site on how to take advantage of the <asp:chart> control:

  1. Getting Started - walks through getting started using the Chart Controls, from version requirements to downloading and installing the Chart Controls, to displaying a simple chart in an ASP.NET page.
  2. Plotting Chart Data - examines the multitude of ways by which data can be plotted on a chart, from databinding to manually adding the points one at a time.
  3. Rendering the Chart - the Chart Controls offer a variety of ways to render the chart data into an image. This article explores these options.
  4. Sorting and Filtering Chart Data - this article shows how to programmatically sort and filter the chart's data prior to display.
  5. Programmatically Generating Chart Images - learn how to programmatically create and alter the chart image file.
  6. Creating Drill Down Reports - see how to build drill down reports using the Chart control.
  7. Adding Statistical Formulas - learn how to add statistical formulas, such as mean, median, variance, and forecasts, to your charts.
  8. Enhancing Charts With Ajax - improve the user experience for dynamic and interactive charts using Ajax.
  9. Serializing Chart Data - see how to persist a chart's data and appearance to a persistent store.

His articles are written using .NET 3.5 and the separate ASP.NET charting controls download – but all of the concepts and syntax work out of the box exactly the same with ASP.NET 4.

Michael Ceranski has also written a blog post demonstrating how to use the ASP.NET Chart control within an ASP.NET MVC application.  I’m hoping someone will create some nice ASP.NET MVC Html.Chart() helper methods soon that will make this even easier to do in the future.

Hope this helps,

Scott

[Read More]
ASP.NET MVC 2 (Release Candidate 2) Now Available
Published Fri, 05 Feb 2010 08:44:26 GMT

[In addition to blogging, I am also now using Twitter for quick updates and to share links. Follow me at: twitter.com/scottgu]

Earlier this evening the ASP.NET team shipped ASP.NET MVC (Release Candidate 2) for VS 2008/.NET 3.5.  You can download it here.

The RC2 release of ASP.NET MVC 2 is a follow-up to the first ASP.NET MVC 2 RC build that we shipped in December.  It includes a bunch of bug fixes, performance work, and some final API and behavior additions/changes.  Below are a few of the changes between the RC1 and RC2 release (read the release notes for even more details):

  • The new ASP.NET MVC 2 validation feature now performs model-validation instead of input-validation (this means that when you use model binding all model properties are validated instead of just validations on changed values of a model).  This behavior change was based on extensive feedback from the community.
  • The new strongly-typed HTML input helpers now support lambda expressions which reference array or collection indexes.  This means you can now write code like Html.EditorFor(m=>m.Orders[i]) and have it correctly output an HTML <input> element whose “name” attribute contains the index (e.g. Orders[0] for the first element), and whose “value” contains the appropriate value.
  • The new templated Html.EditorFor() and Html.DisplayFor() helper methods now auto-scaffold simple properties (and do not render complex sub-properties by default).  This makes it easier to generate automatic scaffolded forms.  I’ll be covering this support in a future blog post.
  • The “id” attribute of client-script validation message elements is now cleaner.  With RC1 they had a form0_ prefix.  Now the id value is simply the input form element name postfixed with a validationMessage string (e.g. unitPrice_validationMessage).
  • The Html.ValidationSummary() helper method now takes an optional boolean parameter which enables you to control whether only model-level validation messages are rendered by it, or whether property level validation messages are rendered as well.  This provides you with more UI customization options for how validation messages are displayed within your UI.
  • The AccountController class created with the default ASP.NET MVC Web Application project template is cleaner.
  • Visual Studio now includes scaffolding support for Delete action methods within Controllers, as well as Delete views (I always found it odd that the default T4 templates didn’t support this before).
  • jQuery 1.4.1 is now included by default with new ASP.NET MVC 2 projects, along with a –vsdoc file that provides Visual Studio documentation intellisense for it.
  • The RC2 release has some significant performance tuning improvements (for example: the lambda based strongly-typed HTML helpers are now much faster).

Today’s RC2 release only work with VS 2008 and .NET 3.5.  We’ll shortly be releasing the VS 2010 RC (which will be available for everyone to download). It will include ASP. NET MVC 2 support built-in (no separate download required).

Hope this helps,

Scott

P.S. The source code for the ASP.NET MVC RC2 release (along with a MVC futures library that goes with it) can be downloaded here. You can learn even more about ASP.NET MVC 2 by reading the ASP.NET MVC 2 blog series I’m working on.

[Read More]
Nice “Quick Hit” Videos about ASP.NET 4 and VS 2010
Published Fri, 29 Jan 2010 05:12:41 GMT

[In addition to blogging, I am also now using Twitter for quick updates and to share links. Follow me at: twitter.com/scottgu]

I’ve been working on a series of blog posts the last few months that cover some of the new features coming with .NET 4 and VS 2010.

Earlier today someone pointed me at some nice “quick hit” videos that have been published that also provide quick first looks at some of the new features coming with ASP.NET 4 and VS 2010.  These videos aren’t an exhaustive list of everything new – but do provide a great way to quickly learn about many of the cool new things coming with the release. 

ASP.NET 4 Videos

You can learn more about some of the new ASP.NET 4 features by watching these 22 ASP.NET Quick Hit Videos.

image

VS 2010 Videos

You can learn more about a few of the new VS 2010 features by watching these 8 VS 2010 Quick Hit Videos.

image

ASP.NET Team Member Interviews

In addition to the feature demo videos above, you can also watch these ASP.NET team member interviews done by Scott Hanselman.  In them various ASP.NET team members talk about a few of the new features they’ve worked on.

image 

There are a lot more features coming with .NET 4 and VS 2010 not covered by all of these videos.  But hopefully the above clips provide a good way to quickly get a sense of some of the new capabilities.

Hope this helps,

Scott

[Read More]
Extensible Output Caching with ASP.NET 4 (VS 2010 and .NET 4.0 Series)
Published Thu, 28 Jan 2010 07:27:22 GMT

[In addition to blogging, I am also now using Twitter for quick updates and to share links. Follow me at: twitter.com/scottgu]

This is the fourteenth in a series of blog posts I’m doing on the upcoming VS 2010 and .NET 4 release.  Today’s post covers some of the output caching extensibility improvements being made to ASP.NET 4.  These can be used by all ASP.NET 4 applications – including those built using both ASP.NET Web Forms and ASP.NET MVC.

Output Caching Today

ASP.NET 1.0 introduced the concept of output caching, which enables developers to capture and store the generated output of pages, controls, controllers, and HTTP responses in an in-memory cache.  On subsequent web requests, ASP.NET can then serve content faster by retrieving and using the generated output from the cache instead of having to execute the page/controller to regenerate the output from scratch.  This can dramatically improve the performance of your application – especially in cases where your content is based on data within a database (since when the content is output cached you end up not having to hit the database on subsequent requests).

ASP.NET’s output caching system is flexible enough to enable you to cache different versions of content depending on the querystring/form-post parameters to a page/controller (for example: Browse.aspx?category=Beverages versus. Browse.aspx?category=Meat).  It also enables you to cache different versions based on the browser type or user-language preference of the client visiting your application. This allows you to cache a mobile version of a page separate from a version optimized for a desktop browser, as well as to vary the cache entries based on whether the user wants to read a page in English or French.  You can configure ASP.NET to cache a particular output cache entry for a specific period of time (for example: 1 minute – after which the next request will regenerate the content and cache it again).  You can also configure ASP.NET to dynamically invalidate a cache entry based on an external event (for example: if the database upon which the cached content depends changes). 

One limitation of output caching with ASP.NET V1->V3.5, though, is that the cache store itself is not extensible – and the cached content always has to be stored in-memory.

ASP.NET 4 Output Cache Extensibility

ASP.NET 4 adds an extensibility point to output caching that now enables developers to configure one or more custom output-cache providers. Output-cache providers can use any storage mechanism to persist output cached content. This makes it possible to easily create output-cache providers that store the cached content using any persistence mechanism – including local or remote disks, databases, cloud storage, and distributed cache engines (like memcached or velocity).

You can create a custom output-cache provider by creating a class that derives from the new System.Web.Caching.OutputCacheProvider class in ASP.NET 4.  Within your derived class you then override 4 public methods that provide implementations for adding/removing/retrieving/updating cached content (a unique key is passed to identify each separate cached entry).  You can then configure ASP.NET 4 to use your custom outputcache provider by registering it using the new <providers> subsection of the <outputCache> element within an application’s web.config file:

image

Above I’ve added a new output cache provider (which I’ve named “SampleCache”) that is implemented using the “ScottOutputCache” class within my OutputCacheSample.dll assembly.  I’ve also configured ASP.NET to use my “SampleCache” implementation as the default output cache implementation whenever content is output cached – this is done by setting the “defaultProvider” attribute on the <outputCache> element. 

And now, when I add an OutputCache directive to the top of any of .aspx page the content will be cached and stored using my ScottOutputCache provider:

<%@ OutputCache Duration="60" VaryByParam="None"  %>

Likewise, if I add an [OutputCache] attribute on any action method within an ASP.NET MVC Controller the content will also be cached and stored using my ScottOutputCache provider:

image

Customizing Which Output Cache Provider is Used

Above I configured ASP.NET to by default always cache content using my “SampleCache” provider whenever output caching is used within the application.

As a slightly more advanced option, developers can also configure ASP.NET to dynamically choose which output cache provider to use on a per-request basis.  This is useful for scenarios where you want to have a slightly richer set of cache semantics. For example, you might want to cache the “Home” page or "Top 10" requested pages of a site using the built-in ASP.NET in-memory provider (which will be super fast because the content will be in-memory), and then cache less frequently requested pages that get lower traffic on disk.

You can dynamically indicate which output cache provider to use on a per-request basis by overriding the GetOutputCacheProviderName() method within the Global.asax file of an application.  Below I’m indicating that for the “Home.aspx” page within my application I want to use the built-in in-memory ASP.NET output cache provider – and that I then want to use whatever is registered within the web.config file for every other request:

image

This ability to easily switch between providers depending on scenarios ends up enabling a bunch of really powerful scenarios.

Common Output Cache Providers

We’ll be shipping samples that demonstrate how to implement a disk-based output cache provider that stores cached content on the file-system.  We’ll also be shipping samples that demonstrate how to integrate output caching with the new Windows Server AppFabric Caching Service (formerly known as “Velocity”).  AppFabric’s caching service will be a free, fully supported, Microsoft distributed cache system.  It will also be easy to use the new ASP.NET 4 output caching extensibility with memcached – a popular open source distributed caching system.

You can learn more about how to create providers by watching Stefan Schackow’s ASP.NET 4 Core Runtime talk at PDC 2009.  You can also learn more about AppFabric’s Caching service from this PDC 2009 talk.

Summary

The addition of output-cache provider extensibility to ASP.NET 4 enables developers to easily pursue more aggressive and more intelligent output-caching strategies for web sites and applications.  These can significantly improve the performance and responsiveness of applications, and improve both end-user experiences as well as reduce the amount of server resources required. 

Hope this helps,

Scott

[Read More]
About Technical Debates (and ASP.NET Web Forms and ASP.NET MVC debates in particular)
Published Mon, 25 Jan 2010 00:08:41 GMT

[In addition to blogging, I am also now using Twitter for quick updates and to share links. Follow me at: twitter.com/scottgu]

Technical debates are discussed endlessly within the blog-o-sphere/twitter-verse, and they range across every developer community. Each language, framework, tool, and platform inevitably has at least a few going on at any particular point in time.

Below are a few observations I’ve made over the years about technical debates in general, as well as some comments about some of the recent discussions I’ve seen recently about the topic of ASP.NET Web Forms and ASP.NET MVC in particular.

General Observations About Technical Debates

Below are a few general observations independent of any specific technical debate:

a) Developers love to passionately debate and compare languages, frameworks, APIs, and tools.  This is true in every programming community (.NET, Java, PHP, C++, Ruby, Python, etc).  I think you can view these types of religious technical debates in two ways:

  1. They are sometimes annoying and often a waste of time.
  2. They are often a sign of a healthy and active community (since passion means people care deeply on both sides of a debate, and is far better than apathy).

Personally I think both points are true.

b) There is never only “one right way” to develop something. As an opening interview question I sometimes ask people to sort an array of numbers in the most efficient way they can.  Most people don’t do well with it.  This is usually not because they don’t know sort algorithms, but rather because they never think to ask the scenarios and requirements behind it – which is critical to understanding the most efficient way to do it.  How big is the sequence of numbers? How random is the typical number sequence (is it sometimes already mostly sorted, how big is the spread of numbers, are the numbers all unique, do duplicates cluster together)? How parallel is the computer architecture?  Can you allocate memory as part of the sort or must it be constant?  Etc. These are important questions to ask because the most efficient and optimal way to sort an array of numbers depends on understanding the answers. 

Whenever people assert that there is only “one right way” to a programming problem they are almost always assuming a fixed set of requirements/scenarios/inputs – which is rarely optimal for every scenario or every developer.  And to state the obvious - most problems in programming are far more complex than sorting an array of numbers.

c) Great developers using bad tools/frameworks can make great apps. Bad developers using great tools/frameworks can make bad apps. Be very careful about making broad assumptions (good or bad) about the quality of the app you are building based on the tools/frameworks used.

d) Developers (good and bad) can grow stronger by stretching themselves and learning new ideas and approaches.  Even if they ultimately don’t use something new directly, the act of learning it can sharpen them in positive ways.

e) Change is constant in the technology industry.  Change can be scary.  Whether you get overwhelmed by change, though, ultimately comes down to whether you let yourself be overwhelmed.  Don’t stress about having to stop and suddenly learn a bunch of new things - rarely do you have to. The best approach to avoid being overwhelmed is to be pragmatic, stay reasonably informed about a broad set of things at a high-level (not just technologies and tools but also methodologies), and have the confidence to know that if it is important to learn a new technology, then your existing development skills will mostly transition and help.  Syntax and APIs are rarely the most important thing anyway when it comes to development – problem solving, customer empathy/engagement, and the ability to stay focused and disciplined on a project are much more valuable.

f) Some guidance I occasionally give people on my team when working and communicating with others:

  1. You will rarely win a debate with someone by telling them that they are stupid - no matter how well intentioned or eloquent your explanation of their IQ problems might be.
  2. There will always be someone somewhere in the world who is smarter than you - don’t always assume that they aren’t in the room with you.
  3. People you interact with too often forget the praise you give them, and too often remember a past insult -  so be judicious in handing them out as they come back to haunt you later. 
  4. People can and do change their minds - be open to being persuaded in a debate, and neither gloat nor hold it against someone else if they also change their minds.

g) I always find it somewhat ironic when I hear people complain about programming abstractions not being good.  Especially when these complaints are published via blogs – whose content is displayed using HTML, is styled with CSS, made interactive with JavaScript, transported over the wire using HTTP, and implemented on the server with apps written in higher-level languages, using object oriented garbage collected frameworks, running on top of either interpreted or JIT-compiled byte code runtimes, and which ultimately store the blog content and comments in relational databases ultimately accessed via SQL query strings.  All of this running within a VM on a hosted server – with the OS within the VM partitioning memory across kernel and user mode process boundaries, scheduling work using threads, raising device events using signals, and using an abstract storage API fo disk persistence.  It is worth keeping all of that in mind the next time you are reading a “ORM vs Stored Procedures” or “server controls – good/bad?” post.  The more interesting debates are about what the best abstractions are for a particular problem.

h) The history of programming debates is one long infinite loop – with most programming ideas having been solved multiple times before.  And for what it’s worth – many of the problems we debate today were long ago solved with LISP and Smalltalk.  Ironically, despite pioneering a number of things quite elegantly, these two languages tend not be used much anymore. Go figure.

Some Comments Specific to ASP.NET Web Forms / ASP.NET MVC debates:

Below are a few comments specific to some of the recent debates that I’ve seen going around within the community as to whether a ASP.NET Web Forms or ASP.NET MVC based approach is best:

a) Web Forms and MVC are two approaches for building ASP.NET apps. They are both good choices. Each can be the “best choice” for a particular solution depending on the requirements of the application and the background of the team members involved. You can build great apps with either.  You can build bad apps with either. You are not a good or bad developer depending on what you choose. You can be absolutely great or worthless using both.

b) The ASP.NET and Visual Studio teams are investing heavily in both Web Forms and MVC.  Neither is going away.  Both have major releases coming in the months ahead.  ASP.NET 4 includes major updates to Web Forms (clean ClientIDs and CSS based markup output, smaller ViewState, URL Routing, new data and charting controls, new dynamic data features, new SEO APIs, new VS designer and project improvements, etc, etc).  ASP.NET 4 will also ship with ASP.NET MVC 2 which also includes major updates (strongly typed helpers, model validation, areas, better scaffolding, Async support, more helper APIs, etc, etc).  Don’t angst about either being a dead-end or something you have to change to.  I suspect that long after we are all dead and gone there will be servers somewhere on the Internet still running both ASP.NET Web Forms and ASP.NET MVC based apps.

c) Web Forms and MVC share far more code/infrastructure/APIs than anyone on either side of any debate about them ever mentions - Authentication, Authorization, Membership, Roles, URL Routing, Caching, Session State, Profiles, Configuration, Compilation, .aspx pages, .master files, .ascx files, Global.asax, Request/Response/Cookie APIs, Health Monitoring, Process Model, Tracing, Deployment, AJAX, etc, etc, etc.  All of that common stuff you learn is equally valid regardless of how you construct your UI.  Going forward we’ll continue to invest heavily in building core ASP.NET features that work for both Web Forms and MVC (like the URL Routing, Deployment, Output Caching, and DataAnnotations for Validation features we are adding with ASP.NET 4). 

d) I often find debates around programming model appropriateness and abstractions a little silly. Both Web Forms and MVC are programming web framework abstractions, built on top of a broader framework abstraction, programmed with higher level programming languages, running on top of a execution engine abstraction that itself is running on top of a giant abstraction called an OS.  What you are creating with each is HTML/CSS/JavaScript (all abstractions persisted as text, transmitted over HTTP – another higher level protocol abstraction). 

The interesting question to debate is not whether abstractions are good or not – but rather which abstractions feels most natural to you, and which map best to the requirements/scenarios/developers of your project.

e) We are about to do a pretty major update to the www.asp.net site.  As part of that we will be posting more end to end tutorials/content (for both Web Forms and MVC).  We will also be providing tutorials and guidance that will help developers quickly evaluate both the Web Forms and MVC approach, easily learn the basics about how both work, and quickly determine which one feels best for them to use. This will make it easy for developers new to ASP.NET, as well as developers who already know either Web Forms or MVC, to understand and evaluate the two approaches and decide which they want to use.

f) Decide on a project about whether you want to use Web Forms or MVC and feel good about it.  Both can be good choices.  Respect the choices other people make – the choice they have made is also hopefully a good one that works well for them.  Keep in mind that in all likelihood they know a lot more about their own business/skills than you do.  Likewise you hopefully know a lot more about your own business/skills than they do.

g) Share ideas and best practices with others.  That is a big part of what blogs, forums, listservs and community is all about.  What makes them work great is when people know that their ideas aren’t going to be ripped to shreds, and that they will be treated with respect.  Be constructive, not snarky. Teach, don’t lecture. Remember there is always someone else out there who you can also learn from.

Hope this helps,

Scott

[Read More]