Sometimes (Visual Studio) error messages are just misleading

Take into account this code

    () =>
        throw new Exception();
        t =>

Which results in following error:

error CS1593: Delegate ‘System.Action<System.Threading.Tasks.Task,object>’ does not take 1 arguments

If I use an overload that takes TaskContinuationOptions.OnlyOnFaulted instead of TaskScheduler.FromCurrentSynchronizationContext it just works. There are two overloads (among twenty of them) of ContinueWith:

public Task ContinueWith(Action<Task> continuationAction, TaskContinuationOptions continuationOptions);
public Task ContinueWith(Action<Task> continuationAction, TaskScheduler scheduler);

So, why does the later work and the former doesn’t? Can you guess without reading on?

The explanation is really simple – TaskScheduler.FromCurrentSynchronizationContext is not a property but a method and thus it should be used like TaskScheduler.FromCurrentSynchronizationContext(). Once brackets are in place it works. Rookie mistake.

However the C# compiler’s error message is misleading in this case. Instead of reporting that FromCurrentSynchronizationContext is a method and not a property it yields “can’t find proper overloaded method”. At least it could yield both errors.


An odd error when adding items to toolbox in Visual Studio 2010

Ever got an error like this when trying to add a toolbox item?


Textual representation (for search engines):

Microsoft Visual Studio
Could not resolve mscorlib for target framework ‘.NETMicroFramework,Version=v4.1’.  This can happen if the target framework is not installed or if the framework moniker is incorrectly formatted.

and here is another one:


Microsoft Visual C++ Runtime Library 
Runtime Error!

Program: C:\Program File…

An application has made an attempt to load the C runtime library incorrectly.
Please contact the application’s support team for more information.

The later one is really useful.

Note: It isn’t strictly linked to v4.1 – it happens with earlier versions as well.

Another side effect is that toolbox is somewhat corrupted, only certain tabs are loaded. But fear no more, here is the culprit and the workaround we found.

It turns out that there are problems when .net microframework is installed and its assemblies can’t be loaded.

Update (23.12.2011)

Microsoft wisely broke the link to the thread containing the solution – the solution thread has vanished into the black hole of the internet.
So, here is the solution as far as I remember :-):
Rename the files (or delete them) FrameworkList.xml which are installed in C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETMicroFramework\v4.x\RedistList. Note that each .NET Micro Framework installs its own file in its own folder.


Disabled post comments due to spam

Due to the massive spam amount I was getting these days I’ve opted to disable all comments to my posts for the time being. When I figure out a proper anti-spam system I’ll re-enable them, perhaps through reCaptcha or something.

You can still send me the feedback through the Contact form.

Stay tuned.


Two weeks of HTC Desire impressions

I am following the Android phones progress for quite some time now, though I haven’t had one for real yet. At best I peeked a friend’s phone or played with emulator. My current Windows Mobile 6.1 device is literarly falling apart and thus I am looking for a new phone and why not, an Android based one. Luckily I’ve got a HTC Desire phone from Mobitel (largetst Slovene mobile network operator, thanks to Jure) for two weeks for testing purposes. HTC Desire is a NexusOne’s twin


Final Builder as a helper

Today I’ve tried to ILMerge a WinForms application that uses a bunch of DevExpress controls to produce a single executable in response to this thread. Just for testing purposes.

The thing is that ILMerge is a console application that requires a healthy amount of command line parameters. Not wanting to type them like crazy, I’ve opted to use ILMerge action within Final Builder that provides an UI for entering parameters (which are mostly long paths to assemblies involved in merging):


Instead of writing all those paths in command line and figuring out the command line parameters syntax I just clicked few “folder buttons” and navigated through open file dialogs.

The bottom line is that I’ve spent half a minute with Final Builder instead of many minutes in command prompt. The only drawback is that I’ve spent additional minutes writing this post.

Looks like I’ve found another use for Final Builder as well.


Upgraded BlogEngine from 1.4.5 to 1.5

