So you have some embedded resources in your ASP.Net control library and you want to use them. But instead, nothing works. Scripts are not loaded and images are not displayed.

Look in the IIS log files and check for an error like this: "Exception information: Exception type: ArgumentOutOfRangeException Exception message: Specified argument was out of the range of valid values. Parameter name: utcDate".

If you see it, then your assembly where the resources are embedded has the build date into the future! This also applies to the code you just built and the date is correct and the date of the server where you want to copy it to is in the past. It also applies when the time is in the past, as when you are copying it on a server in a different timezone!

Update: There are other reasons why axd files are not loaded. One of them is that some other IHttpHandler (defined in web.config) is messing up with your settings.

Another is that the .axd extension is not defined in the virtual directory mappings (You get the dreaded Webform_PostBackOptions is undefined javascript error). Go to IIS manager to the properties of the virtual directory, click on the Configuration button, select the Mappings tab. You have to have the axd extension defined to open with aspnet_isapi.dll. Warning: there is a checkbox in the properties for the extension mapping called Check that file exists. Make sure it is unchecked, as the WebResource.axd and ScriptResource.axd are not actual files, so the mapping will fail if the check is set! On Windows 2003 there is also a listbox at the bottom of the Mappings tab. Edit it and look for yet another Check that file exists checkbox and, of course, uncheck it.

Ever wanted to bind something to the layout rendering phase of an element in Javascript? This helps, by checking at a fixed interval if the size or position of an element have changed and, if so, firing the 'refresh' custom event. All one has to do is then bind to it.

Github page: https://github.com/Siderite/jGenerateRefresh
JQuery plugins page: http://plugins.jquery.com/node/9030

Example:
$(function() { 
$('#target').bind('refresh',{},someRefreshFunction);
$('#target').generateRefreshEvent(100); // every 100 milliseconds
});

Wow! This book is a must read. Not only because it is short, well written and freely available online, but because it does what very few books manage to do lately: actually showing you how to practically apply the knowledge and the consequences of that. Basically, it's like a technical book with a story.

As the title suggests, Scrum and XP from the Trenches is a book about software management, moving step by step through all the requirements of the management process in a Scrum environment and showing in detail what Henrik's actual implementation was, the problems he encountered, the options he had and why he chose one, the other, or a combination thereof. Even if he talks mostly about Scrum, he does mix in the elements of XP that he thought worthy of borrowing, making this not a book on any management theory, but of a real life process.

As previously mentioned, the book is freely available on InfoQ, although you are highly encouraged to buy the book to support Henrik Kniberg and other endeavours like his. A must have for any manager or team lead, and a very good read for any developer, having the chance to glimpse at a real software work environment.

For me I am glad to have read it and to see more of my current job in the book than the previous one, which means I have actually moved upwards and not only horizontally.

It seems that there is a renewal of the non-relational database movement. Since I know nothing about the specifics I will list only a few links that I found relevant:
No to SQL? Anti-database movement gains steam
NOSQL debrief
Neo4j - The Benefits of Graph Databases

Of course, this "revolution" is only gaining momentum because of the huge quantity of data being moved around on the web. There can be no centralised system that could handle Google, Facebook, Amazon data sizes and therefore they all move to distributed systems. Tables are now a hinderance, rather than a programming advantage and object oriented schemas step forward.

Will that change our daily work as developers? Well, only if we decide to use some "live" database system to store our data. As proven by the previous "revolution", relational works pretty well for small systems or networks.

As you have probably noticed, a lot of my recent posts have been about WPF. Having to do a demo in this new (for me) technology I had a lot of thing to learn and a lot of brick walls to hit. It was exciting, but also difficult, with new concepts that felt awkward, mind twisting. I even burst one day shouting "I hate WPF".

However, I am now working, temporarily, with ASP.Net (no Silverlight) again. And guess what? At every step where I need to design something, I think in the WPF way and find the web way lacking. Riddle me this, riddle me that. :)

Of course, some might say that this is another proof of my whiny personality. I hate when people say that about me!

I only met this while working on a Menu control, but who knows, maybe it occurs in other situations as well. Bottom line I wanted to create a CSS friendly Menu without using an adapter. So I inherited from Menu, did some stuff, then Kaboom! "A PopEndTag was called without A corresponding PushEndTag" error.

I could not determine where it cam from. The only helpful article on the net seemed to be one from a guy that also wanted to inherit from Menu. Strangely enough his problem only appeared in Design mode, while mine was a runtime thing. And weirder still, the problem was "solved" by the same ridiculous fix, that of calling an extra
base.RenderBeginTag(writer);
in my RenderBeginTag method override. However, his explanation that is all came from IControlDesignerAccessor did not solve anything for me. Menu only overrides the SetDesignModeState and GetDesignModeState methods from IControlDesignerAccessor and when I also overrode them and removed any code inside, I still got the error.

