|
|
These blog entries are written by industry experts and leaders. We consider this content to be a good read for any software developer or web technologist.
August 2006 - Posts
-
If you only look at one feature in Windows Workflow, look at the Policy activity. The Policy activity processes rules. Business rules, game rules - any type of declarative knowledge. Read more in the latest OdeToCode article - "Windows Workflow - Rules and Conditions".
The Policy activity is easy to use, and provides a boatload of functionality out of the box. You can prioritize rules, and track rule processing in detail. WF provides an API to modify rules at runtime, which provides a great deal of flexibility. Rules execute with forward chaining semantics, meaning the rules engine analyzes the dependencies and side effects of each rule, and can reevaluate rules when the underlying data changes. I can see applications using Windows Workflow solely for the Policy activity.
More Workflow articles on OTC: Hello, Workflow - an introduction. Authoring Workflows - a look at XAML, XOML, and Workflow compilation. The Base Activity Library - a tour of the out-of-the-box activities in WF. Hosting Windows Workflow - a look at using the persistence, scheduling, tracking, and transaction services in WF. 
|
-
I haven’t talked much about my project here on the blog, but it has been growing and growing over the last year. I am now the lead on a project including three teams and a total of sixteen developers, which can be quite tough to manage. One of the main challenges is ensuring that the code being written is high quality. We use some automated procedures like CruiseControl.NET, FxCop, and Code Coverage and whenever possible the good old fashioned code review.
One of the things that has always bothered me though is compiler warnings, these are simple things that are usually easy to fix and just represent complete laziness when they start cropping up. I would notice these on the build reports and it always drove me crazy. Well, apparently I am the last person to know that you can tell Visual Studio to treat all warnings as errors. A quick change to all of our project files:

and no more warnings (at least not in builds that work).
In the future I will blog more about some of what I have found that works and doesn’t work.
-James ![]()
|
-
Most business books consist of one idea and then around 160–200 pages of fluff talking about how that idea can be used. A business book that actually delivers some sort of value after the second or third chapter is usually a success. I picked up The Art of the Start because I have been reading Guy’s blog recently and the title is pretty irresistible.
I think the title is a little misleading as it really isn’t about starting “Anything”, it’s pretty focused on starting a business and more specifically a technology-oriented business. This is expected considering Guy’s company finances technology companies. The book is filled with a considerable amount of business advice, many of his lists throughout the book contain more good advice than some entire business books in their entirety. It includes a 100 small ideas instead of one big idea.
The book focused a little too much on getting capital, does every successful business need funding? I know of some that get by growing organically, but I don’t think these are the companies that interest a venture capitalist like Guy, or at least not as much as the ones who get funding. The saving grace of all the advice around getting funded is that the advice is often applicable to your business as a whole. I remember one point Guy made that stuck with me was about a common lie:
Lie #6: “Proctor & Gamble is too old, big, dumb, and slow to be a threat.”
I hear this all the time from people on why they are going to be successful, and I always thought it was a little bit naive. Sure, you might be able to carve out a niche market… but to underestimate companies who dominate the market is delusional.
Overall I enjoyed the book and would recommend it to anyone thinking about starting their own small business or project.
-James
![]()
|
-
Congrats to Phil on getting this latest release out. I can’t wait to upgrade this weekend and check out the new features and fixes. He also launched a new skins gallery over at SubTextSkins.com.
-James ![]()
|
-
Workflow is one of the new core capabilities (along with WPF aka Avalon and WCF aka Indigo) being added in the .NET Framework 3.0 release later this year. It provides an in-process workflow engine to process rules, a designer for VS 2005 to enable both developers and non-developers to define custom workflow processes graphically, and a new Workflow namespace to integrate these within code. The official site to learn more about Windows Workflow Foundation can be found here. Over the last two weeks I've also seen a number of great new posts and web-casts published that cover it in more detail. Below is a list of some of them you might want to explore to learn more: Windows Workflow Foundation Basics: .NET Rocks! Audio-Cast: Carl Franklin talks with Michael Stiefel about Windows Workflow Foundation and discusses what it is and why you might want to use. You can listen to this show here. Bart De Smet has a number of great posts that cover some of the core concepts with Windows Workflow Foundation (WF): K. Scott Allen has also posted several good blog posts on Workflow: ASP.NET Page Flow: ASP.NET developers should checkout the ASP.NET: An Overview of ASP.NET and Windows Workflow Foundation Integration web-cast that Kashif Alam from the ASP.NET team did earlier this month. It explores designing and developing UI workflow applications with ASP.NET and how developers will be able to use the new "Page Flow" capabilities that are being added to ASP.NET to enable developers to create representative UI for business processes defined with Windows Workflow Foundation (and avoid hardcoding in workflow logic in code). SharePoint 2007 Custom Workflows: SharePoint 2007 (which is coming out later this year and is built on ASP.NET 2.0) allows users to define and author workflows for common process activities. Sahil has a great blog post here that describes how to use this to define a custom process for a SharePoint site. Hope this helps, Scott P.S. For other great ASP.NET web-casts (both upcoming as well as past ones that have been recorded and published online), please check out this Web Casts listing page on the www.asp.net site.

|
-
The XNA team released their first XNA Game Studio Express Beta release earlier today. You can learn more about it and download it for free here (below is a screenshot from a fun app build with it). This release works on top of the free Visual C# Express Edition, and provides the ability to build games using C# and .NET that target both Windows and the XBOX 360 (we did the work to port a .NET execution engine with PowerPC JIT support to the XBOX to enable this). The XNA Framework ships with the VS package and provides a managed code library for creating rich graphics, and incorporating 3D content into games. I'm looking forward to having some fun with this. :-) You can download it for free here. Enjoy, Scott

|
-
My client has too much work for me to do as they've grown, so we need to bring on someone else to help us out. First and foremost, we need someone very good with MS Sql Server and T-Sql, including procs, dts, jobs, and more. Most of the work can be done remotely, but we also need someone that can help with network/database maintenance. That is not the main responsibility, but it does mean we need someone reasonably close to my client's location, so we need someone that is relatively near the Virginia burbs of Washington DC, or at least willing to relocate. It would also be great if this person was able to work with me on our .NET development, even using my ORMapper. If this describes you, and you're interested, then please send your resume to me at VAJob-at-WilsonDotNet.com. This is a great client to work with, but they're also very busy, so we're only looking for someone very good.

|
-
Next week - Tuesday, September 5th - I'll be speaking at the San Diego .NET Developer group. My talk starts at 7:00pm and will likely run until 8:30 or so. I'll be talking about Working with Data in ASP.NET 2.0, a sort of in-person, spoken and visualized complement to the Working with Data in ASP.NET 2.0 tutorial series I've been writing for Microsoft.
If you're in San Diego on the 5th, drop on by! The meeting is held in Sorrento Valley at one of Qualcomm's facilities, and it's probably the nicest LUG facility I've ever been to - free parking, incredibly nice plush stadium seating... it's like you're in the theaters, except the aisles aren't sticky and I'm not as dashing or exciting as Brad Pitt. But the biggest incentive is that there will be free pizza and soda!!
Hope to see you there!
|
-
This program throws an exception at runtime. If you've been burned by this problem before, you'll know what's wrong before you even see the definition for class Bar...
using System;
class Program { static void Main() { Foo foo = new Bar(); } }
abstract class Foo { public Foo() { Init(); }
protected abstract void Init(); }
class Bar : Foo { string message;
public Bar() { message = "Hello!"; }
protected override void Init() { Console.WriteLine(message.ToUpper()); } }

