Friday, July 10, 2009

Using TFS SDK on 64-bit machine

Hi, guys!

Using the TFS SDK is pretty easy. You read some articles and documentation from the msdn: Team Foundation Server SDK. Then just add the appropriate assemblies (for example Microsoft.TeamFoundation.Client and Microsoft.TreamFoundation.WorkItemTracking.Client) and enjoy writing TFS accessing applications.

What's the problem with 64-bit machine?
Creating and building the project is easy. Some problems occur when you try to run it, though. I encountered error like this one:

"Could not load file or assembly 'Microsoft.TeamFoundation.Client, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified."

The problem is that it appears that the TFS SDK is only x86 (32-bit).

The solution
What you have to do is just change the Platform target to x86 in the Project/Properties/Build tab in your Visual Studio, and everything will work again for you. It sounds very easy, but I wasted few hours to figure this out.

Happy Coding!

Monday, June 1, 2009

Creating a useful BasePage

When people start a new project,
creating a Base Page for all other pages is a must! I found a very interesting, yet simple and concrete article about the Base Page and some of the useful methods, which can be included there. This Base Page is great for avoiding code duplication and has a good level of error handling.

You can read the article here: ASP.NET Tip/Trick: Use a Base Page Class for All Application Pages

Page Refresh Handling
What I find useful adding to this Base Page, is a functionality for recognizing whether there is a Page Refresh occured (when the user presses F5 or Refresh button), because as you know, the Page Refresh actually does again what the last page post back was - all the events and stuff.
For example, when you click the button next of some results set you expect to move to the next page. What happens if you hit refresh after the rebinding? It actually executes again all the events from the previous post back, so it will move you to the next page, which you didn't want to. What is worse, it can break your application, because there can be no more results and no 'next' page. One way to handle this situation is to write some code in the Base Page so that you can track whether a Page Refresh occured and the other most common way is to stop/invalidate the page after refresh.

In conclusion,
I must remind that creating a common Base User Control is also useful and should be used as a best practice, too !

Tuesday, April 21, 2009

Visual Studio 2008 Keybinding Reference Poster

Hi, guys !

This can sound like a promoting post for some of you, but I recently found this official Visual Studio 2008 Keybinding Reference Poster, which can be downloaded freely from here.

I find it very educative,useful and quite inspiring for myself - hanging there on the wall just in front of me. No more wondering how the Format Document or Format Selection key combination was.

Microsoft have created such Reference Posters for other tools and technologies too, so I will be enjoying most of them soon.

More Reference Posters
.NET Framework 3.5 Common Namespaces and Types Poster
Microsoft® Silverlight™ 1.1 Alpha Developer Reference Poster

Tuesday, March 24, 2009

getElementById compared in IE6, IE7 and IE8

Hi guys!

These days I was enjoying the new Internet Explorer 8 and were observing the differences with the previous versions of the browser.

I encountered a problem connected with the getElementById method. It was working OK in IE6 and IE7, and now in IE8 it suddenly stopped working.

How does getElementById works in IE6/IE7
In IE6 and IE7, the method getElementById would get an element provided either the ID or the Name attribute of the element. What is more, it matches it case-insensitevily.

In Comparison
In IE8 it does exactly what it says and what it should do - it gets the element only by the ID attribute and it matches case-sensitively.

The reason why the old code wasn't working in IE8 was because someone has used the getElementById to get an element on the page provided it's Name. Which apparently won't work in IE8.

More on this
More on this, Here (Check the Remarks paragraph)

Friday, March 20, 2009

asp:FileUpload control in Modal Popup Extender

Hello guys !

Let's go straight to the issue this time.
I have a Modal Popup Extender and want to use the standard FileUpload control in it. What I mean by saying the "standard FileUpload" control is that I will use the asp:FileUpload control and not the AJAX-enabled one which is in the AJAX Control Toolkit.

What's the issue/problem?
The problem is that the AJAX makes partial updates and doesn't perform a full postback. The FileUpload control itself works with full postback - in the postback the File which you uploaded is attached in the Request.Files collection. So, when you are not performing a full postback, the file is not uploaded in the Request.Files collection and you cannot get the file to use it - for saving in the database for example.