I have just upgraded, an excellent blog engine which hosts this blog, from 1.4.5 to 1.5. The process was more or less smooth as I’ll describe in next points:

  1. Download Web from download page.
  2. Read upgrade tutorial.
  3. Make a backup of current installation and database if you are using it.
  4. Delete all files and folders except for App_Data.
  5. Copy new files.
  6. Copy extensions, widgets and other custom data from backup you made in #3.
  7. Upgrade database structure with script found in Setup/SQLServer folder (or any other if you are using other database).
  8. Open web.config and replace the connectionString (I am using SQL Server as a storage).
  9. Replace all occurences of defaultProvider attribute to “DbBlogProvider” (blogProvider, membership, roleManager).
  10. Make sure App_Data is writable for

I think that’s pretty much it for my upgrade process.


Providing syntax editor within a .net application

Many times I’ve incorporated some sort of scripting capabilities into my .net applications. Usually I’d let user to type in some C# code and then I’d take that code, compile it in memory in another AppDomain (to avoid memory hogging) and execute it when required. Or in other occasions I’d let user type some SQL code and later use it to execute a T-SQL command or against the database. The C# feature provides some challenges while the SQL feature is pretty straightforward. The weak point in both feature implementations is the lack of syntax coloring control or even better, intellisense, error underlining and other nice stuff we are used from Visual Studio. In other words if one wants to do it with style a proper syntax editor is required. Creating such a control by myself would be a complex task and without unlimited time at my disposition it’d be a mission impossible.

That’s why I’ve bought Actipro‘s Syntax Editor for WinForms (and no, other platforms aren’t supported right now, WPF being in development AFAIK). The core Syntax Editor is a huge beast in positive sense. It supports all sort of editor features one would expect. Its language definition is dynamic, meaning that you can create support for whatever language you want through an XML definition or, if you require additional features, through an add-on which is written in .net. You most probably won’t need to, because many definitions come out of the box, such as “Assembly, Batch files, C#, CSS, HTML, INI files, Java, JScript, Lua, MSIL, Pascal, Perl, PHP, PowerShell, Python, SQL, VB.NET, VBScript, and XML“, but it is nice to have an open definition.

