Site: http://ardalis.com/ Link: http://feeds.stevesmithblog.com/stevensmith
by via Blog on 2/2/2012 2:22:02 AM
One of my applications relies on a singleton pattern to create a single instance of a server which processes requests from many different ASP.NET handlers. It is created using pretty much standard Singleton code: public static Context CreateContext() { return CreateContext(new ConfigurationFileSettings()); } Recently, this server needed to be made aware of whether requests were coming into it via SSL or standard HTTP. The solution that was checked in (and which worked and pa ...
[ read more ]
by ssmith via Blog on 1/19/2012 7:04:00 PM
If you’re at all serious about testing, at some point you’re going to have a rather large suite of tests that need to run, and you’ll find that your builds are taking longer than you would like because of how long the tests run. For example, consider this suite of 24 tests, each one of which looks like this one: If you run 24 of these, it’s going to take about 24 seconds, by default: Now of course it’s important to keep your unit tests and integration tests separate and to know which ...
by ssmith via Blog on 11/11/2011 4:11:00 PM
There’s a great site for finding extension methods, ExtensionMethod.net. I don’t believe either of these came from there, and I’ve not (yet) submitted them there, but here are a couple of extensions on IEnumerable<T> that I’ve found useful recently. ForEach<T> The first one is simply a method that allows you to easily iterate over a sequence and perform an action on it. This is a pretty commonly useful extension method, so much so that it’s now included in .NET 4.0 out ...
by ssmith via Blog on 10/29/2011 3:25:17 PM
Using lazy initialization in C#, a class’s state is set up such that each property’s get method performs a check to see if the underlying field is null. If it is, then it calculates or populates the field before returning it. This is a very simple and common approach, but it requires that the class follows a convention of only accessing the field via the property. Unfortunately, there are no language features that can enforce this, so it’s possible for errors to creep in. ...
by ssmith via Blog on 10/26/2011 9:09:36 PM
I’ve been using RazorEngine on a project and have been impressed with its simplicity and ease-of-use. However, the performance of the application isn’t quite where I need it to be, and I was pretty sure the issue was with how I was using RazorEngine, especially since I could anecdotally see that the processor consumption on the machine running the app was quite high, and looking at the running tasks it was clear that most of that was a result of csc.exe (C# compiler) activity. A bit of se ...
by ssmith via Blog on 10/25/2011 2:23:03 PM
You can use the sc.exe command to install an EXE as a service on Windows Server 2008. There’s a good article on creating an application that can easily run as either a console app or as a service here. From an administrator command prompt, the syntax is something like this: sc \\servername create MyService.ServiceName binpath= d:\services\Foo\Foo.exe displayname= MyService.ServiceName Note that for this particular utility, the command line options include the “=” sign in them, so y ...
by ssmith via Blog on 10/3/2011 2:57:45 AM
Entity Framework 4 has Lazy Loading built-in and enabled by default. Here’s a quick bit of code to show you how to work with this feature. To get started with this, simply create a new Console Application and in nuget (Package Manager Console), run this command: install-package EntityFramework.Sample This will install a simple blog post example. Copy and paste the following into your Program.cs file (replace everything): using System; using System.Collections.G ...
by ssmith via Blog on 9/30/2011 10:07:00 PM
I’m very pleased to be speaking again at DevReach in Sofia, Bulgaria next month. As usual, the conference has an amazing list of speakers (which I’m still somewhat amazed includes me), with Scott Hanselman making the trip out this year to give several sessions. If you have the opportunity to attend, I highly recommend it. There’s certainly no other conference in Eastern Europe that comes close. This year, I’ll be presenting on three topics. The first is something new for ...
by ssmith via Blog on 9/30/2011 6:43:33 PM
Due to some database moves, I’ve recently been touching a lot of connection strings, which has me thinking about the topic. In fact, I put together a short survey on twitter, and invited a bunch of developers and DBAs to share their thoughts, both on twitter and in the survey, on some issues relating to connection strings. Here are three tips you should know about that, if you’re not already using, should improve your use of connection strings. Use Windows Authentication ( ...
by ssmith via Blog on 9/30/2011 4:30:00 PM
Next Friday, 7 October 2011, Microsoft in Cleveland is hosting a free one-day event focused on the basics of Software Engineering. There are a handful of seats left before the event sells out. You can learn more and RSVP for Software Engineering 101 here (until tickets run out). The event is being held at the Microsoft office here: Microsoft Corporation 6050 Oak Tree Blvd Independence, OH 44131 Last year, the event sold out (well, “sold” is misleading, since it ...
by ssmith via Blog on 9/27/2011 2:15:00 PM
I’m currently building an internal application for The Code Project that needs to be able to transfer the contents of some potentially very large files over the wire. After considering various ways to get the data from point A to point B, we decided the easiest thing would be to process the text file on the client, and send batches of rows up to the server for processing. Initially we looked at building a WPF client for this, but then switched over to Silverlight 4 since the rest of ...
by ssmith via Blog on 9/26/2011 12:57:00 PM
If you’re working with ASP.NET MVC and JsonResult, you may encounter this error: This request has been blocked because sensitive information could be disclosed to third party web sites when this is used in a GET request. To allow GET requests, set JsonRequestBehavior to AllowGet.Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: Sy ...
by ssmith via Blog on 9/23/2011 8:00:00 PM
Ran into a small problem today, where I had two classes referring to one another using EF 4.1 Code First. Let’s say I had a class Item and another class ItemHistory. ItemHistory has a property of type Item that refers to the Item class. Item, in turn, has an ICollection<ItemHistory> Histories property: public class Item { public int Id { get; set; } public virtual ICollection<ItemHistory> Histories { get; set; } } ...
by ssmith via Blog on 9/22/2011 4:33:02 PM
In my recent analysis of the Windows 8 / WinRT options for building Metro style Apps, I mentioned the many choices Microsoft is offering for building these applications. While I agree with Microsoft’s decision to support C++, .NET, and HTML5/JS developers when building these applications, it does still represent a Paradox of Choice for many developers, myself included. If we consider only native apps for the iPad, there are far fewer choices involved when it comes to programming lang ...
by ssmith via Blog on 9/20/2011 10:46:00 PM
Last week at BUILD, Microsoft introduced their vision for the next generation of Windows devices with announcements and previews of Windows 8, Metro style applications, and WinRT. The BUILD conference was the most secretive event I’ve ever known Microsoft to hold, with very few leaks prior to the keynotes that began on Tuesday, September 13th. Now that the event has come and gone, you can watch the sessions and keynote presentations for yourself here. In this post, I am going t ...
by ssmith via Blog on 8/30/2011 8:32:00 PM
I just published an article on ASPAlliance on Moving Beyond Enums, describing when and how to move from enums to classes in your code when you start demanding more from your enums than they were designed to give. Check it out and let me know what you think. I also thought I’d post an alternate LINQ-ified version of the DisplayFriendlyNames() method I used in the article. Original, non-LINQ version: public static string DisplayFriendlyNames() { var sb = new S ...
by ssmith via Blog on 8/24/2011 7:33:59 PM
I’m using SimpleMembership, from WebMatrix’s distribution(WebMatrix.WebData), with an ASP.NET MVC 3 application. You can find the NuGet Package for SimpleMembership.Mvc3 here, and installing it is just a matter of running “Install-Package SimpleMembership.Mvc3” from the Package Manager Console in Visual Studio. Unlike the built-in Membership and Role providers for ASP.NET, SimpleMembership doesn’t require huge swaths of XML to be added to your web.config file, or much in the way of d ...
by ssmith via Blog on 8/12/2011 3:01:58 PM
If you’ve worked with the System.Net.Mail API to send out messages, you may have run into the fact that when you add an email address to a message, it will sometimes throw an exception if the email doesn’t appear to be valid: var myMessage = new MailMessage();myMessage.To.Add("ssmith@somewhere,com"); // invalid ','// do more stuff Result: FormatException - The specified string is not in the form required for an e-mail address. This is handy since it’s usually better to fail ...
by ssmith via Blog on 7/19/2011 6:42:00 PM
Visual Studio includes support for distributed load testing through the use of Test Agents and Controllers. For reference, there are a couple of MSDN Walkthroughs on Installing and Configuring Visual Studio Agents and Test and Build Controllers and Using a Test Controller and Test Agents in a Load Test. However, they lack pretty pictures, so if a screenshot walkthrough is more your speed, read on. Before starting, you’ll need to installation media. This might be an actual DVD, ...
by ssmith via Blog on 7/13/2011 2:35:30 PM
Last night I gave a presentation at the Cleveland .NET SIG on Common Design Patterns. The turnout was great, so much so that the group ran out of pizza and chairs, so thanks to everyone for taking the time to come out! Thankfully the A/C held up pretty well (in years’ past, it’s been an issue there), and I hope everybody enjoyed the topic and discussion. I promised that I would post the slides and demos here, so I am, along with a few links to other resources. Download my C ...
by ssmith via Blog on 6/27/2011 2:47:00 PM
Have you ever set up a recurring payment with a vendor using a credit card? I have. It’s very convenient, both for the consumer and the vendor, because neither one needs to be bothered with invoicing and paying bills on a regular basis. Everything’s great, as long as the consumer really does still want the product or service offered by the vendor, and as long as the vendor is ethical and diligent about allowing the customer to cancel their service. It’s this last bit wher ...
by ssmith via Blog on 6/24/2011 3:46:46 PM
I’m adding SpecFlow to an application I’m working on so that I can add some acceptance tests that actually exercise the user interface. I’ve only spent a couple of hours on it thus far, but I have it working with a single specification running through the tests via WatiN. I found the following resources helpful as I was going through this exercise: Getting Started with SpecFlow and ASP.NET BDD with SpecFlow and ASP.NET MVC BDD with SpecFlow BDD with SpecFlow and Watin ...
by ssmith via Blog on 6/23/2011 9:06:20 PM
Last night I spoke at the Dayton .NET User Group on the topic of Anti-Patterns and Worst Practices. It was a pretty good-sized group, albeit rather subdued. You’ll find some of the inspiration for the talk in my Principles, Patterns, and Practices of Mediocre Programming post, and others in the 97 Things Every Programmer Should Know book (or online here). The slides and demos are available for download. Thanks to those of you who came to the meeting, and to Joe for inviti ...
by ssmith via Blog on 6/21/2011 6:08:00 PM
Sometimes when you’re about to do some major surgery on your database, you want the comfort of knowing that you can always rollback if there’s a problem. And it’s not always the case that you’ll immediately know there was a problem. Sometimes, you just want a copy of the original data so that you can go back to it, or use it to analyze where you went wrong. Of course, you can backup the whole database, but restoring the full system is often overkill if you’re only working on a ...
by ssmith via Blog on 6/20/2011 2:36:51 PM
Last week I ran a poll (that maxed out at 400 responses on twtpoll) asking how developers recommend using regions in C# (or not). You can see the results here: About 15% of the respondents chose Other and/or chose to leave a comment. The comments are useful because they often highlight answer categories that I overlooked when I set up the poll. In this case, there were a lot of comments, I think because there are a lot of different opinions about regions in general, some of ...
by ssmith via Blog on 6/14/2011 1:18:34 PM
The var keyword was introduced in C# 3.0, and has since gained quite a bit of popularity. There is also a fair bit of contention over how it should be used, with posts like this one (with which I happen to agree) being not uncommon. Over the last week I posted a couple of polls on twitter that asked about specific scenarios in which one might use var, trying to address the two scenarios outlined by the author of that post. Scenario One This was meant to depict the case where the ty ...
by ssmith via Blog on 6/13/2011 4:21:48 PM
Last week I hosted a quick poll on Twitter about how useful a particular XML comment was for a particular class. The code looked like this: /// <summary>/// Repository for handling Users./// </summary>public class UserRepository : Repository<User> The poll actually got 355 votes, which is pretty impressive. In hindsight I should have added an option relating to generating documentation, or updated the “necessary evil” option to include documentation as a ...
by ssmith via Blog on 5/31/2011 4:09:00 PM
Fiddler is a great tool for examining and working with HTTP requests. If you’re a web developer, it’s one of those tools that you should definitely be at least aware of. The most recent version has some nice new features, like being able to very easily isolate which window or process it’s recording, so you don’t end up with a lot of noise from messengers and other background HTTP requests. The feature I want to describe for this post has actually been around for a while, so eve ...
by ssmith via Blog on 5/29/2011 3:08:00 PM
Sometimes it’s handy to see the order in which methods are firing, or how long they’re taking, without having to attach a debugger. Typically, you might write some code like this: public void Foo() { Debug.Print("Entering Foo"); // other stuff } public void Bar() {
... [ read more ]
by ssmith via Blog on 5/13/2011 5:41:38 PM
Design patterns are general, reusable solutions that occur in software design, which can usually be adapted to fit into a number of different situations and applications. Recently, I recorded a screencast interview with Carl Franklin on Commonly Used Design Patterns for dnrTV, and one of the things we discussed was the stages of learning design patterns. I noted that, at least for myself, I’d found that I tended to go through four distinct phases during my learning process when it ca ...
by ssmith via Blog on 4/24/2011 2:51:00 PM
I wrote a couple of weeks ago about using Visual Studio 2010’s Performance and Load Testing tools to analyze and correct some performance concerns with the Stir Trek Conference web site (which, by the way, is 2 weeks from today!). I realized, though, that there are a bunch of mobile applications that are set up to use the site’s XML and JSON data feeds, and I hadn’t measured or tuned these at all. It’s likely that more traffic on the day of the event will come via these feed URLs tha ...
by ssmith via Blog on 4/22/2011 3:14:49 PM
Yesterday I wrote about how to wire up jQuery UI’s AutoComplete add-in to a WCF Service to create an autocomplete search/navigation control. Today I deployed the resulting code to production but initially had some trouble getting things to work. The only real difference between the two environments is that in production everything goes through HTTPS/SSL, so I figured that had to be the culprit. A bit of searching led to this blog post describing WCF Bindings Needed for HTTPS. ...
by ssmith via Blog on 4/21/2011 9:12:42 PM
On an application I’m working on, there’s was an ASP.NET DropDownList used for jumping to a particular account. This, when enhanced with the AJAX Control Toolkit’s ListSearchExtender, provided an awesome user experience for quickly navigating to a particular account. Just click the control, and either scroll, or better, type in the first few characters of the name of the account, and it was instantly selected. Tab or enter from there, and you’re done. Unfortunately, as often h ...
by ssmith via Blog on 4/18/2011 1:29:52 PM
The Windows Azure team is holding a contest, and The Code Project is helping to support it. As part of this contest, you can get free Azure compute time by signing up with the code CP001 here. The contest is simple – Rock, Paper, Scissors, with bots, and with 2 new moves: Dynamite, which beats Rock, Paper, or Scissors, and Water Balloon, which beats Dynamite. The catch: you only have a limited supply of dynamite. Get Started Here: My bot placed 4th out of about 50 in last w ...
by ssmith via Blog on 4/14/2011 2:10:00 PM
I’m creating a simple windows service using Visual Studio 2010 and .NET 4. I want to be able to easily test it by simply running the resulting exe without the need to install the service. I did some research on this topic and found three helpful articles: HybridService: Easily Switch between Console Application and Service (on CodeProject) Run Windows Service as a console program Creating a windows service in visual studio 2010 (in VB) I found that the first article was a ...
by ssmith via Blog on 4/13/2011 3:42:34 PM
Phil Haack has a post introducing the ASP.NET MVC 3 Tools Update that you probably should read. This is my own experience installing the update and upgrading an existing MVC 3 project to use the new tooling. First, you’ll want to install the MVC 3 Tools Update, using one of these options: Web Platform Installer for ASP.NET MVC 3 Tools Update Download Page for ASP.NET MVC 3 Tools Update And then you can read the Release Notes as well. I’m not going to talk about what’s new w ...
by ssmith via Blog on 4/11/2011 1:46:00 PM
I recently joined the board responsible for organizing the Stir Trek conference in Columbus, Ohio. This is a great conference I’ve spoken at the last couple of years that’s held in a movie theater on opening day of a new great movie. The first one, two years ago, was held for the opening day of Star Trek (hence the name), and last year was Iron Man II. This year’s movie is Thor, which looks to be pretty awesome. Here are some badges promoting the event: You can find ...
by ssmith via Blog on 3/30/2011 6:23:48 PM
Last weekend I presented at the Cincinnati Day of Agile event on Introducing Pair Programming (see on slideshare). The event was nearly sold out with about 240 people in attendance, a mix of devs and PMs. The content and (other) speakers I thought were great – Phil and his team did a great job. I took a few pictures during the event, which you can see below: Phil and Joel Semeniuk Brian Prince James Bender Jim Holmes The event went very well, logistically, ...
by ssmith via Blog on 3/25/2011 3:48:37 PM
When you create a new project in Visual Studio, it will usually include some files as part of the project. Most of the time, these are pretty useless, but if it’s your first time working with said template, they may help you get going. In VS2010, the Test Project, for example, has been improved over prior versions by eliminating a useless text file describing tests and a useless Manual Test file that I never once used. It still includes a unit test file, which I think is fine, ...
by ssmith via Blog on 3/3/2011 10:29:00 PM
Last summer at the Software Engineering 101 event put on by NimblePros in Cleveland, I saw Kevin Kuebler do a demo using git or Mercurial to iterate from phase of the project he was building to the next. It worked amazingly well and I thought I would document how to set this up yourself, so that when you’re giving a technical presentation that involves a somewhat complex set of changes to a project, you can easily step through the updates without having to resort to a lot of on-stage typin ...
by ssmith via Blog on 2/20/2011 3:40:25 PM
I recently did a show with Carl Franklin on ASP.NET Tips and Tricks, recorded for dnrTV.com. In it, I go through a bunch of ASP.NET tips, from the oldies but goodies like Tracing and Caching, to some new ones like optimizing the performance of your ASP.NET MVC 3 applications. The samples from the presentation are available for download here. ...
by ssmith via Blog on 2/17/2011 4:14:00 PM
If you ask a newly-hired developer this question while they are busy coding away on something, you’ll usually get an answer like “the Acme project.” If that’s too obvious (after all, maybe that’s the only project this dev works on), then the answer might be “the new xyz feature” or “that abc bug.” All of these are more-or-less valid responses, and depending on the scope of the response, they might be sufficiently clear to narrow down exactly how far along the dev is in getting the ov ...
by ssmith via Blog on 2/16/2011 5:17:12 PM
I’m a huge fan of TechSmith Camtasia and use it for pretty much all of my screencasts. However, I’m currently recording some presentations for the Code Project Agile Virtual Tech Summit that’s taking place next week, and the preferred capture program for the platform is Expression Encoder 4. So, I figured while I’m learning how to do it, I might as well share how it works and how I find it compares with Camtasia. To get started, you should download and install Expression Encoder 4.& ...
by ssmith via Blog on 2/15/2011 5:03:30 PM
In part one of this series, I introduced the CachedRepository pattern, and demonstrated how it can be applied through the use of simple inheritance to an existing Repository class. This allows us to easily configure whether or not we want to use caching at the repository level through the use of an IOC Container like Structuremap. However, using inheritance to achieve the behavior isn’t always desirable, since generally it’s better to use object composition if possible (this tends to ...
by ssmith via Blog on 2/14/2011 5:56:00 PM
In this first part of a series on adding support for caching to the Repository Pattern, I’d like to show how to very simply control whether or not caching is performed on a per-repository basis through the use of an Inversion of Control Container. In this case, I’ll be using StructureMap with ASP.NET MVC 3. One of the primary goals of this implementation is to follow principles of object oriented design, in particular the Single Responsibility Principle and the Don’t Repeat Yourself ...
by ssmith via Blog on 2/10/2011 4:36:00 PM
This wraps up my mini-series on using PowerShell to help manage services running on multiple remote servers. In my case, these scripts exist to make it easy for me to globally start and stop services on a number of web servers that are part of Lake Quincy Media’s AdSignia ad platform – you can read more about the message-based architecture we’re using here. I learned the basics of starting and stopping services here. I adapted this so that I could store all of my server’s names in o ...
by ssmith via Blog on 2/9/2011 4:40:51 PM
Yesterday I gave a presentation to a little over 300 attendees of MVCConf on Improving ASP.NET MVC Application Performance. There were some great responses on twitter and generally the ratings on SpeakerRate were positive, which was great because I was a bit worried going into the presentation, since I’d only committed to giving a talk at the conference a few day earlier. I’m uploading the recording of the session to the MVCConf team now, and will add a link here when it’s available. ...
by ssmith via Blog on 2/9/2011 4:29:00 PM
As I wrote earlier, Lake Quincy Media’s AdSignia ad platform is utilizing services and a message-based architecture to decouple the system from the database and improve performance and reliability of the servers. It’s proven useful to quickly work with the services across multiple nodes in the web cluster, and PowerShell is the obvious choice for automating some of these tasks. When building up a collection of PowerShell scripts to support an application, I recommend that you store t ...
by ssmith via Blog on 2/8/2011 4:06:00 PM
If you’re using PowerShell but want to keep your scripts DRY, you may want to factor common functions into their own scripts, and then call these scripts from multiple other scripts. This is pretty easy to do. For instance, if you have an array of values that you want to use as inputs for several scripts, you could create a file like this one: Colors.ps1 function Colors { return "Red", "White", "Blue" } No ...
by ssmith via Blog on 2/7/2011 3:11:00 PM
Recently at Lake Quincy Media we upgraded our logging system for the AdSignia ad platform so that it uses messaging rather than direct SQL database access. This allows us to log much more detailed data, which we can then analyze, and also improves the performance of every ad request, since it eliminates a database call and replaces it with a local queue operation, which is much faster and less likely to suffer from any kind of contention. Prior to this, the logging information was st ...
by ssmith via Blog on 2/3/2011 8:41:00 PM
There’s a great pattern for ensuring that unmanaged resources are cleaned up in the .NET world. It’s called the Disposable pattern and it applies to any resource that implements the IDisposable interface. If you are writing an object that directly deals with unmanaged resources, such as files, database connections, network sockets, fonts, etc., then you are well advised to implement IDisposable and ensure your resources are cleaned up in your class’s Dispose() method. Having fo ...
by ssmith via Blog on 2/3/2011 4:36:23 PM
If you get this error: error MSB5016: The name “Intitial Catalog” contains an invalid character “ “. or something similar when trying to specify a connection string within an MSBuild task, like this one: <MSBuild Projects="src\Databases\Northwind.dbproj" Targets="Build;Deploy" Properties="TargetDatabase=Northwind;TargetConnectionString="Data Source=localhost;Initial Catalog=Northwind;Persist Security Info=True;User Id=foo; ...
by ssmith via Blog on 2/2/2011 3:46:00 PM
Most of your domain objects should override ToString() for the simple reason that if you ever want to simply display the object’s state, you shouldn’t need to implement a custom formatter for it. Furthermore, it’s well-known that the default System.Object implementation of .ToString(), which outputs the type’s name, is useless 99% of the time. Thus, it’s generally a good idea to implement .ToString() on your classes that have some kind of state, and to have your implementation presen ...
by ssmith via Blog on 2/1/2011 8:46:16 PM
I’m working on an application that needs to deploy a new database each month, in order to manage the large amount of data involved. We’d like to automate this as much as possible, and since we already have the database schema in a Visual Studio 2010 database project, we figured the simplest thing would be to create an MSBuild task to do this, and then schedule it as part of our build server. The format we want to use for the database name is simply “Databasename_201103” where the 201 ...
by ssmith via Blog on 2/1/2011 4:29:00 PM
Continuing in working with the MVC Music Store sample application, the next thing I ran into after installing the SQL database by hand, was an error on the home page saying: Invalid object name 'dbo.Albums'. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Data.SqlClient.SqlException: Invalid object name 'dbo.Al ...
by ssmith via Blog on 1/31/2011 10:44:39 PM
In an example of extremely intuitive user experience, the latest version of Outlook has moved things around in the interests of ribbonizing everything. This would be fine if in fact the trendy new ribbon UI was organized in a fashion that was, well, based on logic. Sadly, at least in the case of Exporting data, this is not the case. In previous versions of Outlook, one could navigate to File, Import/Export, and lo and behold, the Import and Export options did appear. Not ...
by ssmith via Blog on 1/31/2011 4:21:00 PM
I’m working with the new MvcMusicStore sample application, and immediately I’m having trouble with the database. When I try and open the .mdf file that’s in my App_Data, I’m presented with this error message: The database 'C:\DEV\SCRATCH\MVCMUSICSTORE-V2.0\MVCMUSICSTORE-COMPLETED\MVCMUSICSTORE\APP_DATA\MVCMUSICSTORE.MDF' cannot be opened because it is version 655. This server supports version 612 and earlier. A downgrade path is not supported. Could not open new database 'C:\D ...
by ssmith via Blog on 1/30/2011 9:14:59 PM
If you’re working with the ASP.NET MVC 3 MvcMusicStore demo and you run into the error message: The name ‘ViewBag’ does not exist in the current context It’s probably a sign that you are running on an older version of ASP.NET MVC (or a pre-release of MVC 3). You can download the latest version of ASP.NET MVC 3 here. This will install the Web Platform Installer (version 3) and will install ASP.NET MVC 3: Once MVC 3 (released version) is installed, recompile the MVC Music Stor ...
by ssmith via Blog on 1/27/2011 4:35:25 PM
Consider a scenario where you have a many-to-many relationship, but it’s nullable. For instance, maybe you have Articles and Categories (or Tags), and an Article can have 0 to N Categories/Tags. Now, you want to pull in a set of Articles that are uncategorized. Using SQL, you might write a query like this: SELECT a.ID, a.Name FROM Article a WHERE NOT EXISTS ( SELECT NULL FROM Article_Category_Xref acx WHERE acx.ArticleID = a.ID ...
by ssmith via Blog on 1/21/2011 9:07:13 PM
As I write this, the best resource for official documentation on ASP.NET MVC 3 is of course MSDN. You can also learn more about ASP.NET MVC 3 here. However, neither of those mention how to properly set up an IOC Container (like StructureMap) with ASP.NET MVC 3. After some searching, I was able to get things working using the RTM version of ASP.NET MVC 3. Here’s what I had to do. Step One – Global.asax – Application_Start() First, you need to wire things up when your app ...
by ssmith via Blog on 1/19/2011 10:10:00 PM
Last week at CodeMash I went through the Harry Potter Book Kata with Steve (@underwhelmed). This is an interesting kata because it pretty much starts out very straightforward and things progress very quickly, and then you are faced with a brick wall in terms of how to proceed with the algorithm. I recommend you give the exercise a try yourself before reading my tips, since they may be something of a spoiler for you (if you enjoy the puzzle-solving aspect of these exercises more than ...
by ssmith via Blog on 1/10/2011 4:39:50 PM
I’ve been writing tests and unit tests for quite a while, and naturally my personal preference for naming them has evolved somewhat with time. Initially, I didn’t really know what I was doing and the default organization tended to be something like “given a class, Customer, all of the tests will go into a class called CustomerTests.” This turned out, for me at least, to be less than ideal. Later I learned more about BDD and specifications and I decided I could apply some of the ...
by ssmith via Blog on 1/7/2011 3:23:32 PM
If you encounter this error in your ASP.NET application after updating it while using NServiceBus: Server Error in '/' Application. Type DataPump.Infrastructure.Messages.MyMessage was not registered in the serializer. Check that it appears in the list of configured assemblies/types to scan. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in ...
by ssmith via Blog on 1/5/2011 4:34:26 PM
If you see this bug while running an application that is referencing some third-party DLLs that you recently downloaded, your first thought should be “I need to Unblock the assembly I’m referencing!” …an attempt was made to load an assembly from a network location… Windows, while trying to be helpful, will block downloaded files, causing .NET to fail when trying to load such DLLs. The best way to fix this problem when you are downloading a package with many assemblies in it (e ...
by ssmith via Blog on 12/10/2010 3:38:00 PM
A very common practice in web applications, especially those written using the ASP.NET built-in Role provider (circa ASP.NET 2.0 / 2005), is to perform role checks throughout the code to determine whether a user should have access to a particular page or control or command. For instance, you might see something like this: if (CurrentUser.IsInRole(Roles.Administrators) || CurrentUser.IsInRole(Roles.SalesAgents)) { SomeSpecialControl.Visible = true; } The problems w ...
by ssmith via Blog on 12/9/2010 3:43:00 PM
I’m working with NServiceBus to send messages to and from different parts of my application. NServiceBus is a mature tool that sits on top of MSMQ and provides a great developer experience for working with a number of different scenarios. One thing that’s challenging when working with queues is figuring out where a message went when it doesn’t show up at the other end of the message bus. Where did things go wrong? How can I see the messages in the queue for MSMQ? Is ...
by ssmith via Blog on 12/8/2010 3:11:00 PM
I’m a huge fan of build automation, and all of my dev projects include scripts to build, test, deploy, run etc. Sometimes these use PowerShell and quite often they use MSBuild (or occasionally NAnt) but batch files remain a very simple and powerful way to take care of automation business. Today I’m trying to wrap up my use of NServiceBus on a project that’s going live with some CQRS goodness, and I want a simple way to kick off the host process while I’m doing development so I don’t ...
by ssmith via Blog on 12/7/2010 2:32:20 PM
I recently published an article on Alternatives to the Singleton Design Pattern on AspAlliance.com. If you’re a fan of the Singleton pattern, I would encourage you to have a read and feel free to comment (here or there) if you agree or disagree with my position. You can also learn more about the Singleton in the Patterns Library at Pluralsight. Finally, if you haven’t read it, I definitely recommend checking out Jon Skeet’s coverage of the Singleton, as it provides several alte ...
by ssmith via Blog on 11/19/2010 4:05:28 PM
The folks at NimblePros have put together a pretty sweet 2011 calendar showcasing principles of software craftsmanship and agile software development. The calendars are arriving from the printer today and should start shipping out over the next week or so to those who have pre-ordered them (or won them in the twitter contest, which lasts until 8 December 2010). Here’s my review of the calendar (before having an actual one in hand, mind you). On the Cover: It starts with The Mani ...
by ssmith via Blog on 11/11/2010 11:19:00 PM
Recently I wanted to test a bunch of URLs to see whether they were broken/valid. In my scenario, I was checking on URLs for advertisements that are served by Lake Quincy Media’s ad server (LQM is the largest Microsoft developer focused advertising network/agency). However, this kind of thing is an extremely common task that should be very easy for any web developer or even just website administrator to want to do. It also gave me an opportunity to use the new asynch features in ...
by ssmith via Blog on 11/10/2010 2:37:16 PM
Last night I led a discussion on software quality at the Cleveland area .NET SIG. Thanks to everyone who came and especially to those of you who shared your thoughts and opinions. I enjoyed the discussion and I hope you did as well. This was the first time I’ve done such a talk at this style of group, which typically just has a speaker lecturing for 90 minutes or so, and I thought it went well but of course I welcome any comments. I quickly looked through the evaluations after ...
by ssmith via Blog on 10/27/2010 2:31:33 PM
If you’re using XML Comments for intellisense purposes, or are making heavy use of attribute-based metadata in your classes, you’ve likely found that these have a tendency to bloat your code and make it more difficult to follow. For example, consider this simple configuration section handler: 1: public class DemoSettings : ConfigurationSection, IDemoSettings 2: { 3: private static readonly DemoSettings settings = 4: ConfigurationManager.GetSectio ...
by ssmith via Blog on 10/5/2010 3:24:00 PM
Ran into this issue last night and just figured it out. I have this code for a demo: using System;using System.Data.Objects;using System.Transactions;using ExtractTransformLoad.Domain;using Northwind.Entities;//using System.Linq;namespace ExtractTransformLoad{ public class SqlFreightByShipperRepository : IFreightByShipperRepository { public void DeleteAndInsert(DateTime runDate, FreightByShipper freightByShipper) { using (var context = new NorthwindEntiti ...
by ssmith via Blog on 9/29/2010 4:02:00 PM
Over the past few years, I’ve established something of a standard for how I like to organize my projects, and this includes having a one-click build-and-test script for each project. This is a quick description of my current thoughts on this, along with some details of how to get the MSBuild scripts working for your project as well. The ultimate goal is that you, a new developer who just pulled down the source from the version control system, and the build server can all run a build ...
by ssmith via Blog on 9/22/2010 12:04:55 AM
In Real World Monitoring and Tuning ASP.NET Caching Part 1, I showed the behavior of a certain ASP.NET application under load. We resolved the issue today, which turned out to be a result of two related issues that, thankfully in our case, were limited to a single class in our application that was responsible for interacting with our cache. Here’s the old behavior: The new version of the same application, under pretty much the same load, looks like this: Note the lack of ever ...
by ssmith via Blog on 9/18/2010 6:33:00 AM
Updated 5 October 2010: There is now a patch available via Windows Update. Read more about it here, and ensure all ASP.NET web servers have been patched ASAP. Microsoft just released some details on a security flaw that was publicized a few hours ago. On this post, you can learn more about the ASP.NET vulnerability and how to detect whether your web sites might be affected by them. This is a serious flaw that you should take steps to address as soon as possible, since the attac ...
by ssmith via Blog on 9/17/2010 3:44:55 PM
Using Visual Studio 2010 (and some earlier versions), it’s very easy to create a WebTest by recording one or more web requets to the system under test (SUT). To get started, open Visual Studio 2010 and create a New Project. Then select Test Project like so: Next, add a Web Test to the project, and hit the URL you want to test (the one that accepts multiple different parameters that you want to make dynamic). Run the test and verify it passes with a single set of hardcoded pa ...
by ssmith via Blog on 9/8/2010 9:19:00 PM
First off, let me direct you to a great article on monitoring your ASP.NET cache API behavior. Go read that first, then come back here. Done? Good, so let’s make the advice from Simon’s blog a bit more concrete with some real-world examples. Consider this fairly high-traffic web server’s behavior (avg. 55 ASP.NET requests/sec, 110 max, at the moment): Notice how the RAM sort of falls off a cliff, and at that same moment, CPU is much higher than usual? That&rs ...
by ssmith via Blog on 9/1/2010 12:22:00 AM
In .NET, it’s very easy to set up custom configuration section handlers to handle your application or component’s configuration needs. As my previous post shows, it’s also very easy to configure these with attributes that enforce required fields and other validation. However, over time it’s very easy to create fairly large configuration sections that violate the Interface Segregation Principle, which states that classes shouldn’t be forced to depend on things they don’t need. Consid ...
by ssmith via Blog on 8/24/2010 2:11:49 PM
I just ran into an odd issue with a VS2010 project. In my case it was an MVC 2 application I was upgrading from VS2008. One of the built-in controllers (ProfileController) was failing to compile because it could not resolve the Linq extension method symbols Single() and Matches(). These are located in the System.Core assembly. I checked my project references in Solution Explorer, and System.Core was not listed. So I tried Add Reference, and System.Core was listed as ...
by ssmith via Blog on 8/18/2010 3:47:01 AM
There are a number of code analysis tools available for .NET developers, including some stats that are built into the pricier SKUs of Visual Studio. Recently, I’ve been playing with a relatively new product (released earlier this year by Microsoft agile consulting shop NimblePros.com) called Nitriq. Nitriq is a bit like LINQPad for your code. If you’re not familiar with it, go download LINQPad now – it’s a great tool worth paying for. I’ll wait until you’re back… Back? ...
by ssmith via Blog on 8/17/2010 5:53:53 PM
The idea of Design By Contract has been around for quite a while, and Microsoft Research has had a project focused on this topic for several years now, called Spec#. With Visual Studio 2010, there is now support for Code Contracts which are a DevLabs project based on the Spec# project. You can read more about and download Code Contracts for VS2010 here. Once you’ve downloaded and installed Code Contracts, you’ll have a new tab in your VS2010 projects: With the Code Contracts inst ...
by ssmith via Blog on 7/2/2010 6:42:04 PM
If you’re writing an HTML Helper for ASP.NET MVC you may want to do something different based on whether the page that is to be rendered was arrived at via a particular controller or controller action. I found the following code which does just this in one of the ASP.NET MVC Themes available from the www.asp.net web site (the Dark theme, I believe it’s called). Note that I’ve already modified this code to work with the new ASP.NET 4 string encoding and the MvcHtmlString type, as I wrote a ...
by ssmith via Blog on 6/24/2010 5:36:26 PM
If you have ASP.NET MVC 1 code you are moving to ASP.NET MVC 2 (and ASP.NET 4) you are likely to encounter a problem in which your application starts displaying encoded HTML on the page rather than the actual results of that HTML (e.g. you see <a href … /> instead of a hyperlink). One of the greatest features added to ASP.NET 4 is a new way to render content that is encoded by default in your .aspx/.ascx pages/views. This new syntax uses <%: Model.SomeString %> instead of the ...
by ssmith via Blog on 6/21/2010 1:32:00 PM
In my last post about testing emails in .NET, I noted the use of the using statement to ensure safe usage of the IDisposable SmtpClient and MailMessage objects. This is the typical usage of the using statement, but you can take advantage of this statement’s behavior for other scenarios as well, resulting in cleaner code. Consider the scenario where you want to perform some kind of pre- and post- processing around an arbitrary block of code. The simplest scenario I know of is when yo ...
by ssmith via Blog on 6/18/2010 6:00:00 PM
Recently I learned a couple of interesting things related to sending emails. One doesn’t relate to .NET at all, so if you’re a developer and you want to easily be able to test whether or not emails are working correctly in your application without actually sending them and/or installing a real SMTP server on your machine, pay attention. You can grab the smtp4dev application from codeplex, which will listen for SMTP emails and log them for you (and will even pop-up from the system tra ...
by ssmith via Blog on 5/17/2010 7:28:57 PM
In your code, you’ll sometimes have write code that validates input using a variety of checks. Assuming you haven’t embraced AOP and done everything with attributes, it’s likely that your defensive coding is going to look something like this: public void Foo(SomeClass someArgument) { if(someArgument == null) { throw new InvalidArgumentException("someArgument");
by ssmith via Blog on 5/7/2010 2:25:00 PM
RESTful interfaces for web services are all the rage for many Web 2.0 sites. If you want to consume these in a very simple fashion, LINQ to XML can do the job pretty easily in C#. If you go searching for help on this, you’ll find a lot of incomplete solutions and fairly large toolkits and frameworks (guess how I know this) – this quick article is meant to be a no fluff just stuff approach to making this work. POCO Objects Let’s assume you have a Model that you want to suck data int ...
by ssmith via Blog on 5/5/2010 4:38:00 PM
Most .NET developers who need to store something in configuration tend to use appSettings for this purpose, in my experience. More recently, the framework itself has helped things by adding the <connectionStrings /> section so at least these are in their own section and not adding to the appSettings clutter that pollutes most apps. I recommend avoiding appSettings for several reasons. In addition to those listed there, I would add that strong typing and validation are add ...
by ssmith via Blog on 4/16/2010 6:45:03 PM
ASP.NET MVC 2 adds support for data annotations, implemented via attributes on your model classes. Depending on your design, you may be using an OR/M tool like Entity Framework or LINQ-to-SQL to generate your entity classes, and you may further be using these entities directly as your Model. This is fairly common, and alleviates the need to do mapping between POCO domain objects and such entities (though there are certainly pros and cons to using such entities directly). As an examp ...
by ssmith via Blog on 3/2/2010 9:41:45 PM
Yesterday I was looking at some old code and refactoring it to clean it up (in this case I wasn’t the original author, but I’ve written code just like this). The application in question was a simple process that had to run once per month, on demand, and so was coded up as an EXE application. As it ran, it provided updates on its progress, so it looked something like this: static void Main(string[] args) { Console.WriteLine("Starting Application @ " ...
by ssmith via Blog on 2/26/2010 10:35:04 PM
I just ran into a problem with SQLite and NHibernate, which was giving me this error message: The IDbCommand and IDbConnection implementation in the assembly System.Data.SQLite could not be found. The strange thing was, it worked fine from within Visual Studio, but it died when I used my ClickToBuild.bat file, which calls msbuild and runs my tests from the command line. A bit of searching led me to a similar problem on StackOverflow, which produced the answer: Use the x64 binaries. ...
by ssmith via Blog on 2/10/2010 5:57:00 PM
Building software applications is sometimes compared with building structures out of smaller components. The children’s toys, Legos (and their generic brethren), come to mind and in fact make for a good analogy. Given a set of components with varying characteristics (shape, color, etc, or in the case of software, objects with different behavior and state), it is possible to connect the components in order to create a larger structure, with (hopefully) more advanced capabilities. Th ...
by ssmith via Blog on 12/18/2009 2:25:22 PM
I’m very pleased to see Microsoft respond to customer feedback requesting a little bit more time before the release of Visual Studio 2010. There has been concern with the current beta release that its performance is not where it needs to be, especially in certain specific scenarios. Microsoft is aware of these issues and has a number of fixes under way or already checked in, but the concern among the community was that there wouldn’t be time for another broad beta or RC release of V ...
by ssmith via Blog on 10/22/2009 3:53:37 AM
Tonight at Hudson Software Craftsmanship, I paired with another group member and worked on the PotterKata for the first time. I’d seen NotMyself write about it a few days ago, which prompted me to suggest it for the group to work on (summary of the meeting here). Briefly, this kata is a fairly real-world exercise in that it has to do with business rules for a shopping cart that are non-linear. In this case, the rules are: One copy of any of the five books costs 8 EUR. If, howeve ...
by ssmith via Blog on 9/6/2009 4:39:00 AM
The LINQ Aggregate() extension method uses a Func<int, int, int> to operate on items in a series. If you want to use it, for example, to return the product of each value with its successor, you can do something like this: Func<int, int, int> producter = (one, two) => one * two; var result = subString.ToCharArray().ToDigits().Aggregate(producter); Of course, you don’t need the intermediate value. You can simply use a lambda directly for the Aggregate ...
by ssmith via Blog on 9/6/2009 3:53:00 AM
Euler problem 7 requires returning the 10001st prime number. It notes that the 6th prime number is 13 in the problem description. Having already done some work with iterators and various number generators, including a Primes generator for previous Euler problems, the base case given in the problem can be reduced to this NUnit test: public void SixthPrimeIs13() { Assert.AreEqual(13, NumberGenerator.Primes().Take(6).Last()); } Replacing the 6 with 1000 ...
by ssmith via Blog on 8/27/2009 6:19:00 PM
Recently I’ve been doing some Project Euler problems as exercises to help improve my coding skills. We do this internally at NimblePros periodically and also at last weeks Hudson Software Craftsmanship meeting, which I co-run. In doing these problems, I’ve been trying to approach them both from a traditional C# 1.0 standpoint as well as using newer constructs such as lambda expressions, LINQ, and iterators. It’s amazing how much more flexible a design can be through the use of ...
by ssmith via Blog on 8/26/2009 4:19:00 PM
One of my applications relies on a singleton pattern to create a single instance of a server which processes requests from many different ASP.NET handlers. It is created using pretty much standard Singleton code: public static Context CreateContext() { return CreateContext(new ConfigurationFileSettings()); } Recently, this server needed to be made aware of whether requests were coming into it via SSL or standard HTTP. The solution that was checked i ...
by ssmith via Blog on 8/25/2009 4:00:15 PM
Recently I was reviewing some code and ran across this – can you spot the problem? var parameters = new List<SqlParameter> { new SqlParameter("@SomeID", someId), new SqlParameter("@SomeOtherID", someOtherId), new SqlParameter("@ServerDate", serverTime) }; string cacheKey = string.Format("ResultSetName-sid{0}-soid{1}-date{2}",
by ssmith via Blog on 6/18/2009 2:48:47 AM
I’m working on a little application right now that provides some insight into the assemblies in use for a given application. One of the things that I want to be able to show is whether or not each assembly was built in Debug or Release mode. As you’re no doubt aware, running applications in production that were built in Debug mode can be a major performance problem (at a minimum – depending on what else you have turned on in Debug mode it could also be a security issue). So I did so ...
by ssmith via Blog on 6/11/2009 7:50:00 PM
Sarah suggested Tuesday that I write a blog PostFormatter that only changed the format of blog posts created on days that were Fibonacci Sequence days (e.g. 1, 2, 3, 5, 8…). I’d hoped to code something like that up during my Ann Arbor talk last night but ended up not having the time, so just to show how easily this could be done, I threw something together today. First, this is for a demo application that I used in my talks this week – if you want to follow along, grab t ...
by ssmith via Blog on 5/12/2009 4:30:27 PM
I’m wiring up the IoCControllerFactory from MVCContrib into an MVC application and I kept running into an issue where a request was coming in looking for a ContentController. The reason for this is that in my CSS file I have a property like this: background: transparent url(images/logo.gif) no-repeat scroll left top; which is in the Content folder. The resulting request for “/Content/images/logo.gif” was matching the default routing rule: routes.MapRoute( & ...
by ssmith via Blog on 2/11/2009 9:42:28 PM
I’ve been working with Azure off and on since last summer, and like any new API or platform, there are hurdles involved with the learning curve. This is especially true for pre-release software that is rapidly changing and of course has neither official documentation nor much in the way of info on blogs or developer community sites like ASPAlliance.com. One of the ways I like to learn about projects these days is through testing. Ideally, the project will already have a suite o ...
by ssmith via Blog on 2/11/2009 7:59:34 PM
When using ASP.NET MVC to post data that might contain HTML or other potentially “dangerous” data, the default behavior as of the Release Candidate is to throw an exception, preventing the posting of the data. This is a well-known feature of ASP.NET that was introduced several versions ago, and the typical way to avoid it (when necessary for the application’s function) is to add validateRequest=”false” either to the @Page attribute or to the <pages /> section in web.config. Not ...
by ssmith via Blog on 2/9/2009 3:47:56 PM
Recently we’ve been separating our monolithic application into smaller systems which communicate via services. We’re using WCF for this communication, and one of the things that we’ve quickly noticed is that WCF is, for whatever reason, not compatible with the usual best practice of wrapping IDisposable objects with a using() {…} block. Personally, I don’t think resources should be marked IDisposable if you can’t simply use the using() statement. The issue with the case of WCF’ ...
by ssmith via Blog on 12/10/2008 5:19:59 AM
The saga began here. Where I left off, I'd managed to create a new class for handling the storage of my creative files, called CreativeFileStore. This method took in an IFileSystem as a parameter to its constructor, which provides two benefits: Testability Flexibility - I can swap between WindowsFileSystem and AmazonS3FileSystem easily In the interest of keeping the individual posts at a reasonable size, I didn't include all the tests for the CreativeFileStore, but here's a summary: 1 ...
by ssmith via Blog on 12/10/2008 12:34:01 AM
Still working on cleaning up some legacy ASP.NET code. Here's where we are: Part 1: Define problem and demonstrate IFileSystem basic version Part 2: Spike solution to support saving files in IFileSystem that works in both Amazon S3 and the Windows file system Part 3: Initial refactoring via TDD of big ugly method Now it's time to take the big step of pulling the main ugly method guts out into its own object. Since the main purpose of the method, GetImageOrFlashData(), is to store a ...
by ssmith via Blog on 12/9/2008 8:06:25 PM
In part one I described the problem. In part two I worked out the details of how to save files in a platform-ignorant way by creating a spike solution. Now I'm looking back at my original ugly method from part one and extracting it into its own class that accepts an IFileSystem instance via constructor injection. Looking at the original method, it has a number of dependencies and issues. My next step is going to be to get it out of the untestable ASP.NET codebehind file and int ...
by ssmith via Blog on 12/9/2008 3:20:54 AM
In my last post in this IFileSystem series, I described the problem I'm working on of removing a dependency on the System.IO Windows file system in my ASP.NET application. A bit of research on this subject revealed some help on making file uploads testable by ScottHa, but his technique still makes use of the SaveAs() method and ultimately ties the solution to the server file system. A similar post on creating Unit Test Friendly File Uploads was more helpful, in that it provided some ...
by ssmith via Blog on 12/8/2008 6:08:14 PM
In the course of making my software more testable, I’ve attempted to eliminate a dependency on the file system (in this case, via System.IO) by creating an interface, IFileSystem. I just did a quick search for this term and came back with only one C# interface (in the first few results) that matches this, which is for CC.NET, and looks like this: My basic version of the interface is similar: public interface IFileSystem { bool FileExists(string path); vo ...
by ssmith via Blog on 10/20/2008 4:45:00 PM
In the last year or so I've really seen the light on how to really write loosely-coupled code. I thought I knew something about this concept before - I mean, I knew loose coupling was good, generally speaking, and I knew data abstraction was one of the key ways to limit dependencies between classes. However, I didn't realize that I was unintentionally adding all kinds of coupling into my applications despite my best efforts to the contrary. Let's talk about some dependencies, i ...
by ssmith via Blog on 9/25/2008 4:54:17 AM
This is a follow-up to my post about avoiding dependencies with design patterns. It left off with something like this as a Cart object that uses the Strategy pattern to avoid a direct dependency on SMTP emails. 1: public class Cart 2: { 3: private ISendEmail emailProvider; 4: //public Cart() 5: //{ 6: // emailProvider = new LiveSmtpMailer(); 7: //}
by ssmith via Blog on 9/22/2008 1:39:00 PM
I've been asking for a recursive FindControl() method as a method off of System.Web.UI.Control for years but so far no luck. You find yourself needing these frequently when you work with composite controls, like most of the Login family of controls introduced with ASP.NET 2.0. In particular, LoginView, CreateUserWizard, and Login frequently require a technique like this to access their contents. I posted a simple version a while back; Michael Palermo updated it, and Aaron Robson post ...
by ssmith via Blog on 9/19/2008 3:09:09 PM
I've been manually adding DotNetKicks icons to my posts recently to try and generate more buzz for them, but that gets old quickly, so about an hour ago I decided to figure out how to make this automatic. My current blog engine is Graffiti, which I really like, and after doing some searching for a pre-existing solution, I pinged ScottW on IM about the problem and he set me down the right path within seconds. The Problem DotNetKicks will display a dynamic image with a count of how many "kic ...
by ssmith via Blog on 9/19/2008 3:34:02 AM
I gave a one day class to about 20 developers today introducing Microsoft .NET, C#, and ASP.NET. As it was only one day and there were no hands-on labs, coverage was necessarily cursory, but overall things went very well. In the course of discussing the Base Class Library and specifically the areas of logging and sending emails (System.Diagnostics and System.Net), I was careful to emphasize to the class that they should definitely avoid making direct calls to these namespaces' members for their ...
by ssmith via Blog on 7/7/2008 1:57:59 PM
Oren has a post showing how he deals with time sensitive code in his unit tests. One thing that's interesting is that, like my previous post, deals with the System.Func<T> construct introduced in .NET 3.5. I see this convention more and more and it's really growing on me. I've dealt with timing issues in my own code using a convention similar to the one Ayende demonstrates, which is to create a singleton or static property for the system time, and consistently reference t ...
by ssmith via Blog on 7/7/2008 1:03:12 PM
Karl Seguin has an interesting post about using System.Func to fight repetitive code blocks, which actually addresses a pain point I've had for quite some time but had never acted on to fix. Whenever one access the Cache or a similar statebag that might or might not contain the value sought after, it is important to check if the value exists first, and if it doesn't, go and retrieve it from wherever its authoritative repository is (typically the database). This can be done poorly, so ...
by ssmith via Blog on 7/2/2008 4:00:44 PM
I'm strongly considering adopting the use of an IsNull extension method in my .NET 3.5 coding projects. A quick search to see what others have to say about this revealed a new web site dedicated to extension methods, which includes this IsNull method ready to go: pubic static bool IsNull(this object source){ return source == null;} The String class supports the IsNullOrEmpty() method now, but you have to pass it your instance yourself. This is another good candidate for Extension M ...
by ssmith via Blog on 5/1/2008 2:00:00 PM
I interviewed a couple of college students earlier this week for internship positions with Lake Quincy Media, and one of them reminded me of my own college days when we were graded in part based on how well commented our code was. In school, comments are typically there as a "check the block" measure to ensure that the professor doesn't take off points for not having them, but in the real world comments can actually serve a good purpose. One of the things you learn with ...
by ssmith via Blog on 1/8/2008 4:26:31 PM
Al Pascual wrote about some trends he noticed using Google Trend, with regard to different programming languages. It's an interesting tool, since it can be used to gauge general interest in particular keywords and search terms, as well as news, going back about 4 years. For instance, here's a comparison of Visual Basic and C# using common search terms for each (VB, VB.NET vs. C#, CSharp): Given just these search terms, it's clear that VB/VB.NET is on a downward trend, with C#/CSharp ...
by ssmith via Blog on 8/7/2007 6:54:00 PM
We ran into this issue today: A LoginView control that has always worked just fine was failing to have any contents on a PostBack. Stepping through it and checking things in the Immediate Window confirmed that it had a Controls.Count of 0. Looking at it in ASP.NET Trace also showed that, after a postback, it had no controls below it in the control tree. This was a problem since it contained a DropDownList and a TextBox that we needed to save the contents of in a click handler, ...
by ssmith via Blog on 7/13/2007 7:33:38 PM
I recently heard about a set of controls that is being made freely available via CodePlex with the goal of improving the usability and consistency of medical software applications. The Microsoft Health Common User Interface (CUI) includes a suite of rich controls and guidance for building user interfaces that follow a standard approach to user interface design. The CodePlex Project for MSCUI includes the controls library. The controls are freely available and open source, so th ...
by ssmith via Blog on 6/27/2007 4:51:06 AM
I just finished reading Jon Galloway's post, The value of "good enough" technology, and it reminded me of something I repeat very often in my talks on improving performance and/or caching (which share some content as you may imagine). I wanted to emphasize one point a bit more succinctly than Jon did, and that is that in software development (and I imagine in any endeavor where resources are constrained): Going beyond merely good enough is wasted effort. What does this mean? It means ...
by ssmith via Blog on 6/17/2007 5:12:00 AM
Plenty of others have written about this so I'll keep it brief. I needed to sort some objects based on a string property. Some quick searching led me to this post which got me close to what I wanted. My final code was this:myThings.Sort(delegate(Thing x, Thing y) { return String.Compare(x.Name,y.Name); }); myThings is a List<Thing> collection. String.Compare done in this fashion will sort them alphabetically - reverse its parameters to sort in reverse. Share thi ...
by ssmith via Blog on 4/10/2007 7:42:55 PM
As part of my automated build and test process, I wanted to be able to confirm that my third party components were the proper version and, more importantly, that they were fully licensed. For some components, I can create a new instance of the control or component and test its IsLicensed property. For others, the assembly itself is different for evaluation versus professional versions, and another approach is required. In the first case, the code required to test if the control ...
by ssmith via Blog on 10/2/2006 9:52:32 PM
CSharpFeeds is a simple community site dedicated to keeping up with the latest goings-on in the C# world, while eliminating the noise and personal/social posts from the various C# blogs out there. This task involves individually touching each post to approve or reject it as on-topic, and while this is not a terribly arduous process, we could use some help. If you are a C# guru and would like to devote a few minutes (literally, like maybe 5–10 minutes) a day (or even a week) to ...
by ssmith via Blog on 9/1/2006 2:08:02 PM
Frans Bouma, creator of LLBLGen, MVP, and all around very smart guy, wrote yesterday about the ‘myth’ that caching inside an Object-Relational (O/R) mapper makes queries run faster or makes the O/R mapper more efficient. I think he’s missing a few key usage scenarios (and, what’s more, I think he generally has a dislike of caching for whatever reason, which may bias his opinion), which I’d like to examine here. First, let me look at his definition of a cache, ...
by ssmith via Blog on 8/24/2006 1:49:00 AM
There's an example in Professional ASP.NET 2.0 that shows how to add a few profile items to a CreateUserWizard. Unfortunately, it doesn't work in certain cases, specifically when the profile item in question is set to allowAnonymous="false". When that happens, you will receive this error:"This property cannot be set for anonymous users."One fix is to simply set the allowAnonymous flag to true, but if it's not something you want anonymous users to be ab ...
by ssmith via Blog on 7/31/2006 8:06:39 PM
Today CSharpFeeds officially goes live. This is a pet project of mine and Gregg Stark’s based on Serge’s VBFeeds.com site and its source code (thanks to Serge for letting me see the source!). VBFeeds is a great place to find just VB information from the top VB people, moderated so that it doesn’t include posts about going on vacation or other personal posts. C# Feeds seeks to do the exact same thing, but for C# content, rather than VB. If there’s a C# feed we should be pu ...
by ssmith via Blog on 7/20/2006 2:39:19 PM
Murach’s C# 2005 is one of many books I’ve picked up since .NET 2.0/VS2005 went gold last November. I have to say, I really love the layout of Murach’s line of books. The book would make an ideal textbook for a training class, but outside of a training environment it is still a great learning tool. In addition to great technical material, each chapter also includes practice exercises. Joe Stagner recently blogged about the book, too, saying: But ...
The content of the postings is owned by the respective author. CSharpFeeds is not responsible for the contents of the postings. This site is automatically generated and cannot be reviewed for abusive content. If you find abusive content on CSharpFeeds, please contact us. Designated trademarks and brands are the property of their respective owners. All rights reserved.