Error connecting to undo manager

 vs_errorWhile developing a web application for a friend of mine, I ran into a Visual Studio error message I hadn’t seen before: Error connecting to undo manager of source file ‘D:DevelopmentSomeWeb ApplicationDefault.master.designer.cs’.

The error occured whenever I tried to start the (web) application in debug mode. The application did start OK after the error message though. Starting the application without debugging didn’t cause the error.
I closed the solution file I had opened, but that didn’t solve the  issue. Stopping the ASP.NET Development Server didn’t do anything either. I had to exit Visual Studio al together to get this error to go away.

I searched for this specific error, and saw it already occured in Visual Studio 2005 SP1. Scott Hanselman has a blog post on how he solved this issue. Now, in Visual Studio 2008, this error still seems to be in there…

Backing up and restoring Visual Studio settings

When roaming the MSDN forums for unanswered questions for me to answer, I come across a lot of questions about any of the following:

  • Intellisense acting weird
  • Intellisense not showing up at all
  • Menu items that are all garbled up
  • Missing buttons on toolbars
  • Complete toolbars missing
  • Keyboard shortcuts acting weird
  • Keyboard shortcuts not working at all

In most cases, resetting the Visual Studio settings to the default settings using devenv /resetsettings solves any problems that are in that list. But I can imagine you don’t want to go through the hassle of setting up Visual Studio exactly the way you want it again (and again, and…). There’s a solution to that: define your own settings file to restore settings from.

To create a file with your settings, first install Visual Studio (if you hadn’t done so already) and adjust all settings to accomodate your needs. Next, select ‘Tools’ and ‘Import and export settings’. This pops up an import export wizard, where you can choose the ‘Export selected environment settings’ option to create your own settings file. On the next screen, select the settings you want to be able to reset later on. After pressing next, enter a filename to store the settings in and click finish. That’s it!
Restoring your settings is as easy as exporting is: open up the wizard, choose if you want to backup the current settings, select the settingsfile you want to import, select the settings to restore and click finish.

Besides using the import export wizard, you can also use the /resetsettings command line switch to reset to a specific set of settings in a file by specifying that file like so:
Devenv.exe /ResetSettings “C:My FilesMySettings.vssettings”

Technorati tags: ,

Selecting all the controls of a specific type, the (built in!) LINQ way

We probably all worked with dynamically generated controls on forms, ASP.NET pages or (user) controls. And I guess we’ve all written for-each statements to loop through the ControlCollection and filter out all the controls of a specific type, right? I wanted to do the same today, so I started by trying to use LINQ for this:
linq_OfType_1 
This, as you can see, generated a compile time error:
Could not find an implementation of the query pattern for source type ‘System.Web.UI.ControlCollection’.  ‘Where’ not found.  Consider explicitly specifying the type of the range variable ‘control’.

As the error states, this is easily solved by explicitly specifying the type of the control variable. Because a ControlCollection can contain so many types, it is not strange the compiler asks you to be a bit more precise on the type you will be querying. That looks something like this:
linq_OfType_2

But when I added the System.Linq namespace to my using section, I saw an extra method on the ControlCollection, called OfType<>. This method is one of the extension methods that can be applied to a collection that has a non-parameterized type like a ControlCollection or an ArrayList, because OfType<> extends the type IEnumerable.
Another one of those nice ‘native’ Linq extension methods is the Cast<> method, which pretty much does the same but throws an exception if there are any objects in the collection that cannot be cast to the specified type. And yes, exceptions are sometimes wanted ;)

For more info on the OfType<> method, see: Enumerable.OfType<TResult> Generic Method
For more info on the Cast<> method, see: Enumerable.Cast<TResult> Generic Method

Technorati tags: ,,

Error adding an OleDb Data Connection to Visual Studio Server Explorer

The error I’m getting when setting up an OleDB connection to an Access database* via the Server Explorer in Visual Studio 2008 is Incorrect Add Connection screen‘Format of the initialization string does not conform to specification starting at index 0’. The screen doesn’t display the way it should be displayed, as you can see in the screenshot on the left.

