Regenerating DBML Designer when your database changes

Here’s how to regenerate your DBML code in Visual Studio 2010 when one of your database objects changes:
1. Remove the table
2. Close the DBML designer and save
3. Re-open the DBML designer
4. Re-add the object by dragging from Server Explorer
5. Close the DBML designer and save

In finding this solution, I did find some wailing and gnashing of teeth on-line, with people expecting the DBML code to have some kind of refresh feature for automatically doing this when the database changed.

I must admit I don’t share their chagrin. I am:
* Pathetically grateful for anything that saves me not having to write a hundred lines of property let/get statements
* Impressed by the way projects that reference these objects automatically re-test for compilation as soon as you save the DBML code

Matching in a comma-separated list with Regular Expressions

Tonight’s quiz:
How to see if ‘foo’ is a unique entry in comma-separated list ‘foo,bar,foobar,foo,foo’?

We want to match the ‘foo’ at the beginning, at the end, and also in the middle, but not as part of the word ‘foobar.’ Also the comma-separated list might only be ‘foo’.

First attempt:

Plain wrong, because ^ means something different inside a set

Second attempt:

Works, but clunky.

Third attempt:

Works perfectly. Especially when you remember to escape the ” in your .NET string assignment 🙁

Thanks to the Rad Software Regular Expression Designer too!

Visual Studio Stops Recognising Mouse Input

The shine is starting to wear off Visual Studio 2010 Professional for me. Recently the IDE has started to hang, in a rather strange way. The code editor still appears to respond to mouse events, but nothing actually happens. E.g. you can highlight some code, right mouse click and choose copy from the context menu, but then when you come to paste, nothing happens. Or you’ve been coding away, and you see the file name has an asterisk against it, so you hit ‘Control+S’ to save, but nothing happens. And the only way you can save your changes is by closing the file – at this point VS prompts you if you want to save.

This seems to be something that others have noticed, certainly in the Beta:

One of the tips is to uncheck the ‘Enable the Visual Studio hosting process’ checkbox in Project Properties > Debug pane – and this seems to have fixed it for me.

This is not very impressive. I’ve used all of the previous .NET editions of Visual Studio, and never seen this kind of stuff before.

Parser Error Message: Could not load type

Have been wrestling with the ‘Parser Error Message: Could not load type’ error for the past day and a half.

Plenty of people on Google having the same problem – it turns out my version of this problem was caused by a rather subtle mistake.

The directory structure in my web site is as follows:

I had duly configured app_directory to be an Application Virtual Folder in IIS, and was getting the Parser error every time I opened the following URL:

Before I got as far as the Parser Error Message, I was getting another message:

“It is an error to use a section registered as allowDefinition=’MachineToApplication’ beyond application level” – this error message pointed to the line:
<authentication mode=”none”>

I got round this error by removing the node from web.config – but really this was pointing to the solution.

The URL I should have been accessing was:

I had gotten confused between the physical location of the folder on the server, and the path in the URL. Because the ‘dir1’ folder actually existed, IIS was still able to serve up the URL, including any test HTML pages I placed in the directory, but it did not consider it to be the Virtual Application Folder, and thus I was unknowingly breaking all sorts of rules.

Not sure what I could have done to spot this earlier – and I guess I take back what I was saying about Microsoft at midnight last night. Or some of it, anyway.

DevExpress DXGrid for WPF and Visual Studio Express

Turns out that the DevExpress installer does not integrate DXGrid with Express editions of Visual Studio. Solution is:

1.Manually add references for following assemblies:

2. Manually add namespace to XAML:

You can then add your element as usual.

DevExpress Support also say that you can manually add the following assemblies to the Toolbox to achieve designer support, but that didn’t work for me:
C:Program FilesDevExpress 2009.2ComponentsSourcesDevExpress.DLLDevExpress.Wpf.Editors.v9.2.dll
C:Program FilesDevExpress 2009.2ComponentsSourcesDevExpress.DLLDevExpress.Wpf.Grid.v9.2.dll

Tip: Shared Assembly Attribute File

When you on a solution with several assmblies in .NET, you’ll find yourself maintaining multiple copies of AssemlyInfo.cs, each of which contain a lot of common attributes such as:

You may also wish to make AssemblyVersion uniform accross your build.

A useful technique in this situation is the following:
1. Copy the common attributes out into a new file, called something like ‘GlobalAssemblyInfo.cs’
2. Delete these common attributes from the original AssemblyInfo.cs files
3. Save your GlobalAssemblyInfo.cs file somewhere useful, e.g. in the same folder as your solution file
4. In each project, add GlobalAssmblyInfo.cs through the IDE as a linked file, rather than a straight addition.

Breakpoint conditions

Just started using these in a large project I am maintaining – very useful for working with event sinks that get called every time *anything* happens.

School boy error for the day was thinking in VB rather than C# for my loop condition: ‘i=6’ has changed rather than ‘i==6’ has changed
Assignment never changes, as I found, waiting in vain for my debug window to appear!

IIS and 403.1 Error

Today I was tormented by the following error from IIS:
HTTP 403.1 Forbidden: Execute Access Forbidden

I checked the directory security permissions in Windows, gave everyone under the sun god-like permissions on the whole folder tree, checked anonymous authentication, checked the server logs … but still this error came.

It turns out it was because I had “.com” in the folder name – something it would have taken a couple of months to figure out without Google:
Forum post on Velocity Reviews (new window)

Regex.Replace, $ and $$

Just hit an interesting problem with the replacement argument of Regex.Replace. The issue was that I was passing in variable content to this argument, and it turned out that dollar signs could occur in the content I was passing in. These were interpreted as backreferences, which gave me very different results to the ones I was expecting.

With hindsight, this is kind of obvious, and the solution is simply to replace any single dollar signs in the variable content with repeated dollar signs, as described here:
MSDN on Replacement Substitutions (new window)

See if you can spot any whiff of this looking at the documentation for the method though:
MSDN on Regex.Replace(String, String, String, RegexOptions) (new window)