Codepolice

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

Attach the Visual Studio debugger to Expression Blend for Windows Phone

I just watched Laurent Bugnion’s excellent talk about MVVM (Model-View-ViewModel pattern) from the MIX10 conference. In that talk he shows a cool trick when he attach the Visual Studio debugger to Expression Blend which lets you debug your design time code. It’s often really hard to figure out why your design time data doesn’t show up when using the MVVM pattern and this trick really helps you.

I had some problems to get it to work thou. First i thought it was some stupid limitation in Expression Blend for Windows Phone but after a while i realized that i had to choose “Manged (V4.0) code”. The default in my version of Visual Studio where “Manged (V2.0, v1.1, v1.0) code”. When i changed this everything worked perfectly. A more step-by-step description of how this works can be found here.

Find App ID so you can link to an Windows Phone 7 app on the Zune Marketplace

I wanted to link to a couple of of apps on the Zune marketplace today. Easier said then done. But i figured it out at last. Start with a link like this:

http://social.zune.net/redirect?type=phoneApp&id=APPID&source=Codepolice

Type is kind of obvious, ID is the one i had some problems with and source is just used for tracking and is optional.

How do i find the ID?

I spent 30 minutes on Google trying to figure this out and the only thing i found was this dude who had the same question. After a while i realized that Zune is of course using http to communicate with the world as everything else and since i have Fiddler installed i started it and browsed to an app in the Zune Marketplace and there i found it! Quick walkthough:

  1. If you do not have Fiddler just download it from their website.
  2. Start Fiddler and then browse to an application in the Marketplace with your Zune Software. You should see stuff happening in Fiddler.
  3. In the URL column look for a a URL looking something like this: http://catalog.zune.net/v3.2/en-GB/apps/981750c8-24cc-df11-9eae-00237de2db9e/?version=latest&clientType=WinMobile%207.0&store=Zest
  4. The long string (it’s a GUID) you see in green above is the ID you looking for.
  5. Just copy the ID into the URL and you have a fine link.

Final result: http://social.zune.net/redirect?type=phoneApp&id=981750c8-24cc-df11-9eae-00237de2db9e&source=Codepolice

Let’s hope Microsoft make this a bit easier soon.

Having problem adding a simple image to a Windows Phone 7 app?

I’m not the type of person who first watch 10 videos and read lots of documentation before i jump into some new environment. Therefore it’s kind of easy to get stuck on trivial and stupid problems like this one.

I just wanted to add an image and show it in the “ApplicationBar” but it simply would not work. At last i figured out that i had to change the image properties to.

Build Action -> Content
Copy to Output Directory -> Copy Always

IsolatedStorage on Windows Phone 7 error

I’m playing around with the new Windows Phone 7 SDK and today i run into an issue with the “IsolatedStorage” thing that is used to store some data like settings and stuff.

Anyways my designer in Visual Studio complained that it could not render my User Control that used an instance of the Isolatedstorage object.

Unable to determine application identity of the caller.

I found some forum thread and it turned out i just had to add this and it seems to work fine again.

if (!System.ComponentModel.DesignerProperties.IsInDesignTool) {
.. your isolatedstoragecode
}

I should add that i never had any issues while running the app in the emulator.

Refresh a Updatepanel from Javascript causing a full refresh

One big advantage of using ASP.NET Webforms is features such asĀ  the updatepanel. The updatepanel is awesome for admin UIs and things like that where you doesn’t care about performance or pretty markup.

Today i wanted to refresh a updatepanel via JavaScript and after a quick session on Google i found this article by Encosia (Encosia is the no1 resource for asp.net developers who wants to use jQuery and JavaScript in thier webforms apps btw). This article explained how to easily refresh a updatepanel via JavaScript by just calling.

__doPostBack('updYourUpdatePanel', '');

From your .js file. But when i tried this it simply didn’t work. The page did a full refresh and i was confused. Then i realized that my Updatepanel wasn’t named ‘updYourUpdatePanel’ anymore since Webforms renamed it with a generated ID. Since i use Webforms 4.0 i could just add the new ClientIDMode attribute.


And it worked. If you have no control of the ID you have to view source or use <%= updYourUpdatePanel.UniqueID %>.

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.

Request Filters doesn’t appear in IIS 7 Manager

For some reasons some versions of IIS doesn’t include an option for “Request Filters” in IIS (In my case a Windows Server 2008 Datacenter hosted in Amazon EC2). If you have this problem just download the IIS Administration Pack.

Stress test a web application in IIS

I recently noticed some performance issues with my ASP.NET Webforms application when it got some heavy load and i wanted to test it on a dev server with some heavy load. After loads of shitty Java and Python apps that required X number of strange frameworks and stuff i finally found the dream tool.

The WCAT Fiddler Extension was exactly what i was looking for.

  • It uses WCAT that is designed to test IIS.
  • It use fiddler to record a test script.
  • You don’t have to install Java, Python or any other framework.
  • Everything is GUI based.

I really recommend you to check out this tool. You can read more about how it works on the Fiddler and the WCAT extension page.