So here I am, banging my head against the table repeatedly (quite
literally, feel free to ask my colleagues) because of a bug so idiotic
I can't even begin to describe it.
I wasted 20 minutes tracking down a bug just to find what Rik Hemsley says best:
?productlistview.Items(0).Selected
True
?productlistview.SelectedItems.Count
0
Hmm?
Apparently, though no-one will tell you this, the selection could fail if you don't have the focus. Make sure you add a call to lstWhatever.Focus() before you mess with selections.
Eli Ofek has published a
5-part (well, 4-part really) series about migrating an actual project
from the classic triad of VS2003/.NET 1.1/VSS to VS2005/.NET 2.0/Team
Foundation Server. I used to be a developer on the "sister team" of the
project he's talking about, and I can tell you that it's a huge project
with an extremely talented and devoted team of developers, so if you're
going to be doing any migration work in the nearby future I highly
recommend you go ahead and do some serious reading on his blog. The
bottom line is that Beta 2 servers aren't stable enough, nor the IDE
performant enough, to do any proper work on. The little experience I
had with the VS2005 was that it was actually very good and the
performance just fine (on my 1.7GHz Dothan laptop w/1GB memory), but I
can't argue with server stability issues.
Regardless, I particularly recommend reading phase 3, which discusses critical language/library differences.
I've updated the article about events and .NET remoting with some source code. Let me know if
you find it useful. That said, I haven't been active on the 'net for
the last few days so I have quite a bit of catching up to do.
A colleague was writing a bit of image processing code in C# while
working under the assumption that a bitwise shift operation by a
negative count (i.e. lvalue >> -2) would result in the opposite shift ( lvalue << 2
in our example). Nevermind the logic behind that assumption, while
helping doing some research I've stumbled upon what might be a
portability issue in the C# language design.
Apprently C# defines the left/right-shift operators as, for example:
int operator >> ( int x, int count );
It goes on to specify the behavioural differences between 32-bit and
64-bit code but gives no indication of what happens if you shift by a
negative value (which is possible given that count is of type int); this is left undefined. This leaves certain behavioural aspects of applications up to the VM; what probably happens is (for Intel processors anyway) that the JIT compiler generates something which looks like:
mov ecx,[count]
and ecx,0x1f
shl [eval],ecx ; or sal, if x is uint...
If count is negative, this will result in a mask of the two's complement, so for -2 this would be 11110
- or a shift-left by 30. I'm not sure what prompted Tal to make the
assumption regarding negative shifts, but the fact of the matter is
that his code compiled without warning. If the default operators were
declared with uint count,
at the very least we'd get a "possible signed-unsigned mismatch"
compiler warning. Most people would slap themselves and correct their
erroneous code.
I couldn't find any reference of this with a Google search and would
be more than interested in hearing corrections, explanations or just
opinions...
Update (September 7th, 10:16): As per Eli Ofek's advice I started a discussion thread
on the MSDN forums which already proved useful. A guy calling himself
TAG suggested that the reason why the operators are defined with signed
shift count is that unsigned types are not CLS- (common language
specification-) compliant. This could very well be the case, however I
am adamant that the language specification should reflect this; also,
the fact that the CLS does not support unsigned types is nontrivial
(and not easily found), which could potentially mean a lot of projects,
open source and commercial, are in fact nonportable because they make
use of unsigned types.
The game reviews I promised are still in the pipeline (it takes a lot of effort to get myself in the "reviewer state"), but I did post other stuff instead (mostly software- and development-related). Now it's time for tidbits:
- I've been sorely lacking a "navigation" submenu in Microsoft Word. I use a lot of internal hyperlinks in my documents (and have been reading and writing quite a few of those for the past few weeks), and it's a pain in the ass not to be able to navigate back and forth. Apparently it's just hidden in the Web toolbar and is readily accessible using Alt+Left and Alt+Right keyboard shortcuts. Oddly enough the keyboard customization dialog shows a GoBack function as well as the WebGoBack-WebGoForward duo; I'm not entirely clear on the difference yet. Anyways it's amazing how much better life is all of a sudden.
- There are numerous updates to the ReSharper 2.0 beta post.
- Thanks to Ofer for introducing me to the kickass bugmenot.com. It's basically a user-contributed database of registration information for any and all websites (there's even an entry for Nectarine!) which should prove amazingly useful, particularly when complemented by services like DodgeIt. They also have a petition asking content providers to stop with the pointless mandatory registration procedures. Not sure if I'll sign or not, but the site itself is damn useful.
- DevBoi seems to be a very useful development tool: it is a sidebar extension for Mozilla browsers offering easy access to online/offline documentation repositories for standards such as HTML, CSS and more.
- Apparently them christian preachers weren't kidding around: pr0n can indeed make you blind. Consider yourself, er, warned.
Light load this time. More to come.
I always enjoy researching languages (a passion that's only intensified since I cowrote our internal C#->java source-level compiler), so when a colleague approached me with an issue he had while creating a design in C# I was immediately intrigued.
Consider the following scenario:
class a1
{
public virtual int ret()
{
return 1;
}
}
class a2 : a1
{
public override int ret()
{
return 2;
}
}
Now, suppose I want to create another class, a3, which overrides ret but instead of implementing it on its own, it calls the a1 implementation - effectively skipping two generations of inheritence. If I wanted to call a2's implementation I could write a simple base.ret() call, so for a1 it's a simple case of base.base.ret(), right?
Quite wrong. Apparently the C# language specification defines the base keyword in a way that simply does not allow this. I was curious of this is the case with java as well, and lo and behold: java doesn't support super.super.member constructs either.
While researching the issue, I've come across two particularly interesting notes: Mads Torgersen, the new Microsoft program manager on C# Compiler and Language, has this to say in an interview:
Q: why only the first immediate base class is allowed in c#? e.g. cant do base.base.ToString()
A: The behaviour of your base class is determined by the writer of that class. It would open up a hole for breach of contract if you could bypass this and access something that this writer has decided to hide from you.
I'm not sure I'm convinced by this; it assumes the person who writes the instance class is not the same person who wrote the base class, which is not always the case. Other people around the 'net have said that this is a sort of "OOP no-no"; I can't say I've ever thought about this particular issue very deeply so I'll have to do some more thinking. If anyone has any references (no books, please - they're expensive and difficult to get) I would be very interested in hearing about it.
Brian Maso, posting to a similar discussion regarding java, suggests that this limitation derives from the java virtual machine design:
"super" is not an object reference. It's a Java language fiction. It
basically indicates to the compiler that the target method call uses the
"invokespecial" bytecode, not the usual method invocation bytecode
"invokevirtual". This is as opposed to "this", which is an actual object
reference variable.
If that is indeed the case, I can imagine the CLR shares similar design limitations, however this is research I'll leave for another time. For the time being suffice to say that the only way to do this is to use reflection, which is a sloppy solution which hinders performance, readability and safety. Imagine accessing runtime information, creating class instances (generating additional work for the GC in the process) etc. instead of a simple vtable indirection - it's not even funny!
I was implementing a watchdog system over a certain system's XML configuration repository using System.IO.FileSystemWatcher. Annoyingly, changes to the file (such as saving it with Notepad) would often result in the change event being fired twice. The system is designed so that whenever the file is changed, it is reloaded and several parts of the system are suspended (via thread synchronization) while the information is being re-cached. This in itself wouldn't be a problem since changes to the XML files are manual and rare, the XML schemas and serialization metadata are already cached etc. so the reloading operation shouldn't take more than 100-200ms (and the lock itself is only obtained at the very end of said process) - however there is a drain on CPU time and memory resources which I certainly wouldn't want doubled.
While it seems I wasn't the only one to encounter this behaviour, I've yet to see a proper solution to it; in the meanwhile I settled for a small hack where an update to the XML file are only processed if n seconds (2 in my case) have elapsed since the last update. Does anyone know of a cleaner way to solve this?
I came across a fairly unusual situation today, where a referenced
assembly contained XML schemas as embedded resources. The schemas may
(and do) contain <xs:include> and <xs:import>
directives, which could not be resolved when I was trying to compile
the schema: the schemas were including other schemas by relative URI
(for example, SystemConfig.xsd has an <xs:include schemaLocation="Base.xsd" /> directive), and when the schemas are loaded from a resource there are no URIs to speak of.
After a bit of reading I settled down to write a custom implementation of XmlResolver. It's used like so:
Assembly container = typeof( anyTypeFromTheResourceAssembly ).Assembly;
XmlResourceResolver resolver = new XmlResourceResolver( container );
schema = XmlSchema.Read( stream, new ValidationEventHandler( schemaValidationEventHandler ) );
schema.Compile( new ValidationEventHandler( schemaValidationEventHandler ), resolver );
Grab it here, and do let me know if you find this useful or have any comments/questions!
Update (18:58 GMT+2): Interesting. Apparently a developer called Jay Harlow wrote a similar class
a while ago; his is VB.NET, mine is C#, but the similarity is
staggering. So if you're looking for a VB.NET version of the class,
there you are 
I've been using NDoc a lot over the last couple of weeks and have found it invaluable. There is, however, one major hurdle I've encountered: it doesn't seem to support documenting of events. At all. Now I'm trying to generate documentation for one of our interfaces (which consists mostly of events) but can't :-(
I couldn't find anything relevant on the web (via Google or Google Groups). Ideas?
Check this out: How to install Windows XP in 5 hours or less. I found this one particularly funny:
56. Time passes. It is getting dark. You are likely to be eaten by a grue.
I'll give a shekel (don't ask) to anyone who knows what that's all about  (well no, not really, but it's funny anyway).
I was about to download log4net
1.2 beta 8, which I've been using for almost two years now, only to
find that the project's been moved from SourceForge to Apache and an
incubation release it out.
1.2.9 beta looks extremely impressive and I will report my comments on the subject as I become more experienced with it.
From the list of features the ones that impressed me the most are:
- The new logging contexts; NDCs was always thoroughly useful
(never found any use for MDCs though) and an extensible, scoped NDC
should indeed prove useful.
- PatternLayout customization; combined with the new logging contexts
this seems to be an incredibly powerful tool (consider: conditional
object state dumps with no little or no code overhead/clutter!)
- .NET formatting syntax. Trivial but necessary.
- Customizable levels for finer debug message granularity.
- Per-appender security contexts: 'nuff said.
- Pluggable file locking for FileAppender; I'm not readily sure where this would be useful, but I bet I'll find it before long...
I'm always impressed by open source goodness
Scott's released dasBlog 1.8!
I don't have time to install it just yet - will probably save that for
tomorrow. Since all the bugs I filed were fixed the new version is
bound to be da bomb!
Update (August 15th, 11:32 GMT+2): dasBlog 1.8 is up and running. Oddly enough it seems to be compiled, or at least set up, to run in debug mode (web.config is set to <complication debug="true"... />), so I changed that. Everything seems to be in order. The new BlogXP theme is very slick, but it's going to take quite a
bit of time to rework it to fit the site design (get rid of the
calendar, change the title, add a bit of personality...), so I'll stick
with my modified DiscreetBlue in the meantime.
I went to see The Island in the cinema with a bunch of friends the other day. Hey, it didn't cost me anything so why not, right?
It's sort of 1984 (at least in the beginning) meets The Matrix (towards the middle). There are plenty of very high-profile actors who do a pretty good job with the mediocre script (including Ewan McGreggor, Scarlet Johansson, Sean Bean, Steve Buscemi and Michael Clarke Duncan) - there's even a guest role for our own Noa Tishby.
Bottom line: harmless generic action movie; ten years ago it might've been considered innovative but nowadays it's just a cash cow. The acting is, as I said, pretty good (considering the amount of star actors), the eye candy is great - but the movie itself is really uninspired.
.NET Remoting is a pretty nice piece of technology. It theoretically
allows you to tear out a class from the server code and use it remotely
from a client; it features all sorts of nice features like SAO and CAO,
lifetime leasing and sponsors, pluggable protocols and provider chains
etc. But in order to effectively use it there are quite a few things
the programmer should take into account: the obvious ones
(serialization, object lifetime, state) and the less-obvious ones
(object construction [for CAOs], security [e.g. typeLevelFilter]).
Today I'd like to discuss one these less-obvious issues,
specifically the usage of events in remotable classes. For clarity,
lets assume the following scenario: a Server has a singleton SAO
factory for client registration. The CAO class is called IProvider. Suppose it has the following structure:
public delegate void ServerEventHandler( string message );
public interface IProvider
{
void ClientMessage( string message );
event ServerEventHandler OnServerMessage;
}
And suppose the client were to register itself to the event like so:
p.OnServerMessage += new ServerEventHandler( p_OnServerMessage );
What happens behind the scene is a little less trivial. Delegates
themselves are value types which hold a reference to their target. So
in other words, we are sending the server an object which holds a
reference to our client class, in itself a MarshalByRefObject derivative. What happens when an object is marshalled by reference? Answer: a proxy is created on the remote machine. What happens, in effect, is that the server is trying to create a proxy of the client object, which requires the assembly containing the client object's type. A naïve implementation like the one above would result in the following error (click for a larger image):
The solution is something of a hack I originally found in this article;
the general idea is that for every delegate defined in your shared
interface you create a shim object. This object acts as an intermediary
between the client and server, passing events from one side to the
other; the shim itself is defined in the shared assembly, which means
it is always recognized by both client and server. This way the server
does not need to recognize the client object type:
The actual shim implementation is ugly but trivial. Here's one example of how to do this for the ServerEventHandler delegate:
public class ServerEventShim : MarshalByRefObject
{
ServerEventHandler target;
private ServerEventShim()
{
}
public void DoInvoke( string message )
{
target( message );
}
public static ServerEventHandler Wrap( ServerEventHandler handler )
{
ServerEventShim shim = new ServerEventShim();
shim.target = handler;
return new ServerEventHandler( shim.DoInvoke );
}
}
Now all that's left is to slightly modify the way the client registers itself for the event:
p.OnServerMessage += ServerEventShim.Wrap( new ServerEventHandler( p_OnServerMessage ) );
Be advised: the client is now effectively also a .NET Remoting
server, which means you have to register a channel for it (you should
use 0 for port; this instructs Remoting to use whatever available
incoming port.) You are also serializing custom types here, which means
you must also set typeLevelFilter=true for this incoming channel.
Finally, to be honest I'm a little astonished that the .NET Remoting
team didn't realize this shortcoming and found a more reasonable way to
do this (anonymous, automatically generated shim classes? Why not -
there are anonymous, automatically generated proxy classes...) Oh well,
another few hours down the drain.
Update (August 29th 09:45 GMT+2): As per the request of Peter Gallati, here's some source code demonstrating the technique. Feel free to drop me a line if you need any further help.
I just installed The Gimp 2.2.8 on my laptop. Somehow when I used it on other machines I managaed to miss the fact that it's partially migrated to Hebrew, and that this mode is enabled by default on machines with their regional options set up accordingly.
Now, I can't stand Hebrew in applications so I generally always set
localizable applications to English (including GAIM and even Windows
itself); getting Hebrew menus is bad enough, but when they're only
partially translated and the dialogs aren't RTL'd to begin with it
looks absolutely terrible.
If you try to run The Gimp on a Hebrew-enabled machine I seriously suggest you set LANG=en in your environment settings.
I've converted. Three of what I considered the most useless Windows
features have one me over. Specifically: large font sizes, large icons
and ClearType.
Now let me make myself clear: for the vast majority of people on the
vast majority of equipment, these features are indeed absolutely
useless. Six months ago I bought an LG LM50
laptop (which is absolutely terrific, by the way) with an 1400x1050
SXGA+ display. I was stunned by the resolution, particularly the
desktop real-estate and sharpness the new display provided, and never
felt that the default font sizes were too small: they were certainly
smaller, but the display was sharper and when typing on the laptop I
was sitting much closer to the display than I was used to. Then I
figured what the hell, I'll give it a try, enabled the three features
and was absolutely stunned: I had (at worst) the same desktop
real-estate I did on the old CRTs with much clearer fonts and icons.
The whole experience is that much easier on the eyes, and I still get
the added bonus of extra desktop real-estate (particularly when
browsing) and much better resolution when displaying images etc.
I'm never moving back to CRTs!
I had started to write an article about event shimming in .NET Remoting (yes, I know there are such articles already, but I couldn't find one that was easily accessible and understood) yesterday, but simply crashed and slept over 9 hours. Now I'm at work, so I guess it'll just have to wait until later today or tomorrow. That said, there's the usual variety of things of interest:
- GuestMaps are a really awesome third party tool based on Google Maps; the idea is that you basically put a map on your site and it allows your readers to mark where in the world they are. I would've put one myself, but I'd rather save myself the embarresment of finding out how many readers I have

- China's on the news again, this time for putting a young man behind bars for political activies (posting "harmful" essays on the 'net). There are two things I find extremely worrying about this: the first is the way the Chinese propaganda machine operates, specifically the official reasons for incarcarating the man: "[he] jeopardised national unity and territorial sovereignty, spread lies and disturbed public order and social stability". There is also the reason given by the Chinese government for its attempts to monitor internet cafés: "[they] can affect the mental health of teenagers while spreading unhealthy information". The second is that any "western" country with its eyes on Chinese business is decidedly ignoring these increasingly dangerous signs of human rights violations, turning a blind eye to what will undoubtedly come back to bite everyone on the ass.
- The Commentator is really funny. I'm very glad it is a joke, because after showing it to some of my colleagues I was a bit worried that they might actually use it.
- There is this movie I was attempting to find for ages. I haven't seen it since I was 6 or so and only knew it by its Hebrew name, the direct translation being "hole in time". Well thanks to the wonders of the 'net I was finally able to find it: it's called Biggles: Adventures in Time, and according to one reviewer it sucks rather badly. Excellent! I'm waiting for my copy and will post my opinion when I have one.
- Go play Psychonauts.
- Here's an interesting article explaining why you must never use "double-checked locking", which is an (apparently broken) technique for saving some CPU cycles on synchronization checks. If you do any performance-savvy multithreading code it's an absolute must-read.
- This is absolutely awful.
Things to expect in the (reasonably) near future:
- The .NET Remoting vs Events article I was talking about
- My experiences with Linux
- Reviews for Psychonauts, Half Life 2, Chronicles of Riddick
A list of Gecko configuration options (accessible by entering about:config in any Gecko-enabled browser, such as Firefox) can be found in the knowledge base (via linmagazine).
I'll be listing interesting options here whenever I find them.
| editor.singleLine.pasteNewlines | Integer | Determines the behavior when pasting content containing newlines into single-line text boxes. 0: Paste content intact (include newlines) 1 (default): Paste the content only up to (but not including) the first newline 2: Replace each newline with a space 3: Remove all newlines from content 4: Substitute commas for newlines in text box |
| browser.urlbar.autoFill | Boolean | True: Enables inline autocomplete.
False (default): Opposite of above. |
Or to quote Penny Arcade from a while back:
Quit whatever you're doing, it's not important. Maybe
you're performing a surgery. Put the scalpel down. Maybe you're holding
a runaway car back from rolling over a carriage which contains an
infant. There's no baby shortage, and even if there were, they're
apparently a lot of fun to make. Run over the roof of the car, go home,
and open up a browser.
It's rare that I encounter something which I can't find the proper amount of superlatives to describe. That something is Charly and the Chocolate Factory, the latest Tim Burton/Johnny Depp movie based on the famous novel by Roald Dahl (which I admit not to have read). I will not bother you with the list of superlatives I did manage to come up with, but trust me: you owe it to yourself to watch this movie. Just stop whatever it is you're doing and go.
Another recommendation that's bound to steal a few days of your life
(and repay you by making the remaining days worth living) is the
fantastic Psychonauts. It hardly matters what you're playing now, it can't compare. Remember Monkey Island? Day of the Tentacle? Grim Fandango? Same guy, and Psychonauts just might be his best work ever. You owe it to yourself to play this game. Just stop whatever it is you're doing and go.
Mailinator's been down for a while, and also slow and quite limited. I've been looking for a replacement and was recommended DodgeIt, which hits the spot. Highly recommended!
I was rather surprised to find comment spam in my blog (considering
it's new and relatively unknown), but then it was Outlook-specific spam
and I did have some Outlook-related blogposts.
Anyway in an attempt to fight it off I've enabled Movable-Type Blacklists as well as CAPTCHA images in the comments. I hope this isn't too annoying for you; if it is let me know and I'll remove it.
|