So, after an hour of searching, I solved it by overriding the Render method with
protected override void Render(HtmlTextWriter writer)
{
if (this.Page != null)
{
this.Page.VerifyRenderingInServerForm(this);
}
if (this.Items.Count > 0)
{
this.RenderBeginTag(writer);
this.RenderContents(writer);
this.RenderEndTag(writer);
}
}
which is the exact implementation from the original Menu source code, but without the 'false' parameter in RenderContents and RenderEndTag.

Hope it helps someone.

In C# 2.0 and above there is this new feature of the '??' double question-mark operator that operates like the SQL isnull function. If x is null then x??y will return: x if it is not null and y if x is null.

A bit annoying, though, that Javascript does not have an operator of the sort. Or so I thought. Enter ||, the logical OR operator. In fact, in javascript x||y will return y if x is null. Also if x is undefined, string empty, 0 or false. But it works in a reasonably similar manner. Beats x===null?y:x anyway.

This is called Short Circuit Evaluation, if you want to be pedantic about it. Be aware that you can chain it, too, similar to a Coalesce function:
0 || null || '' || false || undefined || 'something' // result 'something'

and has 2 comments
I have this Genius Comfy KB-16e model K640 keyboard. I went to the Genius web site and downloaded the drivers and Media Key application which is supposed to control what the "media" keys are doing. But the application is crap. It only shows some of the buttons I have and some I don't. Most annoying, I don't have listed the buttons for previous/next track.

The solution is to modify the registry. If you go to the Media Key installation directory (typically in Program Files) you will see a registry file called Magickey.reg. It holds all the information loaded in the reg by the installer of the Media Key application. Open it with notepad (not by double clicking!) and search for "Function Table". You will see a bunch of equalities like:
"0000000B"="Show MediaPlayer"
You will need to write somewhere the numbers associated with the keys that don't appear in the Media Key application. In my case
"00002000"="Previous Track"
"00002005"="Next Track"
Ok, now run regedt32.exe from the command line (or Run command in the Start Menu) and navigate to HKEY_LOCAL_MACHINE\Software\WayTech\Versato\System. You will see there stuff like button1, button2... and their values 0000XXXX or some string holding a path. All you have to do is double click on the buttons that hold the numbers you wrote down as the value (in my case 2000 and 2005) and write instead of the value a path to a batch file or an exe file. I use bat files so I can change them later.

So, in my case I double clicked on button17 and button18 and filled the value with C:\Batches\prevTrack.bat and C:\Batches\nextTrack.bat. And now it works. I am sure you can change something in the registry to actually make the buttons visible in the Media Key application, but I don't care about that. If you do it, please let me know.

If you have the same problem as I do and all you want to do is set up your Music, PlayPause and Prev/Next buttons, take the text below and write it into a file with the .reg extension, change the paths to your own batch files, then double click on it:
Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\WayTech\Versato\System]
"button7"="C:\\Batches\\playpause.bat"
"button8"="C:\\Batches\\playlist.bat"
"button17"="C:\\Batches\\prevTrack.bat"
"button18"="C:\\Batches\\nextTrack.bat"

and has 0 comments
I know, Might and Magic IX is an old game, but I haven't played it because, after being a HUGE fan of Might and Magic 1 through 5 I got really dissapointed with versions 6,7 and 8, which used 3D technology, but presented a lot less as the game story and playability was concerned. Then I played the tenth version, Dark Messiah of Might and Magic, which was a completely different game, more of an Arx Fatalis 2, rather than M&M 10. Not that it wasn't very very cool, just wasn't what I had expected from an M&M game.

Enter Might and Magic IX. From the start it looked less modern than versions 6-8, which prompted my friend to think that he played more recent versions of the game. It became soon apparent that it was an attempt to go back to the roots. The game was complex, the map large, the monsters inventive and the storyline pretty interesting. Also, they returned to the old solution of dungeons, where entering a place was moving you to a new map, rather than a small part of the larger one.

I loved every moment of it until close to the end. The cities at the end of the game had less stuff in them, less monsters around and of a more poor quality. I kind of expected that, since it must have been a long software project plagued by a release deadline in the end. However, when I had to spend hours trying to get around dungeons filled with powerful yet silly monsters just to get to the end, I got very bored. I actually did not finish the game, only about 95% of it.

The game had an unhealthy amount of undead creatures, which made Turn Undead a very useful spell. Unfortunately, I think it was a bit buggy. After a strong Turn Undead monsters continued to run, even if the spell wore off. Another really nice spell was Enrage, which allowed one to make monsters fight each other. Wizard Eye was a bit annoying, since it lasted a too short a time.

