When Not-True Doesn’t Equal False


There is a strangely common, reoccurring bug I’ve seen return, again and again, in most projects I’ve worked on in recent years. I call it the “Not True != False” bug, and it crops up, usually, when passing query parameters to a search service of some sort, when you want to search for entities who match a certain condition, and you end up not being able not to search by that condition. Confusing? Let’s back up for a second.
no comments

Building a Nullable ComboBox


I like WPF. It has a bit of a learning curve, but once you get over it, you have an extremely extensible UI model that you can tweak very deeply. Unfortunately, this mindset made Microsoft leave many of the built-in controls with some missing functionality, apparently with the intention that people extend it if they felt like it. One painfully missing piece, for me, was the ability to clear a ComboBox’s selection back to null, for a non-mandatory selection. You can add a Null value to the ComboBox’s ItemSource, but you can’t select it – selecting a null-backed value will...
tags: , ,
no comments

Not-So-Lazy Static Constructors in C# 4.0


A coworker pointed me towards an interesting blog post by John Skeet about the changed behavior of static constructors in C# 4.0 (yes, I know, it’s been a few years now, but I never ran into it). It seems that C# 4.0 now tries to be lazier when instantiated static fields. So if I have a side-effect free static method that doesn’t touch any members, calling it will not bother initializing the static fields. From Skeet’s post: class Lazy     {...
no comments

האם עוד צריך את VB.NET לתכנת מול אופיס?


עברו כמה שנים מאז שעבדתי עם Visual Basic.NET, והייתי בטוח שבימינו, ב-2013, נגמרו כבר הויכוחים של “איזו שפה יותר טובה”. שתיהן שפות עם יכולות דומות, והבחירה ביניהן היא בעיקר העדפה סגנונית. אבל מידי פעם אני עדיין רואה בפורומים או ב-Stack Overflow שאלה בנוגע ליתרונות של שפה אחת על השניה, וספציפית על יכולות ה-COM Interop של VB. האם היא באמת שפה נוחה יותר? המצב טרום .NET 4.0 לפני .NET 4.0 (שיצאה, יש להזכיר, לפני כמעט 3 שנים), התשובה היתה “כן”, אם כי “כן” קצת דחוק. VB הגיעה מתוך עולם ה-Late Binding, ולא היה לה בעיה להעביר לרכיב רק חלק מהפרמטרים שהם צריכים,...
no comments

Remote Debugging through fire, snow or fog


Remote Debugging in Visual Studio is a wonderful feature, especially during the later stages of testing and deployment, and even (if all else fails) when in production, but getting it to work is rarely smooth. Everything is fine if both the computer running VS and the one running the application are in the same domain, but when they aren’t, things start to break, fast. I So for those stuck debugging remote applications in different domains, here’s a quick guide to east the pain. On the the remote machine, install the Visual Studio Remote...
no comments

ArcGIS–Getting the Legend Labels out


Working with ESRI’s ArcGIS package, especially the WPF API, can be confusing. There’s the REST API, the SOAP APIs, and the WPF classes themselves, which expose some web service calls and information, but not everything. With all that, it can be hard to find specific features between the different options. Some functionality is handed to you on a silver platter, while some is maddeningly hard to implement. Today, for instance, I was working on adding a Legend control to my map-based WPF application, to explain the different symbols that can appear on the map. This is how...
tags: , , , ,
no comments

The Case of the Unexpected Expected Exception


“NUnit is being problematic again”, they told me when I came to visit the project. “When running unattended it’s not catching assertions properly and the test is coming up green, but when stepping through in the debugger, it works fine.”. It’s nice, when getting a passing test is acknowledged as a bad thing, at least when you don’t expect it to be. In this case, though, the fault wasn’t really with NUnit. 1: 2: 3: public void DoTheTest() 4: { 5: _myComponent.RunMethod(); 6: ...
no comments

Moq, Callbacks and Out parameters: a particularly tricky edge case


In my current project we’re using Moq as our mocking framework for unit testing. It’s a very nice package – very simple, very intuitive for someone who has his wrapped around basic mocking concepts, but tonight I ran into an annoying limitation that, while rare, impeded my tests considerably. Consider the following code: 1: public interface IOut 2: { 3: void DoOut (out string outval); 4: } 5: 6: 7: public void TestMethod() 8: { 9: var mock = new...
no comments

WPF: Snooping Attached Properties


When developing WPF applications, Snoop is a wonderful tool that can let us see our visual tree at runtime, and find errors in data binding that are otherwise hard to track down in debugging. However, Snoop has an annoying limitation – it can’t show us data-bound Attached Properties. Let’s say we have the following XAML: <Canvas> <Button Canvas.Left="{Binding Location.X}" Canvas.Top="{Binding Location.Y"}/> </Canvas> Snooping this application won’t show Canvas.Left and Canvas.Top among the Button’s properties, since they’re not a part of the Button object. If we have a...
no comments