Tuesday, December 18, 2012

Enhanced JQuery resize event

Have you ever noticed how difficult it is to debug the resize event in JQuery because they are triggered while the user resizes the browser window? Paul Irish came up with an improved resize event which is triggered when the resize ends. Check it out here.

Sunday, December 9, 2012

SharePoint's best coding practices

It's easy to get caught on bad coding practices when using the SharePoint API. First, you need to download the SharePoint Dispose Check tool and run it against your code; and then read the following links, which have useful information:


Thursday, December 6, 2012

Outlook removes id tags from html elements

While doing some tests on how Outlook handles JavaScript code, I noticed it was removing the JavaScript code and the id tag of any div. It makes sense that for security purposes, Outlook does all this. If you want to know more about how email rendering works, check out this link.

Tuesday, November 27, 2012

Downloading files using WCF REST and viewing them in a browser

Creating a service that allows users to download a file is really not that different from creating a regular service. You just have to make sure the method returns a Stream object. This article helped me a little. 

However, you have to do one more thing, because the code in the article downloads the file instead of opening it in the browser itself. The code in the article sets the ContentType of the response to be "application/octet-stream". IE handles this correctly and if the file is an image, it's displayed in the browser. But other browsers like FF and Chrome need the correct ContentType (like "image/png") to open the file in the browser; otherwise they will prompt you to download the file (or even download it automatically). Check out the section "Unable to set an automatic action" of this Mozilla KB article for a more thorough explanation.

Therefore, you'll need to check the file extension and set the ContentType to it's correct value. Pretty simple huh?

Friday, October 19, 2012

Caching in WCF

I read in quite a few blogs that caching with HttpRuntime.Cache was possible in WCF (although not recommended by Microsoft). I decided to give it a try and it seemed to be working. After a while I noticed that the cache was not caching anything (oh suprise!). Instead of writing something from scratch I found this article on CodeProject http://www.codeproject.com/Articles/46945/WCF-Cache. It definitely saved me some time!

Wednesday, October 17, 2012

IE 8 mouseover vs mouseenter

In a nutshell, mouseover doesn't work correctly in IE8. I noticed it when a div showed flickering behavior and I could only blame it on the binded event. I couldn't find a lot of information on this, except some blogs that recommended using mouseenter. It's a quick fix and works great.

Monday, August 13, 2012

TFS Agile Template error "Report execution has expored or cannot be found"

I always wonder why some errors simply disappear by closing and opening an application. This error happened when I tried to open the Sprint Burndown report from Visual Studio 2010. After investigating a couple of hours, I read that just re-opening Visual Studio fixed the problem. And it did!

Saturday, August 11, 2012

CC.NET and SharePoint nightmares

A while ago I thought I was done setting my SharePoint unit tests and ready to execute them with xUnit/CC.NET. However, things didn't work. I didn't consider that xUnit runs as 32 bit and SharePoint runs as 64 bit. How I concluded this was causing the problems will be part of another post. The solution was to compile xUnit as 64 bit (set target = x64) and voila!

One thing that I didn't solve was that even though this solution worked in computer A, it didn't work in computer B. I also got to say that there was little information on the web about setting up automated unit tests in SharePoint. Am I one of the few people that dares unit test SharePoint modules?

Monday, July 30, 2012

Combining TFS, Visual Studio Scrum 1.0 and MS Project to manage a software project

There are a lot of benefits in tackling tasks based on priority instead of using task dependencies. After all, priorities change during the duration of a software project and it's difficult to keep tasks ordered sequentially. Getting your employer to buy in to using an Agile methodology to work on tasks based on priority will probably come with trade-offs. In my case the trade-off was that we had to use MS Project as well.

Here are a few things we learned while setting up a process:

1) Use leveling by priority in MS Project to avoid using task dependencies.

2) We had issues mapping priority fields between TFS and MS Project. In the end, we used to fields and had to keep them sync'ed (you can use a Macro for this).

3) The Scrum template in TFS doesn't allow you to log work. You'll need a custom column for this. This column needs to be mapped back to Project.

4) If you want to view a sprint burndown chart, remember to set the start/end date for the sprint.