There is a possible fix at svenM’s blog (it’s about checking the existence of a key in the registry called ‘ProgID’ and the default value, as you can read in this article), but this doesn’t seem to work for my situation.
It took me some time trying lots of  ‘possible fixes’ (like the registry change, attempts to (re-)install mdac, uninstalling and installing Visual Studio, and so on) . None of them helped. I even went through all four pages of this lengthy thread, but to no avail. The only thing I haven’t tried yet is the most rigorous solution: format the disk and start with a fresh install.

I’m getting annoyed over here…, if you have any tips: let me know.

* I won’t go in to whether an Access file is or is not a database ;). And although I generally wouldn’t consider Access as the database solution for an important business application, I do think it does have its pro’s in specific scenarios, like for a relative small web application.

(Single-Entry, ) Single-Exit, my 2 cents

As a reaction to this article at Peter Ritchie’s MVP Blog, I thought I’d give my two cents on having a single exit point for methods. Here we go…

When writing code, I always create only one exit point except for the occasional throwing of an exception. Most important for me is to always know where your code (really) stops. In case of long and complex methods there’s a chance you’re going to miss a return statement when scanning through a method. That way you could end up studying code not even applicable to the situation, while missing the real point. I do think there is no real reason to hold on to creating methods with a single exit point other than personal favoritism. This feels the same like using curly brackets with an if-statement that is followed by only one statement. I always use curly brackets, but there are lots of developers who don’t.

To answer the questions at the end of Peter’s post: Yes, I do generally follow the Single Point of Exit From Methods Principle, and I do ignore it for exceptions.

BTW: the SESE version of the first method in Peter’s post could be a little less (cyclomatic) complex:

public static int CountCommas(string text)
{
    int result = 0;

    if (!string.IsNullOrEmpty(text))
    {
        int index = text.IndexOf(‘,’, 0);
        while (index > 0)
        {
            result++;
            index = text.IndexOf(‘,’, index);
        }
    }

    return result;
}

Now available: PowerCommands for Visual Studio 2008

One of the most annoying things in Visual Studio (to me) was the fact that complete solutions (solution folders, projects, regulare folder)  would be expanded upon opening. And with big solutions, that isn’t too much fun. There are macros available online, but the ones i found were pretty slow. This is only one of the things that the PowerCommands for Visual Studio 2008 solves for you. But there is more. Much more!

A quick top five of my favorite functions:




  • Collapse projects


  • Copy & paste references


  • Open Command Prompt (at the location of the file you execute it on)


  • Remove and Sort Usings (for all classes in a C# project)


  • Close All (on a tab)

To get the PowerCommands for Visual Studio 2008, or to learn more about all the features in there, visit them over here.

By the way: this fairly new website (the Visual Studio gallery) was released quite silently by Microsoft. It contains lots of products that aid developers while working in Visual Studio, together with some Extensibility stuff. Have a look over there! Another tip: the VSX team blog. It might be a nice one to keep track of new releases of new Extensibility products. There’s a post over there about the PowerCommands, too.

Enjoy!

.NET Framework versioning, or The impact of switching from Visual Studio 2005 to 2008

With the official release of Visual Studio 2008 coming closer and its release on MSDN last november, there are more and more people asking what the impact of migrating from VS2005 to VS2008 will be and if it will have as big an impact as switching from VS2003 to VS2005 had. The answer is pretty simple: no it won’t. Let’s see why, and what impact it will have.

VS2003 > VS2005
VS2003 was the development environment for developing applications based on version 1.1 of the .NET framework. With this came a CLR specific to that version of the .NET framework (version 1.1.4322). When Visual Studio 2005 was released, the .NET framework 2.0 came with it. Because of several architectural changes, like for instance Generics, this version of the framework got it’s own CLR too (version 2.0.50727.42). Knowing this, it is logical that taking an application that was built for version 1.1 of the framework (and CLR) would have to be modified to be able to run on the new version 2.0.

VS2005 > VS2008
VS2008 is the first member of the Visual Studio family that enables multi-targeting. You can have an application target the 2.0, 3.0 or 3.5 version of the .NET framework. That is pretty different from VS2002 (.NET 1.0) and VS2003 (.NET 1.1) that were bound to their specific versions of the .NET framework. The reason it can do that is the same reason switching from VS2005 to VS2008 will not be too hard: these versions of the .NET framework all use the same version of the CLR (version 2.0.50727.42). Although version 3.5 installs Service Pack 1 for .NET 2.0, which adds some methods and properties required for features like LINQ, these changes do not affect applications written for version 2.0 of the .NET Framework.

Impact
Switching to Visual Studio 2008 will not require you to recode parts of your application, but it does have some implications to switch. VS2008 changes your .sln file, rendering it unreadable for VS2005. The projectfiles however are not touched, or at least not in such a way that VS2005 won’t understand them.* The odd one out here is the Web Application Project, which might give some trouble in a multi-VS-development-environment. Have a look at this post at Steven Harman’s blog to see how to work around that.

Language features
Working on a .NET 2.0 project from VS2008 does give you quite some extras, next to the fact that the IDE itself has been greatly improved.** A nice example is from someone who posted this question on the MSDN forums:
(..) while creating properties when I used the code-snippet (…), to my surprise VS 2008 created automatic property. (…) I double-checked the target version by opening project properties and it still showed .NET Framework 2.0. I used this new class in the web page, and it worked fine. How is this possible? Is there a bug in VS 2008 and this code will fail if deployed in production where only .NET 2.0 is available, or did I do something wrong?

The thing here is that automatic properties are not so much a feature of the .NET framework, but of the compiler. So go switch to VS2008, and enjoy.

Happy developing!


* TIP: If you need to edit a .NET 2.0 solution from both VS2008 and VS2005, create two different solutions, one for both. This way, you will be able to open the solution from both versions of Visual Studio. Do be advised! When working in VS2008, you might be tempted to use new syntax that won’t work in VS2005. ;)

