Archive for September, 2010

Linq to SQL Query gives an InvalidOperationException with message “Cannot compare entities associated with different tables.”

Wednesday, September 15th, 2010

If you try to do a Linq to SQL query and it runs fine, but gives you an exception of type InvalidOperationException and the message is “Cannot compare entities associated with different tables.” then it probably means that you are trying to pass in an object of one type and compare it to another type.  I suspect that you will probably only get this error if Linq attempts to translate the error to SQL – if you run it in memory, you might not get an error at all, as it may just do a straight object comparison and conclude that they are different objects.

An example would be something like


Dim p = DBContext.People.First
Dim q = From a in DBContext.Addresses Where a Is p
Dim addr = q.First

The final line will result in this exception as Linq to SQL is attempting to translate the query into SQL and it (correctly) can’t find any way of writing a query that compares a person to an address!

App_Offline.htm – ScottGu’s Blog

Tuesday, September 7th, 2010

I just had an interesting message when working on an ASP.NET 2.0 website – “This application is currently offline. To enable the application, remove the app_offline.htm file from the application root directory.

I’m not sure how this happened, but it looks like it may have something to do with this… App_Offline.htm – ScottGu’s Blog.

How to copy locked files in a Windows profile folder (ntuser.dat etc.)

Monday, September 6th, 2010

Not really a programming issue, but if you need to copy files from a Windows profile folder to another location (eg. you want to copy a profile to a different one, make it roaming/local etc) then you may find that Windows has locked the file and won’t let you do it.  If you want to get around this, reboot the PC (logging off probably won’t work) and make sure that you log straight in as a different user who has sufficient rights to access the profile folders for both of the other 2 (eg. the local machine Administrator account).  Windows should let you do the copying then.

Getting Public Key Token of Assembly Within Visual Studio – Kirk Evans Blog – Site Home – MSDN Blogs

Friday, September 3rd, 2010

Very useful tip – sometimes you need the public key for referencing the assembly in things like web.config – see Getting Public Key Token of Assembly Within Visual Studio – Kirk Evans Blog – Site Home – MSDN Blogs.

Windows Forms Designer gives “Value does not fall within expected range” error

Friday, September 3rd, 2010

I was working on a project that I’ve been working on for a very long time in Visual Studio 2010.  I opened a designer and got the error “Value does not fall within expected range”, which was accompanied by a particularly useless stack trace and a dead link to a help article.

Cleaning the solution, closing Visual Studio and reopening it seemed to fix it for me.  Hope this helps!

Companies House Electronic Filing Problems Part 1 – Introduction

Wednesday, September 1st, 2010
This entry is part of a series, Companies House Problems»

I’ve been doing a fair amount of work over the years for a limited company formation agent and unfortunately, this has meant dealing with Companies House.  I’ve not really had much other work where I’ve had to interact with government systems, but I think that, to put it politely, working with Companies House on a technical level has its own unique challenges.

Before I go into too much detail, why am I posting this?  I guess mostly it is because this is my blog and it seems like a good place to vent frustration, but there is also an element that I hope it may help some other people, whether working on similar systems that integrate with Companies House, other government agencies or just other systems that might have similar issues.

If you don’t feel that it is useful then by all means, please feel free to ignore this series of posts – no one is forcing you to read it!

As a bit of background, Companies House is the government agency responsible for forming and maintaining the records for companies, including (and mostly) limited companies in various different forms.  My client is a company formation agent, which means that they deal with forming companies, providing suitable documents for the constitution of the company called memorandum and articles or M&As for short (there are standard ones, but they have all sorts of legal problems) and providing advice about forming companies.  They also have a list of “off the shelf”/”pre-made” company names – companies that they have already set up and are ready for someone to buy and trade with immediately.

As well as all this, they provide a number of other services, mostly targeted towards accountants.  I’m not really going to go into much detail about these, because they don’t involve working with Companies House and that is the topic of this series of posts.

From a technical point of view, it all started quite a number of years back (I forget when exactly), when Companies House started accepting incorporations electronically.  This was done via a rather bizarre system of us sending and receiving emails with numbered tags in to pass the data back and forwards.  This was subject to all sorts of problems and was not very human readable (when the problems happened to try to debug them), so Companies House eventually decided to replace their quirky tag-by-email system with a more modern system of POSTing XML data to a gateway using HTTPS.  They even elected to use the government standard GovTalk encapsulating envelope system to standardise the communications.

Anyway, that’s the brief background – I’ll post some more detail in future posts.

Entries in this series:
  1. Companies House Electronic Filing Problems Part 1 - Introduction
  2. Companies House Electronic Filing Problems - recent annoyances
Powered by Hackadelic Sliding Notes 1.6.5