We still have some unresolved issues:

1) We are not able to view the Release burndown chart.

2) If you are using baselines, you need to update the baseline before capturing hours in a task that doesn't exist in Project. That's because once you complete a tasks, the initial estimate is gone.

Anyways, I'm happy that the project is managed as "Agile" and take advantage of all the goodness of Scrum.

Continuous integration with SharePoint (and automated unit tests)

I've been working a lot with SharePoint lately and as with any project, we add it to our Cruise Control.NET server. The first challenge was that we had to install SharePoint on the CC.NET server. It was not really a challenge, but more of a time-consuming task.

The second challenge was setting up automated unit tests. In our case we use WCF services that receive an SPToken (actually, the string representation of the SPToken). This token expires every now and then, and we had to come up with a way to get a token in order to connect to a WCF service. The solution was creating a method in a service that creates a token and sends it back. It's really not the best practice, and it's not something you want to deploy to production, but it works fine for a continuous integration environment. These are the steps we followed:

1) Create a new service that is used only in the CC.NET sandbox
2) Create a method in that service that returns a token. The method should run with elevated privileges and return a token of a hardcoded user account (preferably an administrator account)
3) Reference this service from the project that contains the unit tests (we use XUnit)
4) Instantiate a service client from the test case (something like this)

  XUnitServiceClient client = new XUnitServiceClient("BasicHttpBinding_IXUnitService");
  client.Endpoint.Address = new System.ServiceModel.EndpointAddress("http://mypc/_vti_bin/XUnitService.svc/soap");
  string result = client.GetToken();

5) Then just call the method you're trying to test and pass the token.

Monday, July 23, 2012

SharePoint and WCF

I recently upgraded an ASMX project to WCF. It took me a couple of days (investigating, implementing and testing) to figure out, and although I'm sure my solution can still be polished, here are the steps so far to make it work:

1) Copy your .svc file to ISAPI

2) Make sure the markup of the .svc files is as follows

<%@ ServiceHost Language="C#" Debug="true" Service="MyApp.Service.TestService,  MyApp.Service , Version=, Culture=neutral, PublicKeyToken=3333333333" %>

3) We are accessing the WCF services using jQuery, so we had to enable the webHttpBinding. Security needs to be enabled like this:

<security mode="TransportCredentialOnly">
  <transport clientCredentialType="Ntlm" /> 

4) Create an endpoint behavior that includes

<webHttp />

5) Allow Anonymous Authentication on your IIS site.

6) Make sure you use the DataContract and DataMember directives where appropriate. You might get hard-to-debug errors when a type cannot be serialized correctly.

Along the way I learned a lot about Ntlm. At first I was getting a lot of "Unauthorized Access" responses, and I thought maybe using Ntlm was the problem. The real problem was that my WCF configuration was incorrect. Also, Ntlm is a protocol that uses a handshake, so you'll notice the same request three times at the beginning of the communication. Any subsequent request should only appear once.

Sunday, April 22, 2012

Scrum vs Kanban

I personally consider that Scrum provides the best practices for software engineering. However, it's still useful to know what other things people are trying in the software world. One of these techniques in Kanban. You can learn a little about it here:

Tuesday, April 17, 2012

Sharepoint 101: Always read the error messages

If you're new to Sharepoint just like me, you'll notice that every time there is something to learn. Sharepoint is full of... little issues that keep your "googling" skills sharp. This time I was trying to solve a timeout error when debugging an application page. The error was "The web server process that was being debugged has been terminated by Internet Information Services (IIS). This can be avoided by configuring Application Pool ping settings in IIS".

Thankfully the solution is also indicated right there in the message! How often does this happen? Never!

Sunday, April 1, 2012

Could not load type System.ServiceModel.Activation.HttpModule: aspnet_regiis to the rescue

I recently installed Sharepoint on my machine and I couldn't run some Windows Azure solutions. The error was "Could not load type System.ServiceModel.Activation.HttpModule" and it's actually really simple to fix. Just run aspnet_regiis -iru and you're good to go!

Monday, March 19, 2012