If you are serious about providing editing support for either a .net language (C# and VB.NET) or XML language then you have an option to buy an add-on that extends the support even further. With such an add-on the Syntax Editor really starts to shine with IntelliPrompt, syntax error display, reflection and metadata cache of referenced assemblies, etc. Similar features are provided with XML add-on, once you provide matching XSD. I won’t go in the details since this stuff is all over Actipro‘s web pages. Worth to remember is the fact that both .net and XML add-on are a separate products. If you don’t want to buy them you are actually free to create such add-ons by yourself, too. There is even a sample of a simple add-on.

The learning curve is steep but there is documentation to help, a huge (but readable and good) sample that demonstrates various features and a responsive support forum. Support is good, they quickly fix the errors and include the fix in the next minor version. I actually stumbled upon few errors (no wonder there are error in such a big product) which were quickly fixed. If you are interested in what Actipro is doing or explanations you might check their blog as well.

All in all Syntax Editor is a feature rich, easy to use, flexible and expandable syntax editor worth looking at. It is actually very easy to use most important of its capabilities writing just a bunch of lines of code. If you are interested in the product then there is no better way than to check it by yourself – go download their time limited full trial version.

Ah, and here is Syntax Editor in action in my Righthand’s LLBLGenPro Query Studio (application in-development):



Intel Matrix Storage Manager (RAID) drivers are perfect!

I am using Intel’s ICH9R RAID controller integrated on my server’s motherboard for a RAID5 configuration of three disks. Since I don’t need huge performance the mentioned hardware is enough for me – I assume the driver is bug free. Now, one would think that Intel is a serious company, their RAID controller is good and support is great, right? Wrong.

First, let me mention that this isn’t my first problem with this combination, although used for RAID 0+1 with 4 disks. It corrupted the array when I was using Apple’s software such as iTunes. Intel’s support denied any problem with their drivers. They were perfect they said. After a while Intel silently acknowledged the problem and fixed the drivers.

Present time, my Windows 2003 R2 server went BSOD (it wasn’t clear why at that time), I restarted it and immediately after login the RAID software kicked in and started rebuilding the array. It happens sometimes when OS is reset like this. After the rebuild was finished it notified me that one of the drives in array failed and array is running in degraded mode, IOW if another disk fails, say goodbye to data. I also checked the minidump produced by BSOD and go figure:

CUSTOMER_CRASH_COUNT: 1 DEFAULT_BUCKET_ID: DRIVER_FAULT_SERVER_MINIDUMP BUGCHECK_STR: 0x8086 PROCESS_NAME: Idle CURRENT_IRQL: 2 LAST_CONTROL_TRANSFER: from f7b4a79a to 80827c3e STACK_TEXT: 8089a444 f7b4a79a 00008086 8b26b1c0 8acf5340 nt!KeBugCheck+0x14 WARNING: Stack unwind information not available. Following frames may be wrong. 8089a45c f7b4adcd 0000001b 8089a500 f7b13c6f iaStor+0x3b79a 8089a468 f7b13c6f 8b266000 808722e0 8b26b1c0 iaStor+0x3bdcd 8089a500 f7b14905 8b26b1c0 8b392878 ffdffa40 iaStor+0x4c6f 8089a598 f7b511e3 8b26b1c0 00000000 8089a600 iaStor+0x5905 8089a5a8 808320f0 8b266728 8b266000 00000000 iaStor+0x421e3 8089a600 8088de1f 00000000 0000000e 00000000 nt!KiRetireDpcList+0xca 8089a604 00000000 0000000e 00000000 00000000 nt!KiIdleLoop+0x37 ##ERIGNORE##

I am not a great kernel debugging guy but it looks obvious to me that the BSOD was actually caused by iaStor which means Intel Matrix Storage Manager driver. Looks like that a drive failed and RAID driver managed to thrash my OS into BSOD instead of just mark the drive as failed (as later did). So I contacted Intel’s support once again. The conversation was something like this (short version):

Me: “Your driver BSOD my OS due to a drive failure.”
Intel support: “I am glad that you’ve found the cause of the problem, just replace the drive and array will be restored.”
Me: “Yes, but what about BSOD? Your driver really shouldn’t thrash my OS even if a drive fails.”
IS: “These drivers have been rigorously tested and we have not experience such error. If the issue continues or reoccurs, please contact your motherboard manufacturer.”
Me: “Please, it wouldn’t be the first time that these “rigorously tested” drivers would fail miserably instead of protecting the disk content (providing the link to earlier problem with iTunes). Now, please, send my minidump information to a serious engineer of Intel.”
IS: “Then again, we have tested the Intel(R) Matrix Storage Manager and we have not seen this. You need to keep in mind as well that we have not developed or manufactured your motherboard. Even though your board is based on our chipset and RAID controller, the integration of these vary from manufacturer to manufacturer. At this point, we can only recommend that you contact Gigabyte (op.a.: my motherboard manufactures) for further technical assistance.”

Conclusion? It is groundhog day all over again. The story repeats. Intel drivers/hardware is perfect, not a chance that there is an error in there. And if you see an error, it can’t be their, since they haven’t seen it. Yet. They practically tested all the possibilities and their stuff won’t misfire. Great job, Intel. This is support at its best – deny the problems.
Granted, there are very minimal chances that the chipset is badly integrated. And so there are chances we are not alone. If you ask me, Intel should treat a BSOD report very seriously and analyze it “rigorously”. Sticking their head into the sand won’t make the bug disappear. It just won’t.


.net 3.5 SP1 beta and Visual Studio 2008 SP1 beta are here

There are various enhancements and even changes in SP1. Perhaps one of the most interesting is the change in security: applications launched from LocalIntranet will get FullTrust by default from now on (read here). I guess this is because a lot of people found annoying that they couldn’t launch applications (that required FullTrust) from network shares. This move will certainly ease the internal deployment but at the same time it might cause security problems, too.

Here is the list of .net 3.5 SP1 runtime performance enhancements and another list of improvements. A list of changes in TFS. Brad Abram’s list and finally Scott Guthrie’s take.

Download the bits from here.


LINQ to XtraGrid

If you work with [DevEx] XtraGrid’s GridView then you know that it provides a relatively cumbersome way to read values of its grid cells: the values aren’t strong typed and the method is somehow not very OO oriented. It goes like this:

// read an int value from a cell int value = (int)gridView.GetRowCellValue(rowHandle, colAnIntColumn);

Note that you can’t read the value like this:

int value = (int)gridView.Rows[rowHandle].Value(colAnIntValue); // or int value = gridView.Rows[rowHandle].ColAnIntValue;

which would be more object oriented but probably the performance would suffer. If Value property would be strong typed it would be just great. But the most important feature would be to access the values through Rows collection. Why? Because one could use LINQ to query them. That is unfortunately impossible out of the box.

Here is a simplified sample code to find the rowHandle of the row with SOMEVALUE in one of its colAnIntColumn field:

int rowHandle; for (int f; f<gridView.RowCount; f++) { int value = (int)gridView.GetRowCellValue(rowHandle, intCol); if (value == SOMEVALUE) { rowHandle = f; break; } }

It isn’t really pretty, right. Hence the idea of using home made LINQ to XtraGrid.

First, we need a class that will represent a single GridView‘s row:

public class GridViewRow { internal readonly GridView GridView; internal readonly int RowHandle; public GridViewRow(GridView gridView, int rowHandle) { GridView = gridView; RowHandle = rowHandle; } // method that wraps GetRowCellValue method for getting a cell value // using column name public T Field<T>(string fieldName) { return (T)GridView.GetRowCellValue(RowHandle, fieldName); } // overloaded method that wraps GetRowCellValue method for getting a cell value // using column reference public T Field<T>(GridColumn column) { return (T)GridView.GetRowCellValue(RowHandle, column); } }

The code is pretty trivial. The class has to reference the source GridView and RowHandle that represents a row in GridView‘s notion. Note the two Field<T> overloaded methods that lets you get cell values in OO manner. Next, we need a collection of GridViewRow objects that implements IEnumerable<T> (IEnumerable<GridViewRow> in this case) interface (which in turn implements IEnumerable hence the two GetEnumerator() methods):

public class EnumerableGridViewRowCollection: IEnumerable<GridViewRow> { internal readonly GridView GridView; public EnumerableGridViewRowCollection(GridView gridView) { this.GridView = gridView; } public IEnumerator<GridViewRow> GetEnumerator() { for (int i = 0; i < GridView.RowCount; i++) yield return new GridViewRow(GridView, i); } IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } }

The core functionality here is public IEnumerator<GridViewRow> GetEnumerator() method. It uses yield return keyword to create GridViewRow instances for each row as query progresses through collection. From the perspective of garbage collection this shouldn’t be too huge problem because the objects are small and have a short lifetime usually. Thus they are relatively cheaply garbage collected. Furthermore one doesn’t work with million or rows in a grid – if you do, reconsider your approach; but rather in range of thousands. This class also holds reference to source GridView.

Now we have a GridViewRow class that represents a GridView‘s row and a collection of row objects that are dynamically generated for each query. The only step left is to build a way to get the EnumerableGridViewRowCollection out of GridView. We could use a helper class, pass GridView to EnumerableGridViewRowCollection directly, or derive a class out of GridView and add such a method. However the former aren’t really nice and the later is complex and doesn’t provide same functionality for other GridView derived views. Fortunately for us .net 3.5 introduced extension methods which are a perfect way to implement this functionality. Here is how I’ve built it:

public static class GridViewEnumerator { public static IEnumerable<GridViewRow> AsRowEnumerable(this GridView gridView) { return new EnumerableGridViewRowCollection(gridView); } }

This dude adds method AddRowEnumerable to GridView class and to all of derived classes.

LINQ to XtraGrid is now complete and here is rewritten sample query from above:

int rowHandle = gridView.AsRowEnumerable().First( row => row.Field<int>(intCol) == SOMEVALUE);

Doesn’t it look nicer and more compact than the query above? The beauty of the LINQ to XtraGrid is that it opens a whole LINQ world to XtraGrid’s GridView and descendants. Yes, you can use whatever LINQ construct that works on IEnumerable<T> such as:

var query = from row in this.AsRowEnumerable() where row.Field<int>(intCol) == SOMEVALUE group row by row.Field<string>(nameCol) into g orderby g.Key select g;

So, here it is. A simple LINQ to XtraGrid implementation. It doesn’t do everything, but hey, it is a start. Happy?