|
-
I stumbled on a forum posting recently that led me to write the following code:
using System; using System.Threading;
class Program { static void Main() { ThreadStart doNothing = delegate { };
ThreadStart createThreads = delegate { for (int i = 0; i < 50; i++) { Thread t = new Thread(doNothing); t.Priority = ThreadPriority.BelowNormal; t.Start(); } };
for (int i = 0; i < 2; i++) { Thread t = new Thread(createThreads); t.Start(); }
Console.ReadLine(); } }
This program behaves badly on a single processor machine, and pegs the CPU at 100% for over two minutes. On a multi processor machine, the program finishes all the threading work in the blink of an eye - only a brief CPU spike.
Strangely, if I remove a single line of code:
t.Priority = ThreadPriority.BelowNormal;
… then the program performs just as well on a single processor machine (only a brief spike - comparable to the MP scenario).
Could it be a bug? 
|
-
One of the highlights for me of my recent trip to TechEd NZ and Australia was the opportunity I had to create and present a new "Building Data Driven ASP.NET Web Applications using LINQ" talk. LINQ is a super cool new technology, and is going to have an absolutely enormous impact on .NET developers and how they use data. I had a lot of fun doing the talk, and people seemed to really like it (someone told me just before I flew back that it was the most highly rated talk at TechEd this year). You can download the final slides + samples I presented here. The samples use a class library that I built during that talk that encapsulates my LINQ data model classes that go against the Northwind database (please read this post to learn more about how to build a re-usable LINQ class library like this). I also then included 14 separate ASP.NET page samples that show off different concepts within LINQ (starting with LINQ for Objects, then LINQ for SQL, and then LINQ for XML). Update the northwind connectionstring within the web.config file of the web-site to run them against any SQL Northwind sample database instance you have.  Learning more about LINQ To learn more LINQ with ASP.NET, please read these other posts I've done about it: Hope this helps, Scott