All user input is evil: Microsoft Web Protection Library

This application is something that should be under the belt of all web developers. I'm surprised that this library is not already bundled into ASP.NET MVC, which shows how little developers worry about securing an application. The good news is that there's a NuGet package already available.

If you're not sure what the AntiXSS library is, you should go and download it right now. It provides functions to sanitize user input, including but not limited to HTML and Javascript. The bad news is that you probably won't find a lot of documentation about it, but that's just because the library is really easy to use. Check it out here.

Sunday, March 18, 2012

SQL Azure: Invalid object name 'sys.configurations'

This is a rather dumb error. I am able to connect to SQL Azure from SQL Server Management Studio in my work computer but not from my home computer. But if I connect to it from a query window in my home computer it works!

I'm guessing it has to do with the SSMS version or with Object Explorer. It's better not to waste time with these errors because you'll probably end up uninstalling the software (and spend a bunch of time on that) to make it work.

This thread helped me http://social.msdn.microsoft.com/Forums/en-US/windowsazuredata/thread/9e5b6854-9e5a-4e7d-b771-313aa5683b72/.

Saturday, March 17, 2012

Failed to start Storage Emulator: the SQL Server instance ‘localhost\SQLExpress’ could not be found

I wonder why when you follow a tutorial there are always errors in the process which are not mentioned in the tutorial. It happened to me when following a Windows Azure "Hello, World" tutorial. This error is simple to solve though, just do this:

1) Open a command window and go to C:\Program Files\Windows Azure Emulator\emulator\devstore
2) Execute dsinit /server:localhost

In my case I don't use SQL Express, so I had to run the command above to point the Emulator to SQL Server.

Tuesday, March 6, 2012

Scaling guidlines from StackOverflow

If you build software using Microsoft technologies you might want to read this article. It outlines a set of lessons learned from StackOverflow on how to scale software and hardware.

One thing that is not clear to me is how to put a database in memory. In fact, it doesn't sound possible for SQL Server... I wonder what Jeff and Joel meant when they wrote that.

Wednesday, February 29, 2012

Fluent NHibernate tip of the day: Don't use table names that represent other database objects

But if you have to, you can escape the table name using the back-tick (when you create the mapping). I found the answer on stackoverflow. In general I think you should rename your table instead of using the back-tick. However, sometimes you have to work with legacy databases and there's no other choice.

Sunday, February 26, 2012

Debugging ASP.NET MVC when the default model binder doesn't work

A few days ago I came across a strange problem with the default model binder in ASP.NET MVC. It turned out that the name of the parameter in an Action was "request", and this was confusing the default model binder.

It sounds simple to fix (just change the variable name), but the process to figure it out is not that easy. What will help you solve the problem is diving into the ASP.NET MVC framework source code. Follow this post to learn how to debug it. I also had to download the source code, add it to my solution and reference those projects.

Thursday, February 23, 2012

To mock or not to mock

Obviously the answer is yes. The real question is which mock framework to use. I personally recommend using moq. It is easy to use, provides strong-typed programming and has good examples/documentation. If you look at Google Trends, it also seems to be really popular.

Sunday, January 8, 2012

Configuring SMTP in Windows Server 2008

Before you read this post, if you find yourself needing to configure SMTP, there is already something wrong. There are a lot of cloud-based email providers and you should take advantage of them. Using SMTP should be only a temporary solution to your email needs. Anyway, it's really simple and it doesn't take more than 10 minutes. Just follow these instructions http://www.itsolutionskb.com/2008/11/installing-and-configuring-windows-server-2008-smtp-server/

Saturday, January 7, 2012

Duplicate POST in JQuery mobile

Last week I was looking at the requests made by a JQuery application, and I noticed that a POST was being executed twice. After doing some debugging, I thought this was a JQuery mobile issue since my code was doing only one POST. There's nothing more undesirable because we didn't want to change the JQuery mobile code, and even though JQuery mobile does frequent releases, we needed the fix right away.

Long story short, it turned out the whole problem was caused by an IMG tag with an empty src attribute. In other words, we had <img src="" alt....>. It's hard to explain why this error can cause a double POST.