Friday, March 19, 2010

VS 2008 Debugger does not step through

Over the past week, I've had a horrible time with my VS 2008 debugger. Breakpoints hit. There is no problem in that. However, its when I try to step through the code that it fails. It just skips all over the place as though I've hit the F5 key and it lands up breaking at another point.

I tried everything from re-installing/repairing VS 2008; installing SP1 as well. Nothing seemed to fix the problem.

After some time chasing down wrong errors on my output window, I finally decided to call it quits and post on StackOverflow, hoping the community could help me figure out the solution.

Sure enough, one of the questions already posted brought me to the solution.

Apparently this is a known issue, the gist of which is the following:

  • Breakpoints in parallelized loops are eventually ignored after multiple hits
  • Stopping and starting threads causes breakpoints to be missed
  • Visual Studio may crash when you debug multiple processes at the same time
  • Stepping over a disabled breakpoint when you debug a native application turns into a "go"
  • Stepping when you debug a managed multithreaded application can randomly turn into a "go"
  • Running the "Step Over" command while you are debugging multiple processes causes a deadlock
The one in red above was my exact problem.

Thankfully, there is a fix for it which can be downloaded: Fix for Visual Studio 2008 debugger not working

Once using the above said fix, I came across another issue:

Loaderlock was detected

Attempting managed execution inside OS Loader lock. Do not attempt to run managed code inside a DllMain or image initialization function since doing so can cause the application to hang.

After a bit of investigation it looks like some other running applications might cause this problem. Of what I saw the most, many people seemed to be complaining about iTunes. The other software I noticed causing this was grooveshark (flash since it is what grooveshark is based on. GrooveShark itself does not cause the problem).

ModalPopupExtender does not display at the center

Recently I had to work with the ModalPopupExtender that comes with the AjaxControlToolkit. I’ve worked with it before, but this time it posed a couple of problems (that were caused not because of the toolkit, but rather other things).

Without specifying the “X” and “Y” attributes of the ModalPopUpExtender(MPE) it is supposed to, by default, render at the center of the screen. Sometimes this doesn’t happen. The solution to getting it to render at the center of the screen is adding the following doctype to your page:

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>

Even then, my page didn’t seem to display the popup right. Its only later that I discovered that I was using Response.flush on the page to display a “Loading…” screen. This causes the html used for the “Loading…” screen to be the first thing on the page.

Since the DOCTYPE is now forced down the page, the rest of the page does not render as per the specified DOCTYPE. This causes the MDE to render at some other position on the screen (other than the center).

To fix this, Response.Write and Flush your DOCTYPE tag first, so it becomes the first line on the page.

Monday, March 8, 2010

Access dynamically created javascript elements in code behind

For the longest time I wondered why Asp.net would not provide a mechanism to access elements I had created dynamically using javascript in my code behind. It turns out they do, its just that since we hardly ever use that feature any more (and are more used to accessing elements by their ID’s after dragging and dropping them) it has vanished.

What I was attempting to do was create an input box using javascript, fill it with details and post it back to the server.

Code to create the input box and place it in a div:


function addtb()
{
var getdiv = document.getElementById('holddiv');
getdiv.innerHTML = getdiv.innerHTML + "";
count++;
}



On the code behind though, rather than accessing it using the id/name directly (you cannot do something like [input-box-id].Text = ’some text’) you have to get its value from the Request variable and use the data.



string c = Request.Form["tbs"].ToString();



Also if you wanted it to get displayed on the page the next time around you would have to recreate the elements manually in c#




TextBox t = new TextBox();
t.ID = f;
t.Attributes.Add("name", "tbs");
t.Text = f;
Page.Form.Controls.Add(t);


Although this is cumbersom, it works. I’m not sure if there is an easier way to accomplish this.

Thursday, March 4, 2010

Order By clause not so useful

If you have ever come across this error in SQL

The ORDER BY clause is invalid in views, inline functions, derived 
tables, subqueries,
and common table expressions, unless TOP or FOR XML is also specified.

then all SQL is trying to tell you is that you cannot use your ORDER BY clause within a subquery.

So if you have something like this, it sure as hell won’t work:


SELECT x, y, z

UNION

SELECT * FROM(
SELECT DISTINCT x, y, z
FROM (

SELECT x, y, z
FROM a
WHERE

UNION
SELECT x, y, z
FROM b
WHERE
)

ORDER BY z
)

Work arounds? A little hunting around showed that you could “use” a ORDER BY in a subquery if you used the TOP X PERCENT in your SELECT statement which would go something like this:


SELECT x, y, z

UNION

SELECT * FROM(
SELECT TOP 100 PERCENT x, y, z
FROM (

SELECT x, y, z
FROM a
WHERE

UNION
SELECT x, y, z
FROM b
WHERE
)

ORDER BY z
)

Why I stressed on “use” there is because although you can use it, it doesn’t make life any easier. Basically it allows the usage of ORDER BY, but it never does ORDER BY anything. You get back an unordered result set.

The workaround I used was adding an extra column that had blank data for the row I wanted sorted on the top and the actual data I wanted sorted by for the rest of the rows; then sorted it based on this extra column. Crude, but it works.

I thought this would be an easy thing to do, but it doesn’t seem so.

Wednesday, March 3, 2010

Web 2.0 in a flash...

This is one really well done video, I loved it...



Here is the link to the original content - Mediatedcultures

Monday, March 1, 2010

GPS is in the algorithm


I recently had the opportunity to use two different GPS systems, one by Mio and the other by Magellan. Apart from the fact that the interfaces varied greatly I was wondering how the underlying technology worked. Reading lots of reviews and stumbling upon a site catered to GPS systems (
GPS Magazine ) I finally found that Mio, Magellan, Garmin, Google, Yahoo!, Microsoft and probably every other person who makes use of maps in their products uses data provided by either Navteq or TeleNav. After all the reviews (that have been extremely well done by the site) it boils down to the fact that it is the algorithm that makes the difference in providing the routes.

How intelligence is built into the system is a whole different issue, but just providing the shortest routes from the point of departure to the point of destination itself seems like a major task. I was just wondering how primitive the traveling salesman/shortest path algorithms might be in comparison to what these guys might have built to provide the routing.

However, none of the systems seem to have enough intelligence to know how to take shortcuts. Probably its there on the higher end systems, but then I haven't tested/tried any of them. Sometime in the future I see myself sitting in a car, punching in my destination and not even having to lift another finger. I will be there. (Considering Lexus already has the autopark feature done)