Contents tagged with Visual Studio

  • MVC | MvcBuildViews | MachineToApplication Error

    Tags: MVC, .NET,, Visual Studio

    You may come up against this little error when working on a MVC application, I specifically find things like this crop up when you are upgrading from previous version e.g. VS 2008 to 2010 and the like.

    They are a complete pain in the bum quite frankly, you can spend hours googling around, trying this trying that, posting questions here and there etc etc…so I’m adding to the this and that which you will of course try, because it’s the sort of error you don’t care about…it’s just getting in the way of your day!

    There would seem to be some kind of issue with MvcBuildViews and this error

    Anyway, what worked for me was to delete the debug directory from within the obj directory and it all worked…

    Hopefully this will help someone else!! Or at the very least be something else to try on the way to solving another time wasting issue!!

    UPDATE:  May have been a bit hasty in my excitement of solving this…its really only part solved as I find i have to delete the debug directory every time I want to publish/package!


  • Visual Studio 2010: Custom Start Page

    Tags: Visual Studio

    As Visual Studio 2010 IDE has been mostly written in WPF, extending the start page has become pretty darn easy and I for one find this quite interesting as I always open with the start page and the more customisation I can have the better!

    There are a few things you will need to install first to get going

    • Visual Studio 2010 SDK
    • Start page project template, which you can either get from the New Project dialog, in the online gallery section in VS or download from here

    I was going to write a blog post on how to create a custom start page, but decided that msdn have done such a good job I was pretty much wasting my time, so take a look here, it has in detail everything you need to know to get it done! :)


  • Dynamic connection for LINQ to SQL DataContext

    Tags: .NET 3.5, LINQ, Visual Studio, .NET

    If for some reason you need to specify a specific connection string for a DataContext, you can of course pass the connection string when you initialise you DataContext object.  A common scenario could be a dev/test/stage/live connection string, but in my case its for either a live or archive database.

    I however want the connection string to be handled by the DataContext, there are probably lots of different reasons someone would want to do this…but here are mine.

    • I want the same connection string for all instances of DataContext, but I don’t know what it is yet!
    • I prefer the clean code and ease of not using a constructor parameter.
    • The refactoring of using a constructor parameter could be a nightmare.


    So my approach is to create a new partial class for the DataContext and handle empty constructor in there.

    First from within the LINQ to SQL designer I changed the connection property to None.  This will remove the empty constructor code from the auto generated designer.cs file.


    Right click on the .dbml file, click View Code and a file and class is created for you!


    You’ll see the new class created in solutions explorer and the file will open.

    We are going to be playing with constructors so you need to add the inheritance from System.Data.Linq.DataContext

    1. public partial class DataClasses1DataContext : System.Data.Linq.DataContext
    2.    {
    3.    }

    Add the empty constructor and I have added a property that will get my connection string, you will have whatever logic you need to decide and get the connection string you require.  In my case I will be hitting a database, but I have omitted that code.

    1. public partial class DataClasses1DataContext : System.Data.Linq.DataContext
    2. {
    3.    // Connection String Keys - stored in web.config
    4.    static string LiveConnectionStringKey = "LiveConnectionString";
    5.    static string ArchiveConnectionStringKey = "ArchiveConnectionString";
    7.    protected static string ConnectionString
    8.    {
    9.       get
    10.       {
    11.          if (DoIWantToUseTheLiveConnection) {
    12.             return global::System.Configuration.ConfigurationManager.ConnectionStrings[LiveConnectionStringKey].ConnectionString;
    13.          }
    14.          else {
    15.             return global::System.Configuration.ConfigurationManager.ConnectionStrings[ArchiveConnectionStringKey].ConnectionString;
    16.          }
    17.       }
    18.    }
    20.    public DataClasses1DataContext() :
    21.       base(ConnectionString, mappingSource)
    22.    {
    23.       OnCreated();
    24.    }
    25. }

    Now when I new up my DataContext, I can just leave the constructor empty and my partial class will decide which one i need to use.

    Nice, clean code that can be easily refractored and tested.

    Share this post :


  • Postbuild script for Sharepoint project in Windows 2008 and Visual Studio 2008

    Tags: SharePoint, Visual Studio

    Now that is a bad ass title!!

    Anyone who has been through the MindSharp training course for SharePoint and any others that have looked at any code Todd Bleeker puts out there will most certainly be aware of using post build scripts in Visual Studio to deploy your sharepoint project.  This knowledge is of course not limited to MindSharp grads, its just that being one I know what they know!

    To get them to work in a Windows 2008 and Visual Studio 2008 environment you will need to make some changes.  As pointed out here, GacUtil has moved so the command will change from


    "%programfiles%\Microsoft Visual Studio 8\SDK\v2.0\Bin\GacUtil.exe" /if "$(TargetPath)" /nologo

    to this

    "%programfiles%\Microsoft SDKs\Windows\v6.0A\bin\GacUtil.exe" /if "$(TargetPath)" /nologo

    ...and the command to recycle the app pool in IIS7 has changed, if you try the old way you will most likely get a Microsoft.CmdLib error when building from VS.  The required command has changed from


    "%systemroot%\system32\iisapp.vbs" /a "[YourAppPool]" /r

    to this

    "%systemroot%\system32\inetsrv\APPCMD" recycle apppools "[App Pool Name]"

    This is as much for me as everyone else as I no doubt will come up against this again!

    For completeness here is my postbuild script for a custom field project, you might not want to copy the debug pdb file or create a solution (last two commands)

    cd "$(ProjectDir)"

    "%programfiles%\Microsoft SDKs\Windows\v6.0A\bin\GacUtil.exe" /if "$(TargetPath)" /nologo

    "%systemroot%\system32\inetsrv\APPCMD" recycle apppools "App Pool Name"

    xcopy "TEMPLATE" "%CommonProgramFiles%\Microsoft Shared\web server extensions\12\TEMPLATE\" /ys

    xcopy "$(TargetDir)*.pdb" "%systemroot%\Assembly\GAC_MSIL\OC.Sharepoint.FieldTypes\[token]\" /ys

    MakeCab.exe /f FileName.ddf


  • Microsoft Source Analysis for C#

    Tags: .NET, Visual Studio

    image I was just about to blog about this, then I found this post while scanning the feedGuy Barrette does a great job of summarising it.

    If your in a rush, the home page is:

    and you can download it from here:

    While in the link mode; I spotted this at the same time on Charlie Calvert's blog a quick list of keyboard shortcuts for VS2008


  • Error | EventType clr20r3

    Tags: .NET, Vista, Visual Studio

    As errors go I found this one is pretty horrific.

    I got the error deploying a windows service written in .net 3.5 from my Vista x86 dev rig, to a 2003 x86 server.  Only having the .NET runtime installed on the server I wrapped the service up in a deployment project.  The service installed fine, however when trying to start the service I got a "The service did not respond in a timely manner" error.  Initially, like you would, I thought there was probably an error with my code in the OnStart method, but alas nothing in my beautifully crafted exception logging framework(!), over to the event viewer and this little beauty!

    The complete error is...

    EventType clr20r3, P1 <servicename.exe>, P2, P3 4816d837, P4 system, P5, P6 471ebf0d, P7 36d5, P8 7f, P9 system.argumentexception, P10 NIL.

    The error is titled...

    .NET 2.0 Runtime error. (Which through me a little, I'm on .net 3.5!!)

    After some intense googling I have pretty much "Jack", no clear answer from the MS forums, despite input from MSFT staff.  Something that kept popping up was that I was referencing something in the framework that wasn't installed on the server.  So I checked every reference manually on the server, I even thought there might be a problem because some of the .NET dll's on my machine are in "/ProgramFiles (x86)/...." the server not being x64 didn't have this folder so, I created it! (Not convinced, but worth a shot!) Nope, same error.

    Right, most who have seen this error report no problem on their dev machine with VS installed and get it on machines with just the runtime installed.  So, feck it, I installed VS 2008 on the server (clutching right!), I just though perhaps there was something VS installed that I was referencing the very least I would have debug tools installed, speed up the process and could rule it out.  Nope, same error.  Now I can't actually attach a debugger to the process can I, as the service hasn't won't start!

    This is mental!  As far as I was concerned I had nowhere else to go.  By the way, somewhere in there I actually tried to run the service on a different x64 2003 server, but still the same error.  I got another service I have been working on, hacked it about so it would build and run (making sure I was referencing the same libraries as original project).  Same drill, wrapped it in an installer, spun it up on the server, started first time!!!  Right, nothing to do with the framework, clearly the issue is local to my project.

    I created a new project and copied in any custom classes and basically replicated exactly what the problem service was doing, IT WORKED.  The only thing different, when I created the first project, I deleted the "Service1" that the project template creates.

    If you have made it this far down the post in anticipation of the first cause and "concrete" solution for this error, I am sorry to disappoint, but all I have is it to create a new project and start again...VS must be doing/wanting something weird in the background.  After wasting a hours on this I don't have the inclination of patience to look further/deeper.

    Perhaps someone has had similar experiences with the error and could enlighten the rest of us?


  • MS: Would it really have been so difficult?

    Tags:, Silverlight, Visual Studio

    When working with and now XAML I lean towards code view over the designer, a preference of course, but considering this feature I guess I am not alone.  When working with events in XAML you can simply type "Click=" and the nice little helper jumps up asking what event handler you'd like to wire it up to or even create a new one and the stub will be created. NICE!


    As an added little beauty, this doesn't automatically send you off into the code behind.

    Why-o-Why isn't it the same for markup?


  • 1