I recommend you check the character development tree (Druid, Healer, Lich, Gladiator, Assassin, etc) and decide from the very start which character in your party will be what. Pay extra attention to the promotions. You may be able to promote more characters in the same time, but then you are commited to that path with all of the characters. Try to build each character in a different class. Some allow for very powerful spells that one cannot learn or use otherwise.


I don't want to spoil anything, so I will let you play it and enjoy. I applaud the return to the old values of Might and Magic, even if those older games had a lot more brain and humour in them and this had a lot of braun. The ending was inconsistent with the M&M storyline so far which was disappointing.

Bottom line: greatest of the true Might and Magic 3D games, I wish I was young again and full of free time so I can play it without looking at the clock all the time. If you somehow missed it, do play it.

and has 1 comment

Foundations of Programming is a free ebook written by Karl Seguin, a member of the CodeBettter community. As you might have guessed by now from the fact the book is free, he is Canadian. :)

There is even a Foundation of Programming site, where there are a lot of free resources on programming as well as other free ebooks.

About the book, it is a good read. A bit inconsistent, it seemed, since it starts with chapters on Domain Driven Design, Persistence, Dependency Injection, Unit Testing, then moves to Object Relational Mappers and then has three "Back to Basics" chapters about Memory, Exceptions and Proxies. There is a logic to this, but the jump from expert to junior programming and then back again was a little annoying.

Interestingly enough, Karl Seguin is a former Microsoft MVP that advocates ALT.Net.

Bottom line, it is a good and easy read for all levels of programming. People might be attracted to the way Karl is expressing his opinion without actually being biased towards any of the usual debate parties. Beginners might learn about the foundations of the stuff they take for granted, like heap/stack, while more advanced developers can start thinking about structured ways of doing work, like DDD and automated unit testing. Neither chapter is a complete new revelation, but taken together, they do present a clear picture of programming from Karl Seguin's perspective and can surprise you on matters you thought you had complete control over.

and has 0 comments
Something really cool from the TED blog, this image is an optical illusion of grand scale. See the Cyan/Green spirals? Well, they are the exact same color. Trust me, I opened Paint.NET and checked their RGB values. Event at immense zoom, the colors still appeared as different.

I was trying to build a control that has a border around it only in design mode. You do have the static class DesignerProperties and its method GetIsInDesignMode(DependencyObject element) to detect that in code, and you do have a property DesignMode on Components, but one that is not a Dependency property. How can you detect DesignMode in XAML?

Well, looking at the source for DesignerProperties I noticed that it does two things:
  1. Register an attached property called IsInDesignMode to itself
  2. Get/Set that dependency property in the GetIsInDesignMode/SetIsInDesignMode methods


More on how to create attached properties here: How to Create an Attached Property and here: Showing Attached Properties in the Cider/Visual Studio WPF Designer.

So, all I had to do is use a trigger on the IsInDesignMode attached property. For that, these steps must be followed:
  • Add the ComponentModel namespace to your XAML: xmlns:ComponentModel="clr-namespace:System.ComponentModel;assembly=PresentationFramework"
  • Use ComponentModel:DesignerProperties.IsInDesignMode in your Triggers as the Property
  • Use (ComponentModel:DesignerProperties.IsInDesignMode) in your DataTriggers as the Path of Bindings


Please take notice of the brackets around the property when used in Binding Path mode. It is the only way to use attached properties there. It also gives you more advanced intellisense and warnings and a faster type resolution at runtime.

Another thing to take into consideration is that (at least in Silverlight) this mechanism is buggy, at least that's what I found in this blog post.

It was not a problem I encountered (maybe) but a blog post from Chris Brandsma from ElegantCode. Apparently, because of attempts by the SQL Server (not only Microsoft's, btw) to "optimize" a query based on input parameters, query execution time may vary immensely without any obvious reason. Imagine debugging that baby!

Anyway, here is the blog post, one important enough for Chris to repost it these last few days.

I don't want to write a long blog entry, just to attract attention to this blog entry from Josh on WPF which is very concise, to the point and also directing to more complex articles that add more detail.

Even so, I want to cite a part which I think is essential to understanding the concept of Dependency Properties: Remember, a DP never really “has” a value…its value depends on various external factors. That’s why they are called dependency properties.

The problem is moot. The StackPanel doesn't work like that. You need to use a DockPanel to make inner children of the Panel stretch vertically and make the Panel fill all available space. The elements inside should have DockPanel.Dock="Top" to fill only the space they require , then no Dock for the element(s) you want to stretch, then DockPanel.Dock="Bottom" for the rest of the elements. That's how you get that "Outlook feel", too.