Debugging ASP.NET - Irish Style

by admin 2. April 2008 19:09

Irish Aplomb I work in a fairly relaxed development environment. I guess you could call it RAD. Most Web development work is Rapid Application Development by nature anyway. That said, I'm not totally ignorant of the newer methodologies such as Test Driven Development (TDD). However, all the tools and methodologies in existence will not make the slightest bit of difference if your mindset and approach are out of whack for the job at hand.

10 Rules for Debugging - Irish Style

1) Keep it simple, stupid (KISS principle). Many people get in a bind because when given a choice between a simple solution and one that seems more elegant, they of course go for the latter. Elegant code is achieved through experience and refactoring. Get it working first!

2) Divide and conquer. Why look for a needle in two haystacks? Narrow it down.

3) Don't let your emotions get the better of your thinking - always a recipe for disaster.

4) Never panic. Only wimps panic. In the face of insurmountable odds, get drunk, read Hemingway and proclaim your genius loudly to all.

5) Your brain works productively for 40 minutes at a time. This is a universal rule and you are not different. At the 40 minute bell, go away from your desk for 10 minutes as you're only going downhill from that point on. For some strange reason, most people cannot accept this fact. Look around you at work to see who the idiots are. "Gee, I'm sure to get promoted if I never leave my desk"... and pigs will fly.

6) Do not presume that the first change you make to your code that makes it run, is the actual solution. You may have been looking at a symptom...

7) There's a reason why error messages are neither friendly nor helpful. If the guys who penned them were shining beacons of descriptive prose, they would be working for the New Yorker instead of doing that job in the first place. Guess how they get their kicks? Never rely on your bog-standard error message clueing you in to anything other than the onset of an early ulcer.

8) Learn how to think, if you haven't already. I was in my 30's before I started asking the right questions about anything, let alone software development. Ask someone what they really want in life and 90% of the lemmings will reply that "they want to be happy". See where I'm going with this?

9) Creativity is your number one asset. Be creative and learn how to develop new synaptic pathways in that grey matter. The brain needs to be exercised in different ways, regularly. Get out of bed on a different side tomorrow and put your clothes on in a different order. If you really want a laugh, do everything in the washroom with the opposite hand to the one you normally use.

10) As for ASP.NET, if you don't know the life cycle inside-out, you shouldn't be wasting your time skipping a chapter to debugging in the first place ;-)

kick it on DotNetKicks.com  




View other SharePoint posts...

I've recently been assigned the task of setting up and documenting the SharePoint development environment. If you were dismayed by the vagaries of the installation process, you've seen nothing yet. Although SharePoint is built upon ASP.NET, this is an Office product. The Office team have always been the cash cow of Microsoft. Apparently, their priority was to make this product user friendly. And if your company is so large as to have thousands of sites, I can see no better choice than SharePoint. It really scales better than anything out there.

For smaller companies with in-house development teams, there is still a huge hole in this market and it will be filled by someone. Very few users will get to see how "friendly" it is if the IT people determine that it's too much of a pain to develop on. Not only that, but very few IT teams have the expertise required to do this properly anyway. Training in this area has been pretty non-existent up to recently. Some months back, I attended a MOSS boot camp which was one of the very first in the United States. It focused only on the installation and administration of SharePoint. If you are a developer like myself, then for the most part, you are pretty much on your own.

 

The Bottom Line:

  * You have to develop locally for debugging and testing
  * You need SharePoint/WSS on your local machine
  * SharePoint/WSS needs Windows Server 2003 SP1 to run
  * You need to use virtual machine(s) locally to host Windows Server 2003
  * You may need to bump up RAM (4 Gb) and possibly add a fast external drive
  * TFS support will not be available until the Orcas release

 

Everything You Need to Know:

  * Use Virtual PC Differencing Disks to your Advantage
  * MOSS 2007 Development - Virtual Server Set Up
  * Team-Based Development in MOSS
  * Development Tools and Techniques for Working with Code in WSS 3.0
  * How to Create a MOSS 2007 VPC Image - the Whole 9 Yards

 

Summary

I will be implementing the development environment myself and will report back on the outcome. I am going to set up initially with Virtual PC VHDs and difference files on a test machine and work from there. Eventually, I will deploy to a staging server which will be an exact duplicate of the live server. As for source control, I will have to wait until the Orcas release and start all over again. There is a TFS Beta 1 available for those who are interested. Note that you can still save your Web Parts in the current version of TFS. There are hacks to getting the current version of TFS to work with MOSS solutions but it's supposed to be so involved as to not warrant the time spent on it. Also, some people are saying that VMWare is faster that Virtual PC (Virtual Server if you have the license) but I am trying to get some benchmarks to support this. I can't wait to actually sit down and build something!



Events Calendar

by admin 16. June 2007 20:43

One of the most common features of community websites these days is the events calendar. It's also the source of one of my pet hates, the stretching of calendar cells as event title links are added for a particular day. Nothing looks worse than an event calendar with an average of one or two events per day... with that one fifteen-event day stretching the entire Calendar control down the page. This is not just an issue of esthetics. If you only display a limited number of events for a given day, pretty soon the other event organizers will be calling to ask why their events are not being shown! In such situations, a compromise is frequently called for.

Recently, I worked on such an events calendar for my local town's Business Improvement District. The client  wanted an easy way for users to see when there were events without having to dig too much to find them.I did not want to use the Calendar control to display event links. I chose instead to implement a master Calendar highlighting days that had events, and an associated events listing implemented as a pageable GridView.

During development, I encountered the following exception:

ObjectDataSource 'sourceEvents' could not find a non-generic method 'GetEventsByMonth' that has parameters: startDate, endDate, startDate1, endDate1...

This occurred in the paging event handler for the GridView. I was adding the SQL parameters programmatically and implemented a quick fix as shown below:

// Manually remove any select parameters from ParameterCollection sourceEvents.SelectParameters.Remove(sourceEvents.SelectParameters["startDate"]); sourceEvents.SelectParameters.Remove(sourceEvents.SelectParameters["endDate"]);

Then I added the same parameters as before and everything worked fine.

If I ever have to do something similar again and there are a lot of events involved, I might have to look to AJAX for a more creative alternative. Has anyone found another way of doing this? If you would like the complete code, please email me.