The solution
The Script Manager has one very useful method - RegisterPostBackControl ( ). It basically registers a control, which should implicitly do a full postback. In my case, it was enough just to register the FileUpload holding control to perform a full postback and I had the File uploaded into the Request.Files and ready for use.

The issue and the solution were pretty straight-forward this time. But it can become trickier, if you don't know the RegisterPostBackControl method.

Wednesday, March 4, 2009

ASP.NET Validator in Modal Popup Extender

I had an interesting issue, which I want to share with you.

The Case
I had a RequiredFieldValidator in a Modal Popup Extender. After closing the popup, everything in my web page freezed. For example, clicking a LinkButton/Button wouldn't do a postback, everything just stopped working.

The Problem
After some kind of debugging, I figured out the problem. As you know, the modal popup extender works like this:
1.) When you invoke the .Show() method of the Modal Popup Extender, the AJAX.NET takes the PopupControl you want to Show as a popup and brings it to the front.
2.) When you invoke the .Hide() method or close the Modal Popup Extender from a button inside it, it again takes the PopupControl and hides it in the page.
So, the problem I encountered was, that when the user entered some invalid data and presses the cancel button(to close the ModalPopupExtender and to cancel the changes), the AJAX.NET hided the PopupControl in the page. The problem was, that the RequiredFieldValidator was yielding that there is invalid data, so it was blocking all the postbacks. The cute thing is, that you can't actually see the RequiredFieldValidator, because it's in the Modal Popup which you don't see, too.

The Solution
The simplest thing to do, was to clear all the Validators from the ModalPopupExtender, when I hide it. This is not a neat solution for me, but I don't know any better for now.

Probably, people encounter such a 'problem' on rare occasions, but I found it useful for myself, and will be aware of this.

Wednesday, February 18, 2009

XML comment contains invalid XML: Whitespace is not allowed at this location

Today, I encountered this error: "XML comment contains invalid XML: Whitespace is not allowed at this location".

The problem occured in a code similar to this one:

/// Calculates the area & the surface

public double CalculateAreaAndSurface()

* Please, note that this above is just a sample code to illustrate the error, not a meaningful function or well written.

So, when I started using this function, I called it like this ObjectInstance.CalculateAreaAndSurface(), and the Visual Studio(2005 or 2008) didn't show me the comment I have written, but the error instead: "XML comment contains invalid XML: Whitespace is not allowed at this location".

After a small research, I figured out that the problem in the comment was that there is the character "&" in it, which should be replaced with the escaped version "& amp;". Some other characters like < and > are in this list of forbidden characters and should be escaped too.

Thursday, January 29, 2009

WPF - Is it my preferred choice for graphics ?

Hi guys!

I want to share with you some experience with WPF
Recently, I started doing a very simple Graphics project and encountered some difficulties. I wanted to share with you the thing which frustrated me mostly.

What is the most simple thing we should do when using Graphics?
For me, this is to load a simple image and manipulate it. This was pretty easy with GDI+ and System.Drawing classes like Image and Bitmap. You had everything needed - you could load a Bitmap simple like this Image.FromImage(path_to_file) and you could as easily manipulate the Bitmap's pixels - Bitmap.SetPixel(x, y, color). I of course wanted to use the same 'tricks' in WPF, but couldn't do it. After some research, I figured out why:

"GDI+ was a bit different in the sense that the Bitmap object was always cached in memory, so having a SetPixel method made sense. However, this may not be the case in WPF. For applications that do not wish to load the entire image in memory, WPF provides a way to load the image such that it is read from disk on a per-demand basis. In this case, a SetPixel equivalent does not make much sense and would not work. Thus we have chosen to not include this functionality for V1 and will consider such an API for future version."

In Conclusion
Firstly, I couldn't believe this. I could have gone with using Windows Forms Project from the very beginning, but was excited to try the WPF.
I wonder if WPF is grown enough to be used in real projects... ? I will appreciate any professional opinions on the theme.