|
-
In my previous posts on doing data access using LINQ and ASP.NET, I used the built-in SQLMetal command-line utility to automatically generate the data model classes for my LINQ data classes. Recently I've been using the LINQ for SQL (aka DLINQ) designer to define my data models instead, and have been really impressed with how easily it enables me to build a re-usable class library that nicely encapsulates my data and business logic. The below walkthrough demonstrates how you can get started with it yourself. Simply install the LINQ May CTP download on top of VS 2005, and you can then follow along all of the steps below yourself. For the sample below I am using C#, but everything works equally well in VB as well. Step 1: Create a New LINQ Enabled Class Library Choose File->New Project within Visual Studio and navigate to the "LINQ Preview" node in the project-type tree-explorer. Then select the "LINQ Library" project icon and create a new LINQ enabled class library: This will create a class library project whose MSBuild project file enables compilation support for LINQ. A default "Class1.cs" file is added to the project -- I recommend just deleting it to start with an empty project. Step 2: Add a LINQ for SQL Data Model to the Project Right-click on the project and choose the Add->New Item context menu item. Scroll down in the dialog and select the "DLINQ Object" icon, and give it an appropriate name (in this sample I'm naming it "Northwind" since I'm going to be modeling the Northwind database): This will add a Northwind.dlinq file to your project, and bring up its designer: You can now use the designer to map your data models and entities graphically, as well as setup associations to map relationships between them. Step 3: Quickly creating a Northwind data model One of the really easy ways to quickly define your data model classes is to open up the Server Explorer tab within VS 2005 and connect to your database. You can then drill into the Tables and Views within your database, and drag/drop them from the server explorer onto the DLINQ designer surface to automatically create data models for them. For example, if I dragged/dropped the Suppliers, Customers, Orders, Order Details, and Products tables onto the designer surface, I'd by default get a data model that looks like this: Note how the DLINQ designer automatically sets up default associations between the different entities based on the Primary Key/Foreign Key relationships in the database. These will automatically cause properties to be created on the various data classes so that we can perform rich querying and/or easily traverse between them. For example, if I had a "Customer" instance above I could simply access the "Customer.Orders" property to get a collection of all of that Customer's orders in the database. If you want, you can add, delete or alter these associations by simply clicking on the association links in the designer and then use the property grid to change its settings. For example, if I wanted to modify the "Order Details" associations above to instead be named "OrderDetails", I would click on the association line in the designer and change it either via the property grid: Or because it supports inline editing for the name, just click on the name in the designer and rename it in place: Additionally, I could use the designer to easily rename the entities and/or rename/remove/add properties to them. Once we are done defining your data models, we'll just save the file. The designer will then automatically generate a .cs or .vb file containing the LINQ data class definitions. This is saved in a nested file underneath the Northwind.dlinq item in the solution explorer: The LINQ data model classes created are defined as "partial" classes -- which means we will be able to go in later and add entity and property validation rules that enforce our business logic, as well as add any additional properties or helper methods we want to the classes. Step 4: Creating a LINQ Enabled Web-Site that References our LINQ enabled Class Library We'll now want to go ahead and build a LINQ-enabled ASP.NET web-site that uses our LINQ class library. Choose File->Add->Web Site within Visual Studio to add a new project to the solution. Choose the LINQ web-site template to create an ASP.NET web-site that is enabled with the LINQ compilers: Your VS solution will then look like this: The last two steps you'll want to take are to: 1) Add a project reference from the web-site project to the LINQ class library. To-do this, right-click on the web-site and select "Add Reference", select the "Projects" tab and add the reference as normal. 2) Add a connection-string to your web.config file in the web-site project for the LINQ class library. This will enable you to easily configure and change the connection-string that is used at runtime for the application. Simply copy/paste the connection-string value in the LINQ class library's app.config file to the web.config file's <connectionString> section to configure this. Once the above two steps are done, we are ready to build ASP.NET UI pages against our LINQ class library and associated data models. Step 5: Build a simple Products Listing Page To give a simple taste of using LINQ, we'll build a simple Product Listing page that lists products like the image below: To implement this, I'll add a templated ASP.NET DataList control to the .aspx page using the markup below to define the UI for each product in our list: <asp:DataList ID="DataList1" RepeatColumns="2" runat="server">
<ItemTemplate> <div class="productimage"> <img src="images/productimage.gif" /> </div> <div class="productdetails"> <div class="ProductListHead"> <%#Eval("ProductName")%> </div> <span class="ProductListItem"> <strong>Price:</strong> <%# Eval("UnitPrice", "{0:c}") %> </span> </div> </ItemTemplate>
</asp:DataList> I can then use the below code-behind class to execute a LINQ query against the class library data model we defined in our class library previously to retrieve all of the products in the database supplier by the "Exotic Liquids" supplier and sorted by the product name: using System; using System.Web; using System.Query; using LINQClassLibrary;
public partial class HelloWorld : System.Web.UI.Page { protected void Page_Load() { NorthwindDataContext db = new NorthwindDataContext();
DataList1.DataSource = from p in db.Products where p.Supplier.CompanyName == "Exotic Liquids" orderby p.ProductName select p;
DataList1.DataBind(); } }
Notice above how the LINQ query is strongly-typed, and can incorporate the Product/Supplier entity association we setup earlier (for example: note how the where statement is able to search by the product's Supplier.CompanyName property -- which is stored in the Suppliers table and is linked to the Products table via a primary key/foreign key relationship). This strong typing model means I get compile-time checking of my LINQ queries today, and will get full intellisense support with the new release of Visual Studio. No more runtime SQL syntax errors! And that is it. No additional code required. Step 6: Using Debug Visualizers to inspect what SQL is executed against the database One of the most common questions people wonder when using ORM data frameworks is "so what SQL code is it running under the covers?". LINQ makes it easy to figure this out. Just set a debugging breakpoint on a LINQ expression variable, and you can use a built-in LINQ debugging visualizer to inspect it while debugging. For example, set a breakpoint on the DataList1.DataBind() method above and when it is hit hover your mouse over the DataList1.DataSource property and click the magnifying glass to launch its DLINQ query visualizer: This will bring up a visualizer dialog that displays the SQL statement that LINQ will execute against the database when evaluating that LINQ expression: If you click the "execute" button on the bottom-right you can even test out the query in the debugger and see the exact data that will be returned from it when the supplier name is "Exotic Liquids" is this: This makes it really easy to see the exact SQL that is executed and closely watch what is going on as you modify and refine your LINQ queries. Summary Hopefully the above walkthrough provides a good introduction to some of the cool things you can do with LINQ and the LINQ May CTP version of it. To learn more about LINQ with ASP.NET, please checkout the post I am going to be doing in a few minutes which links to a bunch of good resources and which includes the sample I used above. Hope this helps, Scott

|
-
In my previous posts on doing data access using LINQ and ASP.NET, I used the built-in SQLMetal command-line utility to automatically generate the data model classes for my LINQ data classes. Recently I've been using the LINQ for SQL (aka DLINQ) designer to define my data models instead, and have been really impressed with how easily it enables me to build a re-usable class library that nicely encapsulates my data and business logic. The below walkthrough demonstrates how you can get started with it yourself. Simply install the LINQ May CTP download on top of VS 2005, and you can then follow along all of the steps below yourself. For the sample below I am using C#, but everything works equally well in VB as well. Step 1: Create a New LINQ Enabled Class Library Choose File->New Project within Visual Studio and navigate to the "LINQ Preview" node in the project-type tree-explorer. Then select the "LINQ Library" project icon and create a new LINQ enabled class library: This will create a class library project whose MSBuild project file enables compilation support for LINQ. A default "Class1.cs" file is added to the project -- I recommend just deleting it to start with an empty project. Step 2: Add a LINQ for SQL Data Model to the Project Right-click on the project and choose the Add->New Item context menu item. Scroll down in the dialog and select the "DLINQ Object" icon, and give it an appropriate name (in this sample I'm naming it "Northwind" since I'm going to be modeling the Northwind database): This will add a Northwind.dlinq file to your project, and bring up its designer: You can now use the designer to map your data models and entities graphically, as well as setup associations to map relationships between them. Step 3: Quickly creating a Northwind data model One of the really easy ways to quickly define your data model classes is to open up the Server Explorer tab within VS 2005 and connect to your database. You can then drill into the Tables and Views within your database, and drag/drop them from the server explorer onto the DLINQ designer surface to automatically create data models for them. For example, if I dragged/dropped the Suppliers, Customers, Orders, Order Details, and Products tables onto the designer surface, I'd by default get a data model that looks like this: Note how the DLINQ designer automatically sets up default associations between the different entities based on the Primary Key/Foreign Key relationships in the database. These will automatically cause properties to be created on the various data classes so that we can perform rich querying and/or easily traverse between them. For example, if I had a "Customer" instance above I could simply access the "Customer.Orders" property to get a collection of all of that Customer's orders in the database. If you want, you can add, delete or alter these associations by simply clicking on the association links in the designer and then use the property grid to change its settings. For example, if I wanted to modify the "Order Details" associations above to instead be named "OrderDetails", I would click on the association line in the designer and change it either via the property grid: Or because it supports inline editing for the name, just click on the name in the designer and rename it in place: Additionally, I could use the designer to easily rename the entities and/or rename/remove/add properties to them. Once we are done defining your data models, we'll just save the file. The designer will then automatically generate a .cs or .vb file containing the LINQ data class definitions. This is saved in a nested file underneath the Northwind.dlinq item in the solution explorer: The LINQ data model classes created are defined as "partial" classes -- which means we will be able to go in later and add entity and property validation rules that enforce our business logic, as well as add any additional properties or helper methods we want to the classes. Step 4: Creating a LINQ Enabled Web-Site that References our LINQ enabled Class Library We'll now want to go ahead and build a LINQ-enabled ASP.NET web-site that uses our LINQ class library. Choose File->Add->Web Site within Visual Studio to add a new project to the solution. Choose the LINQ web-site template to create an ASP.NET web-site that is enabled with the LINQ compilers: Your VS solution will then look like this: The last two steps you'll want to take are to: 1) Add a project reference from the web-site project to the LINQ class library. To-do this, right-click on the web-site and select "Add Reference", select the "Projects" tab and add the reference as normal. 2) Add a connection-string to your web.config file in the web-site project for the LINQ class library. This will enable you to easily configure and change the connection-string that is used at runtime for the application. Simply copy/paste the connection-string value in the LINQ class library's app.config file to the web.config file's <connectionString> section to configure this. Once the above two steps are done, we are ready to build ASP.NET UI pages against our LINQ class library and associated data models. Step 5: Build a simple Products Listing Page To give a simple taste of using LINQ, we'll build a simple Product Listing page that lists products like the image below: To implement this, I'll add a templated ASP.NET DataList control to the .aspx page using the markup below to define the UI for each product in our list: <asp:DataList ID="DataList1" RepeatColumns="2" runat="server">
<ItemTemplate> <div class="productimage"> <img src="images/productimage.gif" /> </div> <div class="productdetails"> <div class="ProductListHead"> <%#Eval("ProductName")%> </div> <span class="ProductListItem"> <strong>Price:</strong> <%# Eval("UnitPrice", "{0:c}") %> </span> </div> </ItemTemplate>
</asp:DataList> I can then use the below code-behind class to execute a LINQ query against the class library data model we defined in our class library previously to retrieve all of the products in the database supplier by the "Exotic Liquids" supplier and sorted by the product name: using System; using System.Web; using System.Query; using LINQClassLibrary;
public partial class HelloWorld : System.Web.UI.Page { protected void Page_Load() { NorthwindDataContext db = new NorthwindDataContext();
DataList1.DataSource = from p in db.Products where p.Supplier.CompanyName == "Exotic Liquids" orderby p.ProductName select p;
DataList1.DataBind(); } }
Notice above how the LINQ query is strongly-typed, and can incorporate the Product/Supplier entity association we setup earlier (for example: note how the where statement is able to search by the product's Supplier.CompanyName property -- which is stored in the Suppliers table and is linked to the Products table via a primary key/foreign key relationship). This strong typing model means I get compile-time checking of my LINQ queries today, and will get full intellisense support with the new release of Visual Studio. No more runtime SQL syntax errors! And that is it. No additional code required. Step 6: Using Debug Visualizers to inspect what SQL is executed against the database One of the most common questions people wonder when using ORM data frameworks is "so what SQL code is it running under the covers?". LINQ makes it easy to figure this out. Just set a debugging breakpoint on a LINQ expression variable, and you can use a built-in LINQ debugging visualizer to inspect it while debugging. For example, set a breakpoint on the DataList1.DataBind() method above and when it is hit hover your mouse over the DataList1.DataSource property and click the magnifying glass to launch its DLINQ query visualizer: This will bring up a visualizer dialog that displays the SQL statement that LINQ will execute against the database when evaluating that LINQ expression: If you click the "execute" button on the bottom-right you can even test out the query in the debugger and see the exact data that will be returned from it when the supplier name is "Exotic Liquids" is this: This makes it really easy to see the exact SQL that is executed and closely watch what is going on as you modify and refine your LINQ queries. Summary Hopefully the above walkthrough provides a good introduction to some of the cool things you can do with LINQ and the LINQ May CTP version of it. To learn more about LINQ with ASP.NET, please checkout the post I am going to be doing in a few minutes which links to a bunch of good resources and which includes the sample I used above. Hope this helps, Scott

|
-
Joe Stagner has been busy at work publishing more Atlas videos on the www.asp.net website (click here for the full video listing).
Here are a few pointers to some of the recent Atlas videos he has posted: - Add "Atlas" features to an existing ASP.NET web application: Learn how to easily add Atlas functionality to an existing ASP.NET application, and demonstrates how to add the Atlas assembly and configure it within a site (4 minutes, 33 seconds). - Implement Dynamic Partial-Page Updates using Atlas: Learn how to to use the Timer control in Atlas to dynamically refresh portions of an ASP.NET page (5 minutes, 31 seconds). - Using the Atlas Control Toolkit Cascading Dropdownlist Extender: Learn how to implement cascading drop-downlist UI with Atlas server controls, which enables you to have drop-down lists depend on values in another drop-down list on the client without requiring any postbacks to occur (19 minutes, 9 seconds). - Make Client-Side Network Callbacks with Atlas: Learn how Atlas makes it easy to make network callbacks from the client to the server and provides a rich JSON networking stack (11 minutes, 33 seconds). - Atlas Enable Existing Web Services: Learn how to add JSON networking support to your existing web services, and easily create JavaScript client proxies that can invoke and call them (6 minutes, 20 seconds) - Using the Atlas Control Toolkit Popup Control Extender: Learn how to use the Popup Control Extender to enable Ajax popup UI (10 minutes, 19 seconds) - Using the Atlas Control Toolkit TextBoxWatermark Control Extender: Learn how to easily add watermark support to input controls on your site (4 minutes, 52 seconds long). In addition to the above new videos, you can also check out these two to help get you started: - Getting Started with "Atlas": This video demonstrates how to install Atlas for the first time and build your first site with it (10 minutes, 2 seconds). - Getting Started with the Atlas Control Toolkit: This video demonstrates how to install and use the Atlas Control Toolkit suite of additional Atlas controls in your site (12 minutes, 9 seconds). Also -- to learn more about the most recent Atlas CTP and Atlas Control Toolkit release, please check out this post of mine from two weeks ago that covers more. Hope this helps, Scott

|
-
On Saturday, September 23rd, I'll be speaking at the SoCal .NET Technical Summit in Irvine, CA at the Hilton next to the John Wayne Airport. I'll be doing a “Top 10 ASP.NET 2.0 Tips & Traps” talk, which makes me the biggest Scott Guthrie/Rob Howard fanboy (Scott recently presented an ASP.NET Tips and Tricks talk at TechEd in New Zealand, and Rob Howard's done a “Top 10 Tips for Writing High Performance Websites” talk before).
Anywho, the reason I'm posting this is two-fold. First, I want you to come to the Summit! Yes, I'm talking to you. Come on, go, it will be a day full of fun and educational value, with talks broken down into Architecture, Web, Data, and .NET 3.0 tracks. It's only $79 for the conference. Go ahead and register now.
Second, I'd like to get some feedback/suggestions on my talk. Here are my proposed Top 10 Tips & Traps:
- TIP: Use HttpContext.Items as a per-request cache (stole this shamelessly from Rob Howard's performance talk, but it's my favorite of his)
- TRAP: Not setting applicationName setting when using Membership (a trap many people getting started with Membership fall into)
- TIP: A walkthrough of cool Visual Studio 2005 features (I'm thinking about some of the XHTML validation stuff, code snippets, opening an ASP.NET 2.0 website through the command line/Explorer, etc.)
- TIP: Client-side enhancements (the new OnClientClick property, the Focus() method, etc.)
- TIP: Efficiently paging through large resultsets with SQL Server 2005's new ROW_NUMBER() feature
- TIP: Using Reflector (not really ASP.NET-specific, but a tool/knowledgeset every .NET developer should have)
- TRAP: How to handle broken images/links in images, CSS files, etc. A common problem when using a Master Page in one folder and having ASP.NET pages in different folders. In short, use ~
- TIP: Disabling view state for data Web controls to reduce page bloat
- TIP: Use caching. An overview of data caching, output caching, and SQL-dependent caching
- TRAP: Avoid race conditions when caching - see http://scottonwriting.net/sowblog/posts/1982.aspx
I'm a little wishy-washy on some of these, this list was what I came up with a couple days ago. Care to help me shore up this list? Any suggestions for tips/traps? Any tips/traps you'd prefer removed, or relegated to “Only cover if you have adequate time?”
Any suggestions, comments, ideas, and constructive criticism is most welcome. You can either post it as a comment here, or drop me a line at mitchell@4guysfromrolla.com
Hope to see you at the SoCal .NET Technical Summit!
|
-
The WF discussion that Brian Noyes kicked off continues with excellent points from Jon Flanders and Thomas Restrepo. The following posts are full of information from smart people who know WF very well:
You have to understand a technology to use it effectively… Workflow Complexity Workflow Complexity Part 2
Tech evangelist Matt Winkle then asked how to improve WF. In other words - quit bitching and offer us constructive ideas.
If I had a $100 budget to improve WF, I'd divide the money as follows:
$30 on designer improvements. The designer has a number of minor irritations, but one stands out at this very moment. Building declarative rules requires me to navigate a number of modal dialogs, and those dialogs prevent me from getting anywhere else in Visual Studio. When I double-click a .rules file, or ask for a new rule in the properties windows, I want a spiffy designer to appear in the editor. Each time a modal dialog appears in Visual Studio, another star falls from the heavens.
$30 on guidance. Simon Ince threw out the idea of a workflow factory / guidance toolkit. I'd also like to see more content covering common workflow patterns and best practices for hosting, versioning, and scaling.
$30 on "activity packs". Incrementally augment the base activity library with "activity packs". Microsoft could make activity packs available for download as they are developed and in-between major releases of WF. Each activity pack could cover a specific technology domain. Examples: a database activity pack, a WCF activity pack, a file system activity pack, and an XML activity pack. We could download just the activity packs we need.
$10 on an open source base activity library.WF will really shine in scenarios where domain specific activities are available (look at casey's article with a Speech Server workflow to see the flexibility and power of WF). First, however, a team has to build good looking and well-behaved domain specific activities. As Thomas says in his post - "Creating new activities is easy. Creating good activities can be pretty hard." The WF site already includes a number of custom activities, but activities are the lifeblood of WF, and we can always use more.
Earlier this year, the ASP.NET team released source code for all the built-in ASP.NET 2.0 providers, so this idea isn't unthinkable. Providing source and documentation for the BAL would be a tremendous boon for custom activity development. 
|
-
Many thanks to everyone in New Zealand who attended my "ASP.NET 2.0: Tips and Tricks" talk this morning. You can download the slides + samples from my talk here. The samples are number in numbered order and correspond to the slides: Enjoy! Scott P.S. I will also be posting the slides+samples from my LINQ talk a little later today (I first need to jump on a plane to Australia and am running out of time <g>). So stay tuned for those as well.

|
-
The Internet Explorer team maintains a really good blog here: http://msdn.blogs.com/ie that I recommend subscribing to for useful information. They recently posted a good blog post detailing some of the CSS changes that have been made with IE 7.0 to enable it to handle CSS better. This is worth bookmarking if/when you are testing your site with IE7 going forward. Hope this helps, Scott

|
-
Many thanks to everyone in New Zealand who attended my "ASP.NET: End-to-End - Building a Complete Web Application Using ASP.NET 2.0, Visual Studio 2005, and IIS7 (Parts 1 and 2)" talk this afternoon. You can download the slides from my talk here. You can then download the application I built here (note: this .zip file is actually the version I published after the US TechEd, but is the same code I wrote on stage today). There is a "ReadMe.txt" file in the root of the demos .zip file that walksthrough how to setup the demos. I've included two versions of the app -- one is in the "IIS7" directory and allows you to run the application using IIS7 on Windows Vista Beta2. The other is a slightly modified version of the sample that also works on IIS5, IIS6, and the built-in VS 2005 Web Server. The difference is that the non-IIS7 version doesn't use URL-rewriting for the pretty-URL feature. Hope this helps, Scott

|
-
When Windows Live Writer first came out I had the idea that I should do an extension for Firefox that would allow you to easily blog the page you are on. Similar to the one I built for BlogJet. The problem is that instead of command line switches like BlogJet you have to use a COM interface. I couldn’t find an easy way to call the interface directly from Firefox without writing some XPCOM, which I was about to try. But thankfully Can Erten beat me to it and came up with a different solution. The Live WriterFox extension does exactly what I need it to, and instead of using XPCOM he simply wrote a command-line exe that is packaged with the extension to call the COM interface. Brilliant!
I am still trying out Windows Live Writer as well as the Performancing extension for Firefox as alternatives to BlogJet. Performancing seems to offer some cool added features like blog stats and notes, but I think I will stick with BlogJet for now.
-James ![]()
|
-
-
As Jim states Windows Developer Power Tools has officially gone to production, you can even grab a couple chapters over here. We have one more phase of the book where we answer any questions they have and make sure the figures got in correctly, etc.
Having the book out the door is a huge relief and will let me return to some semblance of normal life. Next goal is Zero Email Bounce, then I can start to tackle the book website and a couple other projects. (including tons of house work that has gone un-finished all summer)
-James ![]()
|
-
While procrastinating from finishing up my TechEd talks in my hotel room here in NZ, I came across this really funny link of a Microsoft UK employee's "Ten Worst Presentation Moments" that had me laughing out loud. One of my own "interesting experiences" occurred about 9 years ago at a PDC conference. It was the first time I had ever presented as a Microsoft employee, and it was to ~2400 people. I was doing a joint-presentation with another presenter and the plan was that he'd present the first part of the talk for 60 minutes, and then I'd do the second part of it for another 30 minutes. When we got going he unfortunately got spooked, though, and starting speaking super, super, super fast. After watching this awhile I tried to help calm him down by subtly passing him a note that said "you are going too fast -- slow down". Unfortunately he misread it as "you are not going fast enough -- speed up" -- at which point his pace (which was already so fast you could barely understand anything) really, really increased. It got to the point where he was spending no more than 2-4 seconds on a slide (and even skipping over some to save time). Finally he got to the end-slide of his presentation, apologized profusely to the audience that he had run so late, and handed it over to me. We were 9 minutes into the presentation. The next 81 minutes was a very, very long time for me. :-) Scott P.S. Now I need to go back to work and finish up my LINQ presentation for Tuesday....

|
-
My latest set of Working with Data in ASP.NET 2.0 tutorials focused on paging and sorting data and included a look at implementing custom paging (with sorting) with the GridView and ObjectDataSource. Alert reader Mark Fox pointed out that there's a bit of a problem when using custom paging and clicking the Last page link in the paging interface:
For lesson 25 – Efficient Paging I downloaded the file ASPNET_Data_Tutorial_25_VB.exe and than opened the project in VS 2005 Standard and ran PagingAndSorting/EfficientPaging.aspx. Clicking the PageLast >> button in GridView1’s pager gives a System.OverflowException in System.Web.UI.WebControls.GridView.CreateDataSourceSelectArguments().
Enabling the viewstate in GridView1 fixes this.
With custom paging, the page count value returned by the ObjectDataSource’s SelectCountMethod is stored in the GridView’s view state. Other GridView variables – the PageIndex, EditIndex, SelectedIndex, DataKeys collection, and so on – are stored in control state, which is persisted regardless of the value of the GridView’s EnableViewState property. Since the PageCount value is persisted across postbacks using view state, when using a paging interface that includes a link to take you to the last page, it is imperative that the GridView’s view state be enabled. (If your paging interface does not include a direct link to the last page, then you may disable view state.)
Clicking the last page link causes a postback and instructs the GridView to update its PageIndex property. If the last page link is clicked, the GridView assigns its PageIndex property to a value one less than its PageCount property. With view state disabled, the PageCount value is lost across postbacks and the PageIndex is assigned the maximum integer value instead. Next, the GridView attempts to determine the starting row index by multiplying the PageSize and PageCount properties. This results in an OverflowException since the product exceeds the maximum allowed integer size.
To see the problem in code, use Reflector and drill into the GridView's HandleEvent method. There you'll find a switch statement that handles the different types of events, one of them being when the last page link is clicked:
if (base.IsViewStateEnabled) { num1 = this.PageCount - 1; } else { num1 = 0x7fffffff; }
So if view state has been disabled, then num1 (the page the GridView is going to try to access) is set to the maximum integer value (2.147 billion, roughly). Next, look in the GridView's CreateDataSourceSelectArguments() method, and there you'll find:
arguments1.StartRowIndex = this.PageSize * this.PageIndex;
That multiplication right there is what causes the OverflowException, as any PageSize value greater than 1 will result in a value that exceeds the largest possible integer value.
The fix? Enable view state in your GridView so that the PageCount property can be remembered across postbacks.
|
-
Brian Noyes' post "Understanding Windows Workflow and its complexities" has me thinking.
I know a few people who have given up on Windows Workflow altogether. WF imposes its own paradigm. If your way of thinking is different from the WF way of thinking, you are going to live in a house of pain.
Brian's first complaint is about the designer. I've found the designer to be clunky. There are behaviors you come to expect in Visual Studio, like being able to double-click somewhere and have the designer perform some work. The WF designer never acts intuitively. There are also places where the behavior seems inconsistent - some properties permit data binding and some properties do not. It's not until you learn about dependency properties and meta-properties that this behavior make sense.
Brian's third point was about the HandleExternalEvent activity. Setting up communications between a workflow and its host is a tremendous amount of work, and it's easy to get wrong (a working title for my InfoQ article was "How To Screw-up the HandleExternalEvent activity"). The work doesn't payoff until you see an event arrive for a workflow that has been living in a database table for 8 days. The runtime can re-load the correct workflow and still deliver the event! It's amazing to see this happen, but requires a lot of work to get there.
There are some common gotchas in WF programming:
1) Spawned execution contexts. The rule is that an activity executes once and only once. If you write code that forgets this rule, it's going to hurt!
2) Serialization. You don't need database persistence to see exceptions from the BinarySerializer - spawned execution contexts also make a deep copy of activities using serialization. Make sure those custom properties are serializable!
3) Transactions. It's easy to get MSDTC involved in heavy duty transactions with WF. Just using a persistence service and transactional tracking service at the same time will get the DTC involved (unless a special SharedConnectionWorfklowCommitWorkBatchService is added to the runtime). Something makes me nervous when a class name has 46 characters.
WF isn't as easy as it first appears. It's powerful, but requires an investment of time. 
|
-
For those who don't like the "Attach To Process" dialog box, just pass the application pool name to this Powershell function:
function debug-wp([string]$name) { if([String]::IsNullOrEmpty($name)) { throw "Usage: debug-wp -Name "<appPoolName>" }
$wplist = get-wmiobject Win32_Process -f "Name='w3wp.exe'" foreach($wp in $wplist) { if($wp.CommandLine -match "-ap `"(.+)`"") { if($name -eq $matches[1]) { & vsjitdebugger.exe -p $wp.ProcessID break } } }
if($name -ne $matches[1]) { write-host "Could not find AppPool" $name } }

|
-
One scenario that many large development teams often ask me about is whether it is possible to split up/partition an ASP.NET web application into multiple projects within Visual Studio. The goal with doing this is typically to improve the modularity of large sites and/or to improve the IDE compile-time performance for large projects. VS 2003 supported splitting up a large site into multiple projects, although it is non-trivial to setup and manage. With the VS 2005 Web Application Project option that we released earlier this spring, it is now pretty easy to set this up and manage it using VS 2005.
Omar Khan (the Group Program Manager for the VS 2005 Web Tools) has published two really great walkthrough posts that describe step-by-step how to setup Sub Web Projects using VS 2005: -- Creating Sub-Projects in IIS using VS 2005 Web Application Projects: This post describes the basics of how to setup a multi-project solution that builds a single ASP.NET 2.0 application. -- Creating Shared User Controls and Master Pages with Sub Projects: This post describes how to define master-pages and user controls within a root web project, and the use them within sub-projects in the application. The above two posts show how to use sub-projects with IIS. Omar's next post in the series will also then cover how to use the same technique with the built-in VS 2005 web-server. One question I still get asked a lot is what is "the recommended" web project approach to take with VS 2005 -- use the VS 2005 Web Site Project option or the VS 2005 Web Application Project option? The answer is "it depends on your style of working" - there is really no one single recommended way. Some people love the web-site project model option; others think we were nuts and the web application project model option is the only way to go. The reality is that both options are fully supported (meaning you can call up product support and ask for help or hotfixes), both will ship built-in to Visual Studio releases going forward (the web application project option will be included in SP1), and both are perfectly fine options to use depending on your personal preference and application structure. Two articles you might find useful to debate this topic more is this MSDN whitepaper that includes some comparisons between the two models, and Rick Strahl's Web Application Projects and Web Deployment Projects are Here article that also was published in the Code Magazine and which provides a good discussion of the pros/cons of the different options. Hope this helps, Scott P.S. Please visit this page to read more articles in my "ASP.NET 2.0 Tips, Tricks, and Gotchas" series.

|
-
Earlier this week the Windows Live team released the new Windows Live Writer blog posting and management tool that you can download and use for free. It is a desktop application that provides a really nice editing environment for writing blog posts (spell checker, layout manager, offline editing support, etc). Best of all, Windows Live Writer works with pretty much any server blog software out there, including Community Server (which is the excellent blog software I use to host this blog). This is actually my first post using the Windows Live Writer application with it. :-) Eric Cherng has put together a really nice Windows Live Writer walkthrough that shows off how to install and use it to write your first blog post. You can checkout his post on how to-do this here. One of the cool things about the application is that it is written using .NET, and it exposes a nice .NET extensibility model for creating plugins. It has only been out a few days, but already there are some really cool extensions built by the .NET community appearing. Keyvan Nayyeri has a nice post on how he built a tagging plugin that you can read here. Tim Heuer has created two new CodePlex source projects for a flickr and tagging plugin that you can download and read about here. Fun stuff! Scott

|
-
I’m about to take off for a whirlwind business trip the next 10 days – and email and blog comment responses will unfortunately be very slow while I'm away. I’ll be traveling to New Zealand and Australia for their TechEd events next week. I’m doing 1 keynote presentation, 2 panels, and 8 breakout talks next week – which leave me fairly busy. My last talk is from 9:00-10:30am next Friday in Sydney, at which point I jump in a cab and head to the airport for a 2pm flight to San Francisco. Because of the time-change I get to go back in time, and actually arrive at 10am the same day. I’m then getting a rental car and driving north to Sebastopol (in Marin County) for Tim O’Reilly’s FOO camp event over the weekend. I then fly home on the Sunday. Please forgive any delays in me getting back to you while I’m away – it is going to be a pretty busy trip! Thanks, Scott P.S. If you are attending TechEd New Zealand or Australia, definitely stop by and say hi. I've never been to either country and am really looking forward to visiting.

|
-
-
I have had Sirius since the beginning of the year (mostly for Howard) but recently decided to see if they had a decent indie station. Left of Center is possibly the best station I have ever listened to, it may even replace 97X as my favorite station to stream.
Right now I am listening to “Blog Radio” by Brooklyn Vegan. He is playing nothing but Merge Records songs tonight, just finished playing one of my favorite Spoon songs and went right into some NMH.
-James ![]()
|
-
-
Four new “Working with Data in ASP.NET 2.0” tutorials are now available online at www.asp.net. These four tutorials illusrate how to add paging and sorting capabilities to the GridView and ObjectDataSource, showing how to page and sort naively, as well as how to use the more efficient custom paging technique. There's also a tutorial on creating a more customized sorting user interface.
Like the previous 23 tutorials, these four are each available in C# and VB versions, can be downloaded as PDFs, and have their complete source code available for download as a ZIP file.
Check 'em all out - http://www.asp.net/Learn/DataAccess
|
-
Here is a Visual Basic program with bowling scores in a multi-dimensional array. Two players bowled three games each. The program tries to display the total score for each bowler, but has a small problem. Can you spot it?
Module Module1
Sub Main()
Dim allScores As Integer(,) = _ {{101, 128, 143}, {123, 115, 116}}
' for each player For i As Integer = 0 To allScores.GetUpperBound(0)
Dim score As Integer
' for each game For j As Integer = 0 To allScores.GetUpperBound(1) score = score + allScores(i, j) Next
Console.WriteLine("Player {0} score: {1}", i + 1, score)
Next
End Sub
End Module

|
-
It’s been a rough couple months. The book has been taking much more of my time than I thought it would be at this point, but thankfully we are hitting the final stretch. This weekend we finished the last of the technical reviews and are doing the final “scrub” before sending them off to production. Of course after production we will have to go through them once more, but most of the content is pretty locked down at that point.
The next project on the horizon is the site for the book. I want to do something even more than visualstudiohacks.com (which has also been neglected of late) for this book, I have a plethora of ideas floating around in my head so we will see which ones I have time to implement by November.
I am genuinely looking forward to writing some code. Most of my time at work these days is spent talking with the business, assigning tasks, answering questions, debugging tough issues, etc. that I rarely get to write code. Usually I get to spend some time coding in my off-time, but that has been consumed by the book.
-James ![]()
|
-
One interesting facet to Windows Workflow is how I can combine procedural knowledge with declarative knowledge. Procedural knowledge is the "how-to" knowledge of performing a task. If a bank requires me to make three web service calls to process a payment, I can arrange those three calls inside a Sequence activity and model the exact ordering of calls required by the bank.
WF also provides a Policy activity to process declarative knowledge. Declarative knowledge is the knowledge of facts and relationships between data. Instead of "how-to" knowledge, declarative knowledge provides the "what-is" knowledge. For example, if I want to expedite a payment, the bank will charge me an extra 3%. "All bankers are thieves" would be another piece of declarative knowledge.
Rules engines are pieces of software specialized for processing declarative knowledge. There are a few .NET rules engines around. The most recent entry, as I found out from Larry Obrien's blog, is Drools.NET. BizTalk Server also provides a rules engine, and Charles Young has a good overview of Biztalk rule processing versus Windows Workflow rule processing.
There are some great "rules-centric" Windows Workflow samples on netfx3.com. Samples include a rules driven user interface, rules in Microsoft Excel, how to use an external ruleset (think of rules stored in a database), and more. 
|
-
My ninth Toolbox column in the September 2006 issue of MSDN Magazine is now avaiable online. The September issue examines three products:
- Fast-Help (version 4.4) - quickly and easily create help documentation that can be saved as WinHelp, HtmlHelp, PDF, Word, or web page-based help files.
- FinalBuilder (version 4.1) - organize and manage your build process using FinalBuilder's intuitive user interface.
- XHEO|Licensing (version 2.1) - protect your intellectual property by adding copy protection to your applications. With XHEO|Licensing, you can protect .NET applications using a variety of licensing schemes (serial numbers, online registration, and so on).
This month's issue reviewed Joel Spolsky's The Best Software Writing I anthology, which is a collection of essays pertinent to developers and project managers. It's quite similar to Spolsky's previous work, Joel on Software (which I blogged about earlier). Here's an excerpt from the review:
While the articles about computer science fundamentals, software design, testing, and project management are to be expected, there are also interesting pieces on topics secondary to actual development, but important to developers nevertheless. One essay, written by a developer's spouse, lambastes the short-sighted corporate policies instituted by her husband's employer; another ruminates on intellectual property rights and how it affects us all.
The title - The Best Software Writing I - rings with a tinge of hyperbole since the essays considered for inclusion were restricted to those written in the past two years. But all of the essays included were very interesting, well-written pieces. They range in length from a single page to over a dozen, but even the longer ones seem to end too soon. Joel's introductions to each essay also add color to the collection.
As always, if you have any suggestions for products or books to review for the Toolbox column, please send them into toolsmm@microsoft.com
You can keep abreast of the latest Toolbox articles through the column's RSS feed or the Toolbox column category here on my blog.
|
-
Problem: You are developing/maintaining an ASP.NET web-site, and would like the ability to conditionally show/hide runtime error messages depending on who the user visiting the site is. For a normal user visiting the site you want to be able to display a friendly error message like this when a runtime error occurs:
But when someone within the “developers” security role of your application remotely accesses the site you want to instead show a more detailed exception stack trace error message about the problem without having to change any configuration data:
The below post describes how to use ASP.NET’s role-based security architecture in conjunction with the Global.asax Application_Error event handler to enable this. You can also download a sample I’ve built that shows how to implement this here. Some Background Discussion on Error Handling and ASP.NET Custom Error Pages: ASP.NET and .NET support a rich error-handling architecture that provides a flexible way to catch/handle errors at multiple levels within an application. Specifically, you can catch and handle a runtime exception with a class, within a page, or on the global application level using the Application_Error event handler within the Global.asax class. If a runtime exception isn’t handled/cancelled by one of these mechanisms, then ASP.NET’s Custom Error Page feature will kick-in, and an error page will be sent back to the browser accessing the application. ASP.NET’s Custom Error Page feature can be used to configure a “friendly error page” to be displayed to end-users in place of the standard “server error occurred” message sent back by ASP.NET. For example, the below web.config file section will cause remote users visiting the site to be redirected to a “friendlyErrorPage.htm” file anytime a runtime error occurs (note: HTTP 500 status code responses indicate runtime errors on the server): <customErrors mode="RemoteOnly"> <error statusCode="500" redirect="friendlyErrorPage.htm"/> </customErrors> To learn more about how the ASP.NET Custom Errors feature works, and how to configure it, please review this article. Important: I would recommend never setting the <customErrors> mode attribute to “Off”. Doing this will cause detailed error messages to be sent back to all normal users visiting your site. This can lead to information disclosure issues that can compromise the security of your site. Instead, only change this setting to “On” or “RemoteOnly” (the default) and use the technique below for cases where you want to display detailed error messages to only some users. Solution: The above <customErrors> configuration section will cause a friendly error message to be sent to the browser anytime a runtime error message occurs. This is what we want to happen anytime a normal user access the site, and will allow us to display error pages like this:
To enable developers to instead see detailed error messages when they access the site, I can then add this code to the Application_Error event handler within the Global.asax class: Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs) If (Context IsNot Nothing) And (Context.User.IsInRole("Developer")) Then Dim err As Exception = Server.GetLastError() Response.Clear() Response.Write("<h1>" & err.InnerException.Message & "</h1>") Response.Write("<pre>" & err.ToString & "</pre>") Server.ClearError() End If End Sub The above code checks to see if the current user visiting the site is within a specific security role. If so, then it retrieves the exception raised during the current request via the Server.GetLastError() method. It then clears out any content already generated during the current request, and instead outputs the Exception details to the response. Lastly, it clears out the Exception from the request – which will prevent ASP.NET’s custom error architecture from kicking in. The result instead is a page that details the error like so:
To learn more about how you can easily create and manage a “Developer” role like the one I’m using above, please review my previous post: Implementing Role Based Security with ASP.NET using Windows Authentication and SQL Server. If you don’t want to store your role-mappings within a database, you can also store them within Active Directory or your own custom role-provider. This sample demonstrates using a Windows User’s membership within the local “Administrators” group on a machine to control whether or not the detailed error message is displayed. Note: you can perform a role-check on a local Windows group by writing: User.IsInRole(“BUILTIN\Administrators”) – where the “BUILTIN” prefix indicates that it is a local group as opposed to a domain level one). Hope this helps, Scott P.S. Please visit this page to read more articles within my “ASP.NET 2.0 Tips/Tricks/Recipes and Gotchas” series.

|
-
The web.config file controls all compilation settings in a default web site project. To treat compiler warnings as errors, you'll need the following in web.config:
<system.codedom> <compilers> <compiler language="c#;cs;csharp" extension=".cs" compilerOptions="/warnaserror" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> </compilers> </system.codedom>
Note: You can only twiddle with compiler settings under full trust, but then you'll only need this setting at build time. 
|
-
Diligence - Diligent developers take ownership of their work without being possessive. Diligent programmers fix broken windows.
Humility - Humble developers take pride in their code, but don’t snub constructive criticism. Humble developers know they can always improve themselves.
Patience - Patient developers remain calm during times of stress, and don't surrender to the temptations of a quick fix. Patient developers have the endurance to carry a product across the finish line.
Liberality - Broad-minded developers base their decisions on proofs and particulars instead of preconceptions and prejudices. Broad-minded developers listen to the other side and attempt understanding.
Creativeness - Creative developers find a way around the brick wall in front of them, and do so without creating a mess. Creative developers find the elegant solution to a difficult problem.
Adaptability - Adaptable developers have the ability and willingness to learn new skills and accept new responsibilities. Adaptable developers continue to grow.
Resilience - Resilient developers bounce back from boneheaded bugs and bursting dotcom bubbles to code again another day. Resilient developers appreciate failure as the upward slope of the learning curve.
Eric Gunnerson's "Seven Deadly Sins of Programming" (and others) inspired this post.
I still have to some work to do on 6 or 7 of these. 
|
-
Below are some nice articles and links I’ve found on the web over the last week that I enjoyed, and recommend setting aside some time to consider reading: ASP.NET Topics Sending Email in ASP.NET 2.0: This is a great article from Scott Mitchell that demonstrates how to use the new System.Net.Mail APIs in .NET 2.0 to send email from an ASP.NET application. Sending Email in ASP.NET 2.0: HTML-Formatted Emails, Attachments, and Gracefully Handling SMTP Exceptions: This is a great follow-up article on email from Scott Mitchell that discusses some more advanced email scenarios using System.Net.Mail. UrlRewritingNet.UrlRewrite V2.0 Released: Albert Weinert sent me mail on Friday pointing me at the new release of the UrlRewriting engine that he and Thomas Bandt wrote for ASP.NET. It is available as a free download and includes samples + full source code. Working with GridView Without Using Data Source Controls: There are lots of good articles out there on how to use the new ASP.NET 2.0 GridView control with the ASP.NET 2.0 data source control model. In this article Bipin Joshi covers how to program against the GridView directly without using DataSource controls (and instead write code directly to handle binding, paging, sorting, etc). Using FlickR with .NET: This article by Sam Judson discusses how to consume and use the FlickR photo-service APIs within a .NET application. This allows you to build your own photo browsing applications, as well as upload content programmatically against Yahoo’s FlickR service. Accessing Embedded Resources through a URL using WebResource.axd: ASP.NET 2.0 introduced a really useful feature called “WebResource.axd”. This enables you to avoid having to manually deploy script and image resources files in well-known directories (no more /aspnet_client/ virtual directories). In this article Scott Mitchell discusses how it works, and how you can use this feature yourself to embed file resources within your own controls and components. ASP.NET Case Study: Lost Session Variables and AppDomain Recycles: Tess continues her awesome set of detailed ASP.NET debugging posts to delve into the mysteries of how ASP.NET App-domains work and when they recycle (and why). VS 2005 Topics Custom Grouping of Related Files in VS 2005 ASP.NET Projects: Visual Studio provides built-in support for nesting certain file-types under others within the solution explorer (for example: the code-behind file for an .aspx page is shown as a sub-item in the solution explorer). In this blog post James Hebben shows a neat registry trick that allows you to nest any file under another one inside VS 2005. He illustrates this with a useful sample where you could nest content-specific .js files underneath pages or controls. MSBuild in Visual Studio 2005: This 13-part article series describes how the new MSBuild build system works in Visual Studio 2005. Note that MSBuild can be used with both VS 2005 Web Application Projects and with VS 2005 Web Deployment Projects. Cool Future Stuff Windows Workflow Foundation Hello World App: Sahil Malik has posted a few cool articles that demonstrate how to use the new Workflow features that are shipping this fall with .NET 3.0. Workflow allows you to build composable sequences of operations together in a really flexible way (and allows you to avoid hard-coding in logic). This hello-world sample (and the previous post it links to) provides a quick way to learn more about the new technology. Hope this helps, Scott

|
-
Every so often, I get an email that looks like:
Dear Candidate,
While conducting a search for our client we came across your resume and it appears to be a good match for this opportunity. Blah blah fast-paced blah blah great benefits blah blah and so on.
Using the word "candidate" is not only presupposing, but a sign of laziness. Even the male enhancement spammers can personalize their messages. I'm sure the recruiter will have his pick of top talent with emails like this.
I think I'll reply with the following.
Dear [Recruiter Name],
Thank you for getting in touch about the [Position Name] offer with [Company Name]. Unfortunately, I'm busy on a project that will generate automated responses to mass mail job offers. I'm still working out a few bugs.
Sincerely,
[My Name] 
|
-
The Arizona .NET User's Group has one really big meeting every year, and I've been fortunate to have been invited to come out and speak again for this year's event. It will be held all day Wednesday September 6th at the Orpheum theater in Phoenix, Arizona. I’ll be on stage for a little over 3 hours total, and topics I'll be covering include ASP.NET 2.0 Tips and Tricks, IIS 7.0, Atlas, LINQ/LINQ for SQL and more.
Here's where you can register to attend: http://azgroups.com/forums/post/489.aspx (the event is free). Hope to see you there! Scott

|
-
A developer wanted to keep track of some birthdays with the following table design and data.
CREATE TABLE [Birthdays] ( [Name] varchar(50), [BirthDate] datetime )
INSERT INTO [Birthdays] VALUES('Gene Wilder', '6/11/1935') INSERT INTO [Birthdays] VALUES('Nicola Tesla', '7/9/1856') INSERT INTO [Birthdays] VALUES('Miles Davis', '5/26/1926')
To sort the data by name and by date, the developer wrote a single stored procedure to handle both cases.
CREATE PROC GetBirthdays @Ordering int AS BEGIN SELECT [Name], [BirthDate] FROM [Birthdays] ORDER BY CASE @Ordering WHEN 1 THEN [Birthdate] WHEN 2 THEN [Name] END END
The developer tested the proc by passing a value of 1, and was pleased to see a resultset ordered by birth date.
What can go wrong? (Hint: Try passing a 2).
How could the developer fix the problem by changing only 1 line? 
|
-
Hosting Windows Workflow is a new article covering the WorkflowRuntime class and the WF services. The article shows how to configure and use the scheduling, persistence, and tracking services provided by Windows Workflow.
Feedback is appreciated. 
|
-
-
The Atlas team recently shipped a new Atlas July CTP that contains a number of bug-fixes. You can download it off of the http://atlas.asp.net/ web-site (like all Atlas CTPs it supports a go-live license). The Atlas Control Toolkit team – which is building up a great library of useful Atlas-enabled controls on top of the core Atlas runtime – also recently posted a binary refresh of the Atlas Control Toolkit as well. You can read all about it in Shawn’s announcement post of it, and download it for free here. What is really cool about this new Atlas Control Toolkit update is that it includes Atlas controls contributed by non-Microsoft developers. As I mentioned in an earlier post, we are building the Atlas Control Toolkit collaboratively with the broader .NET developer community as a free shared source project on the new CodePlex site. Our goal is to have ~50 great free Atlas controls that you can download and use as part of it by the end of the year. There are currently 21 cool Atlas-enabled controls included within the Atlas Control Toolkit download (with many more coming soon). You can run online demos of them from the sample site here. Below is a screen-shot of the Atlas Control Toolkit samples that you can try out from this samples site online:
Some of my favorite new controls are the ones built by the non-Microsoft contributors to the project. These include the new FilteredTextBox developed by Christian Wenz that you can see in the screen-shot above. Paul Glavich built the cool new PasswordStrengthExtender control which provides real-time feedback on password complexity:
Paul posted about his experiences building the above control on his blog here. Pierre LaGarde then built the cool new PagingBulletedList, NumericUpDown, and RatingControl:
All of the controls in the toolkit are free, and all ship with full source code (including a license that allows you to take the source, modify it, and do whatever you want with it). How to Get Started with the Atlas Control Toolkit To learn more about the Atlas Control Toolkit and how to get started with it, visit the Atlas Control Toolkit site here. Make sure to also then check-out the Atlas video series that Joe Stagner is working on: Note: The CascadingDropDown control video above was just posted yesterday and shows how to use this control (which ships in the Atlas Control Toolkit) to build Ajax enabled drop-downlists that depend on each other’s values and don’t require a full server round-trip to update when changed. Hope this helps, Scott

|
-
The alpha release of the ASP.NET Best Practice Analyzer was about 5 weeks ago. Similar to the popular SQL Server BPA, the ASP.NET BPA evaluates a set of best practice rules and tells you about configuration problems in your applications. The tool checks both machine level and application level config files. Currently, the tool only has a handful of rules. It will raise red flags if the application runs in full trust, or if debug / trace flags are enabled, and a few others.
Ironically, the tool suggest AutoEventWireup="false", which isn't the default for C# web forms in VS2005.
I can't think of too many hard and fast rules for web.config settings, but here are a few: more that could be useful:
- No plaintext passwords in the <identity> section.
- Make sure the <httpHandlers> section maps appropriate extensions to the HttpForbiddenHandler.
- Make sure the <pages> section has smartNavigation disabled and validateRequest enabled.
- No enabled trace sources inside <system.diagnostics>.

|
-
The Atlanta C# User Group is meeting on Monday, August 7, 2006, at 6:00 pm at the Microsoft offices in Alpharetta. Greg Young will present the design patterns of the month, followed by Wally McClure presenting on Ajax and Atlas. See you there.

|
-
I've been kicking around the best approach for unit testing a custom activity for Windows Workflow. I haven't found an approach I'm comfortable with as yet.
Here is a simple, contrived custom activity.
using System; using System.Workflow.ComponentModel; using System.Workflow.ComponentModel.Serialization;
[assembly:XmlnsDefinition("http://odetocode.com/wf/activities", "OdeToCode.WF.Activities")] namespace OdeToCode.WF.Activities { public class CreateMessageActivity : Activity {
private string _recipient; public string Recipient { set { _recipient = value; } }
private string _message; public string Message { get { return _message; } } protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext) {
_message = String.Format("Message to {0}", _recipient); return ActivityExecutionStatus.Closed; } } }
It's tempting to create a unit test that instantiates the activity and calls Execute directly, but most activities are not this simple. The ActivityExecutionContext class is sealed, and mocking out all the scheduling services, queues, and other dependencies inside is a task for Sisyphus.
Another approach is to test the activity using the WF runtime. A little bit of hacking produces:
[TestFixture] public class CreateMessageActivityTests { [TestFixtureSetUp] public void StartWfRuntime() { _runtime = new WorkflowRuntime(); // use manual scheduler for synchronous execution _scheduler = new ManualWorkflowSchedulerService(); _runtime.AddService(_scheduler);
// type provider needed to resolve custom activity in XAML TypeProvider typeProvider = new TypeProvider(_runtime); typeProvider.AddAssembly(Assembly.Load("ActivityLibrary2")); _runtime.AddService(typeProvider);
_runtime.WorkflowCompleted += new EventHandler<WorkflowCompletedEventArgs> (_runtime_WorkflowCompleted); _runtime.WorkflowTerminated += new EventHandler<WorkflowTerminatedEventArgs> (_runtime_WorkflowTerminated); }
[TestFixtureTearDown] public void ShutdownWfRuntime() { _runtime.StopRuntime(); _runtime.Dispose(); }
[SetUp] public void SetupTest() { _exception = null; _outputs = null; }
void _runtime_WorkflowTerminated( object sender, WorkflowTerminatedEventArgs e ) { _exception = e.Exception; }
void _runtime_WorkflowCompleted( object sender, WorkflowCompletedEventArgs e ) { _outputs = e.OutputParameters; }
WorkflowRuntime _runtime = null; ManualWorkflowSchedulerService _scheduler; Dictionary<string, object> _outputs; Exception _exception;
// create custom activity as the root of a workflow string _xaml = @"<otc:CreateMessageActivity xmlns:otc=""http://odetocode.com/wf/activities""> </otc:CreateMessageActivity>"; }
This is a lot of code, and I haven't even written a test yet. Unit testing a custom activity is an indirect process because the workflow runtime tries to shield a workflow instance from the callous hands of the outside world.
[Test] public void CreatesMessageForScott() { XmlReader reader = XmlReader.Create( new StringReader(_xaml) );
Dictionary<string, object> parameters; parameters = new Dictionary<string, object>(); parameters.Add("Recipient", "Scott");
WorkflowInstance instance; instance = _runtime.CreateWorkflow(reader, null, parameters); instance.Start(); _scheduler.RunWorkflow(instance.InstanceId);
Assert.IsNull(_exception, "Workflow threw an exception"); Assert.AreEqual(_outputs.Count, 1);
// .. and so on
}
I'm feeding a XAML definition of a workflow to the runtime in an attempt to simplify the process and isolate the activity. Still, this code is still far too lengthy and complex to maintain in a unit test. My plan is to create a project of utility classes to simplify the code even further, but I'm still apprehensive.
Anyone else unit testing activities or workflows? 
|
-
Several people have sent me email lately asking for a suggested short-list of my best/favorite past blog posts to read (I’ve done 200 posts over the last 12 months and apparently it takes too long to read them all <g>). I’ve put together a summary page of ASP.NET 2.0 Tips, Tricks, Recipes and Gotchas that you can check out here. It currently contains links to 37 posts that I’ve done in the past that I think are interesting and worth spending sometime to read. I’ve organized the list by area topic (UI, Data, Security, Visual Studio, etc). My goal is to post at least 1-2 new/original ASP.NET Tips/Tricks/Recipes to my blog each week going forward. I’ll also make sure to update the summary page above as I add new ones – so you might find it useful to bookmark if you want to quickly look them up. Hope this helps, Scott

|
-
Source: MSSQL Server 17052 : Cannot recover the master database. Exiting.
The chkdsk result was ugly, too..... 
|
|
|
|