** Found a cool new feature or a nice improvement in Visual Studio 2008? Add it to my list @ Listas!

.NET framework source code now available

As stated on ScottGu’s blog in his latest post, the .NET Framework Library Source Code is now available. A detailed blog post about the steps to follow to enable .NET Framework source access in Visual Studio 2008 can be found at Shawn Burke’s blog in this post.

Taken from Scott’s post:
Once you follow the configuration steps in Shawn’s post above, you’ll be able to dynamically load the debug symbols for .NET Framework libraries and step into the source code. VS 2008 will download both the symbols and source files on demand from the MSDN reference servers as you debug throughout the framework code.

Finally getting some coding done

The last weeks have been filled with holidays and introductional days at my new employer. Because of that, I haven’t had the time to realy dive into Visual Studio 2008, although I have played around with it since the RTM version was available. Since this week I’ve been writing some serious code in VS2008 for my new personal site (more about this later!). I can only agree with what Pieter de Bruin said in his post about the new line of developer tools and additions: “If you are building .NET 2.0 applications, you really should take a look at all of the above”.

I’m already loving working with VS 2008. There have been numerous ‘big’ additions and changes which make a developers life so much easier. But how about all the little ones? The ability to run a unittest from the contextmenu of the code editor, the ‘remove unused usings’ possibility (finally!), the enhanced properties form for project properties and so on. All those changes are great! I’m curious what you think are the best additions/changes in Visual Studio 2008. Care to share? Add your favorite at my ‘Best Visual Studio 2008 enhancements‘ list at Listas.

"Some of the properties associated with the solution could not be read"

Next to the message in the subject, one of the symptoms we encountered is that although the solution contains some test projects the ‘Create private accessor’ menu has disappeared. Also, selecting ‘Create unit tests…’ produces an error. And when editing a testrun config and selecting the ‘Code coverage’ option, the settings dialog simply closes, without any message.

All these (and probably more) symptoms can occur because of a corrupt solution file. In our case the nested projects section was corrupted. Chances are this is because of some project or solution folder not being removed the way it should have been. Anyway, I tried fixing the solution file by hand but because of too many projects and solution folders this wasn’t the way to go. Those GUIDs don’t make a file very readable… I made a new solution file, containing the same solution folder structure, and added the existing projects. I overwrote the existing solution file, and that was that. So when you’re experiencing any or all of the above symptoms, try building up a new solution file.

Hope this helps.

Technorati tags: , , ,