Codepolice

Random posts from Ola in English. Mainly about programming and the web.

C# String Cheat Sheet

I found this great string formatting Cheat Sheet via Twitter some days ago. Just wanted to share it.

‘Row not found or changed’ in LINQ to SQL

Ever got the error “Row not found or changed” when you use Linq to sql. I get this error from time to time and i always forget what it means. But now i write it down here so that i wont forget it again. For me this error message has always been caused by a model (dbml) that do not match the real database. It can be such a small difference as a field is nullable in the physical db but it’s not in your model. So just think back what you changed in your model recently and try to find the difference. The best would probably be to upgrade to Entity Framework but i guess that is not possible all the time.

Upgrade an ASP.NET Webforms application from 3.5 to 4.0

Today i decided to upgrade our site AlternativeTo to ASP.NET Framework 4.0 and naturally there where some stuff that didn’t work. Hopefully someone else who is having the same issues will find this post and get some help from it.

I started by follow this article from MSDN about upgrading from 3.5 (or lower) to 4.0. I followed the manual upgrade process in the article since my site is kind of custom and also because i need to do the same changes in my production enviroment and wanted to know what is happening under the hood.

I should point out that i am running my code in IIS and not in the built in web server to mimic the production environment as close as possible.

  • My first issue was that according to the guide on MSDN i should delete everything in the system.webserver section of my Web.Config. Previously in the article they had pointed out that if i had added any custom stuff anywhere i should keep that. Since i had a lot if custom stuff in my system.webserver section i did not do as the guide suggested here. I guess i should do a trial and error and remove stuff that i think is safe to remove. The reason why you should delete a lot of stuff in the Web.Config is explained by Scott Guthrie in his web.config blog post.
  • After i followed the guide i tried to start my site and got the error “Unrecognized attribute ‘targetFramework’“. I got this error because i had to change the target framework on the App Pool. Just right click the app pool and choose “advanced settings” and you find this setting at the top. But i still got a “anonymous” 500 error after this.
  • Then i tried to create a new site target with .net framework 4.0 and i got a slightly better error 500.19 that was actually “Googleable” and i found out that it was some kind of security issue. I moved my site to a folder outside my “my documents” space and .. another error! yey!
  • I got the error ‘“PageHandlerFactory-Integrated” has a bad module “ManagedPipelineHandler” in its module list‘. This was also kind of easy to find and the post from Got Know How suggested me to reinstall .net framework 4.0 and finally everything worked!

It was actually kind of an easy upgrade. I should point out that i haven’t tested the site that much yet and it’s not installed in my production environment but it should probably not be that big of a deal.