Wednesday, 23 December 2009

SOLVED: Compiler error CS1519: Invalid token 'void' in class, struct, or interface member declaration

This one has cropped up a couple of times in my development activities recently, but with just enough of a gap for me to have forgotten the solution and I had to figure it out again.

It happens in situations where the project worked fine a minute ago and then all of a sudden the project wont run. It has also happened in situations where I have made a small update and then some seemingly unrelated part of the site has broken.

From researching the problem it seems to hint at the server not having the LINQ libraries installed or missing references but from investigation of the projects I found they were both installed and referenced correctly.

It turns out that, for me at least, it was a very simple fix. All you have to do is:

  1. Find the file that is now complaining
  2. Open it up in Visual Studio
  3. Press the space bar and then delete the character you typed
  4. Save the file
  5. Upload the file to the website
  6. Revisit the website

These steps simply "dirty" the file in the eyes of the asp.net compiler and forces it to recompile the website again the next time a visitor requests a page.

My theory as to what is going wrong is that when the previous update caused a recompile the old assemblies are locked and in use / not deleted / forgot about somehow so the next time it tries to run it has two many conflicting assemblies and crashes. That is about as much detail as I can go into though because I am just guessing.

If this article has not solved your problem then the following link could be useful which describes an alternative fix for the problem. It revolves around the fact that you might not have referenced the LINQ libraries correctly:

kick it Shout it vote it on WebDevVote.com

No comments: