Archives

Archives / 2011 / January
  • Tip - Override ToString() in Objects

    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 present at least the bare-bones information about this state.  If it’s a customer, maybe the .ToString() renders their customer ID and name.  If it’s an … more

  • Live Essentials Evilness

    Hey, Microsoft, please stop trying to reset my home page and change my search preferences when I install the one tool from Live Essentials that I find useful, Live Writer (which is awesome, by the way).  I’m pretty sure my browser already has a preferences section wherein I can set my home page, and likewise my search engine of choice, and your presumption that by installing another tool that is related to my browser only inasmuch as it happens to use the Internet that somehow I want your advice on how I browse the Internet is annoying and insulting. Honestly, I don’t mind the “Help improve our stuff” box, but this dialog is evil because: 1. It shows up long after I’ve already … more

  • Where is Outlook 2010 Export

    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 so Outlook 2010.  Clicking on the File tab, reveals this: Notice – nothing to do with Exporting.  You can click around on some of the other tabs.  Home, Send / Receive, hey, it … more

  • Entity Framework Invalid Object Name dbo.Albums

    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.Albums'. Source Error: Line 26: // the albums with the highest count Line 27: Line 28: return storeDB.Album Line 29: .OrderByDescending(a => … more

  • Database cannot be opened - version 655

    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:\DEV\SCRATCH\MVCMUSICSTORE-V2.0\MVCMUSICSTORE-COMPLETED\MVCMUSICSTORE\APP_DATA\MVCMUSICSTORE.MDF'. CREATE DATABASE is aborted. An attempt to attach an auto-named database for file … more

  • ViewBag does not exist in current context

    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 Store demo and your “ViewBag does not exist in current context” errors should disappear. Update: You may still see this error if you have an application that you built using … more

  • Creating a WHERE NOT EXISTS or WHERE NOT IN Query Using LLBLGen

    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 ) If you needed to do this using LLBLGen, and you didn’t know a better way, you could achieve this by first getting all of the tagged messages (easily done using an existing relationship), and … more

  • How Do I Use StructureMap with ASP.NET MVC 3

    Update: If you want to use StructureMap with ASP.NET MVC 5, I have a walkthrough on this now as well.

    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 application starts.  You can put all of your container registration stuff … more

  • Sharp XV-Z9000U Projector Won’t Power Up - Solution

    I have a fairly old projector that recently required a new bulb.  It’s a Sharp XV-Z9000U model, which has bulbs that last for something like 2000 hours, and the projector has a timer in it that starts warning you when you’re approaching this number.  Ultimately, when you’ve ignored the warnings long enough (because the existing bulb keeps on working fine), the projector starts to shut itself down.  This is either a ploy to ensure regular purchases of replacement bulbs (albeit not all that frequently), or is perhaps some kind of safety feature since maybe the bulbs explode spectacularly when they fail, so replacing them prior to that point is a good idea. In any case, I … more

  • Lessons Learned Performing Harry Potter Book Kata

    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 the repetition of known good solutions). Lesson One – Test The Small Stuff This isn’t really a spoiler, so I’ll start with it.  Steve and I tested all of the basic cases in the problem like 0 … more

  • How do I Change Where MSMQ Messages are Stored or Persisted?

    If you are using MSMQ, either directly or with the help of a package like NServiceBus, you may encounter errors if your server becomes overloaded with messages either due to high load or as a result of a failure in your message handling process.  If this happens, you may see exceptions like this one (ask me how I know this…): System.Messaging.MessageQueueException (0x80004005): Insufficient resources to perform operation. at System.Messaging.MessageQueue.SendInternal(Object obj, MessageQueueTransaction internalTransaction, MessageQueueTransactionType transactionType) at NServiceBus.Unicast.Transport.Msmq.MsmqTransport.Send(TransportMessage m, String destination) in … more

  • Unit Test Naming Convention

    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 same context and scenario information to my test organization as well.  Thus, I began striving to write my test classes such that each one described a particular scenario, and each test … more

  • Type was not registered in the serializer exception with NServiceBus

    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 the code. Exception Details: System.InvalidOperationException: Type DataPump.Infrastructure.Messages.MyMessage was not registered in the serializer. Check that it appears in the list of configured … more

  • Attempt was made to load an assembly from a network location

    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.g. NUnit, NServiceBus, etc.) is to Unblock the entire zip file before you unzip it.  Otherwise, every file will need to be Unblocked, which is a major inconvenience. To Unblock either the zip … more