Welcome to RightHand's community place Sign in | | Help

Lost Windows Live Writer

Today I lost my Windows Live Writer. I was doing a Windows Live update of installed WL applications. The update performed an uninstall first and install after. But the install failed and fails with an error 0x80070643. Of course it didn't rollback the original installation.

Quick googling for the solution doesn't help as well. Great error message and hidding installation log file is a great feature, Microsoft. Damn, I'll just use Sysinternals to figure out what goes wrong.

Posted by Miha Markic | 1 Comments
Filed under:

Calling WCF services from within Sql Server

It is possible to create a managed .net stored procedure for SQL Server that acts like a WCF client. SQL Server 2005 at least is required. But I won't talk about how to. I'd rather discuss an odd error you can encounter while performing this stunt.

On development machines one can encounter this odd error when WCF client is being initialized, after managed stored procedure is being invoked through T-SQL.

Msg 6522, Level 16, State 1, Procedure CalcAdd, Line 0 A .NET Framework error occurred during execution of user-defined routine or aggregate "CalcAdd": System.Configuration.ConfigurationErrorsException: The type 'Microsoft.VisualStudio.Diagnostics.ServiceModelSink.Behavior, Microsoft.VisualStudio.Diagnostics.ServiceModelSink, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' registered for extension 'Microsoft.VisualStudio.Diagnostics.ServiceModelSink.Behavior' could not be loaded. (C:\Windows\Microsoft.NET\Framework\v2.0.50727\Config\machine.config line 192) System.Configuration.ConfigurationErrorsException: at System.Configuration.BaseConfigurationRecord.EvaluateOne(String[] keys, SectionInput input, Boolean isTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult) at System.Configuration.BaseConfigurationRecord.Evaluate(FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult, Boolean getLkg, Boolean getRuntimeObject, Object& result, Object& resultRuntimeObject) at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject) at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject) at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject) at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject) at System.Configuration.BaseConfigurationRecord.GetSection(String configKey, Boolean getLkg, Boolean checkPermission) at System.C...

Note that everything is configured properly and WCF client inside stored procedure should initialize just fine. The problem is somehow connected to machine.config file or better, to some initialization of types defined there.

After few google searches I've come across this post from MS' Jason Pang. Looks like the exception is linked to WCF debugging feature, usually installed on development machines - this debugging service has problems with WCF client running under SQL Server.

Workaround: (Temporary) disable WCF debugging by invoking this command line utility:

[Program Files]\Microsoft Visual Studio 9.0\Common7\IDE\vsdiag_regwcf.exe -u

Now the WCF client inside SQL Server runs just fine. After you've done you can re-enable WCF debugging services by calling same exe with different parameter:

[Program Files]\Microsoft Visual Studio 9.0\Common7\IDE\vsdiag_regwcf.exe -i

Note that administrator privileges are required to disable/enable it.

Posted by Miha Markic | (Comments Off)
Filed under: , ,

Windows 7 beta at MSDN Subscriptions

In case you didn't notice Windows 7 beta is available at MSDN Subscriptions. The web site looks like under pressure so keep trying if you get errors.

Posted by Miha Markic | 1 Comments
Filed under:

Autoimplement base class constructors with CodeRush

How often do you derive a class and re-create all of the base constructors? This is not an uncommon task, let's take a custom exception class for example:

public class MyException: Exception { }

If you right click on Exception and pick Go to Definition from the context menu you'll see that the Exception class has four constructors:

public class Exception : ISerializable, _Exception { public Exception(); public Exception(string message); protected Exception(SerializationInfo info, StreamingContext context); public Exception(string message, Exception innerException); }

And you better re-create all four in your derived MyException class if you want to follow the design guidelines. This is how MyException should look like (without custom code that is):

public class MyException: Exception { public MyException() { } public MyException(string message) : base(message) { } public MyException(string message, Exception innerException) : base(message, innerException) { } protected MyException(SerializationInfo info, StreamingContext context) : base(info, context) { } }

This is a straightforward derived Exception class definition and needless to say it is quite boring to create all those constructors again and again. That's why CodeRush has a one-click base constructors recreation feature. Position the caret somewhere on the Exception word and invoke CodeRush with keyboard shortcut (by default the shortcut is Ctrl+CEDILLA) and instantly all of those boring-to-recreate constructors appear from nowhere. Brilliant.

Posted by Miha Markic | 1 Comments

Axialis is making a 50% off sale today only

Marc from Axialis sent me a message that Axialis is having 50% off sale today and only today. If you are in mood for creating artwork such as icons and cursors this would be the perfect timing. BTW their IconWorkshop is really a nice product, even for non designers like me. I haven't tried others.

Posted by Miha Markic | 3 Comments

SIOL (IPTV provider) managed to upset its customers once more

I have an IPTV provided by biggest national IPTV/IS provider. The current service is poor at best. We have FTTH (the slowest is 20Mb - that's awesome) but really lousy (~4Mb at best) MPEG2(!) encoded streams. The most obvious consequence of such encoding is pixelation when there is a faster change on the picture and poor quality in general. To make things worse there is a crappy, yet somewhat functional UI that lets you select channels and read EPG. It mostly works (except for occasional ASP.NET 1.1 server too busy error) and its speed is decent. IMO it mostly lacks two features:

  • one can't browse other channel's EPG (electronic program guide) without actually changing channel (IOW watch a channel and read other channel's EPG). I once asked SIOL about this and the response was: "Check out the teletext - you can't perform this stunt in teletext either". So much about understanding the technology progress.
  • one can't mark favorite shows and have an option of notification before the show

Now, both features are minor, yet SIOL isn't capable of implementing them. Since the UI is built around ASP.NET 1.1 (as seen on occasional errors) it shouldn't take more than a week to implement the two features. But they didn't change the UI for years now. Except for upgrading the progress icon to an animated gif.

Then, one day, they started a SIOL TV+ UI. (note the + char). It features a newly organized and richer UI, plus VOD and a recorder through UI (storage is provided on SIOL's server). Sounds great, right? Not at all. Here is the list of consequences:

  1. You have to buy a newer STB (or get one for free if you sign with SIOL for 2 years)
  2. UI is slow as hell. I mean really really slow at the point where it is unusable.
  3. UI is cluttered as hell - it is really bad and a total mess.
  4. It doesn't have favorite channels group.
  5. Recorder doesn't work and even when it will it will be useless: it is enabled only for a couple of Slovene channels (due to legal issues) and those shows will be persisted only for at most 2 days (the total place for storage per user is 6 hrs in total) . It won't be free as well since it uses SIOL's storage. There are other problems with recorder not listed but the question is why they bother at all with such crap service?
  6. VOD: after you pay for the movie you have 24 hours to watch it. The library is poor, at least the last time I've checked it.

True, I didn't check it lately. But for a reason. There were reports that lately people who checked out the new UI couldn't go back to the old, functional, one. The two UIs could coexist until recently.

And now, actually 10 days from now, SIOL is disabling the old UI for good and forcing everybody to new great new one - with or without the new STB. That's indeed a great move, kill the customer's will to watch TV, way to go! On the other side I'll watch less TV and spend more time with other activities I guess.

Posted by Miha Markic | 2 Comments
Filed under: , , ,

DirectX HLSL compiler chokes on unicode sources

In a week or so I've created two HLSL effects in two different .fx files. While they were really simple and straightforward, one of them failed to load at runtime in my managed DirectX 3D application (yet both worked in NVidia FX Composer). Why would one fail while another is working? The error information was really non existent (i.e. "there was an error in the application" - DirectX, thanks so much for all of the details...). So I tried the fxc compiler that comes with DirectX SDK. The problematic effect didn't compile, of course. This time the error was more verbose but highly misleading:

ID3DXEffectCompiler: There were no techniques

The problem with this message was that I had a technique defined (remember, the thing was working in FX Composer). Hm. Google didn't help me at all. Then I went with my standard problem solving approach (SPSA) - eliminate pieces step by step (take a working sample and modify it slowly step by step to pinpoint the problem). Ok, so I copied the working effect content into non-working file opened in editor (I did copy&paste of the code, not the file). I tried fxc again and to my surprise it yelled the same error at me. What? How could it be? The content was the same. Perhaps I've drank too much coffee today? So I used KDiff3, a file comparison tool (free), to compare both files. On opening it warned me that while the content is the same the binary content isn't. This info finally triggered my brains - it has to be the unicode signature prefix. To be sure I fired yet another free utility, this time a hex editor called HxD. And there is was a hex prefix of EF BB BF meaning an UTF-8 encoded text. We live in an unicode universe for a bunch of years now and I guess fxc should work with non-ASCII files as well. Or at least it should complain that file isn't an ASCII one.

Posted by Miha Markic | (Comments Off)
Filed under: , ,

Twittering

I have obviously too much free time and thus started twittering. Here is my twitter profile.

Posted by Miha Markic | 2 Comments
Filed under:

Using extension methods to make code less cluttered

Here is an example where an extension method is useful. Take this LLBLGen Pro code for example:

public EntityCollection<CustomersEntity> GetCustomers() { using (DataAccessAdapter da = new DataAccessAdapter("Data Source=[SERVER];Initial Catalog=Northwind;Integrated Security=True")) { LinqMetaData context = new LinqMetaData(da); var q = from c in context.Customers select c; EntityCollection<CustomersEntity> result = ((ILLBLGenProQuery)q).Execute<EntityCollection<CustomersEntity>>(); return result; } }

It is a simple LINQ to LLBLGenPro select against (we all love) Northwind database. Pay attention at result assignment. To have data returned as a native LLBLGen Pro EntityCollection you have to resort to ILLBLGenProQuery interface. You have to use ILLBLGenProQuery.Execute method on IQueryable<T> q. A cast is obviously required because IQueryable<T> doesn't know anything about ILLBLGenProQuery. While this code works it is not exactly elegant - I am referring to the later cast of course.

So, the idea is to have something like this instead:

EntityCollection<CustomersEntity> result = q.Execute<EntityCollection<CustomersEntity>>();

Possible? Sure, just add this static class with a single extension method and you are good to go:

public static class Tubular { public static TResult Execute<TResult>(this IQueryable q) where TResult : IEntityCollection2 { return ((ILLBLGenProQuery)q).Execute<TResult>(); } }

Or perhaps, we can further reduce the cluttering by introducing this extension method:

public static class Tubular { public static EntityCollection<TEntity> Execute<TEntity>(this IQueryable q) where TEntity : EntityBase2, IEntity2 { return ((ILLBLGenProQuery)q).Execute<EntityCollection<TEntity>>(); } }

to achieve this, even less cluttered, line:

EntityCollection<CustomersEntity> result = q.Execute<CustomersEntity>();

Isn't this or former de-cluttered line more readable and more elegant than the original?

Posted by Miha Markic | 3 Comments

CodeRush Xpress is free

A stripped (more express) version of CodeRush, called CodeRush Xpress, is available for download at no charge! And even a bunch of refactorings are included. See the announcement or go to the product page directly.

Now you don't have any more excuses to avoid the very handy and useful CodeRush!

UPDATE: I missed the fact that it works only with C#. (thanks to pinkpanter)

Posted by Miha Markic | 2 Comments

Two computers, one scanner

I have an USB scanner I bought a while ago. It is attached to my computer and it is working fine. Occasionally my wife has to scan pictures for herself. She works on her computer but when she has to do some scanning I have to do the scanning for her even though she could scan the pictures by herself - if the scanner was attached to her computer. This sort of scanner doesn't know client-server mode, they work directly on the computer where they are attached. I don't mind scanning, but when you have work to do and 50 pages to scan it is an annoying process: feed the page, go through Acquire Image menu, save the result, etc.

One solution to the problem would be to manually switching scanner between the two computers. It isn't very pleasant to crawl under the desks, pinpointing the right cable (among tenths of others), detaching it from one computer and attaching it to the other. And the reverse when the other person requires the scanner. Not an option for me since I am not a hardware specialist, I am a software developer after all and I refuse to solve the problems with hardware manipulation :-)

Perhaps I could use an USB switch of some sort, but then again, this solution would increase the amount of (USB) cables and the switch would have to be in the reach to operate and it will consume a bit of power.

So I went with USB over Network solution that enables the client-server scenario for USB devices. And not only scanners, the work with all sort of USB devices. Their solution is actually a redirection of USB data flow to network computers and the other way round. A server application has to be installed on the machine (Windows and Linux are supported) where the USB device is attached. Once this server application runs you can decide which USB device to share. In my case I'll share the scanner:

USB over Network server, shared

(it states the name of the device before sharing: ScanJet bla bla)

Once the device is shared it isn't available anymore to the host computer - USB over Network Server takes command of it. On the host computer you can still use a shared device in two ways: either you un-share it or you do it like you'd do it on client computers - install USB over Network Client. Once client is installed you have to add server's address to the list of available servers. The thing communicates over port 33000 by default, so make sure your firewall lets the traffic through (you do have a firewall, right?). Once the connection with the server is established you are given the list of shared USB devices on that server. Just find the scanner, right click and select Attach.

USB over Network client

Server application shows that scanner is in now use:

image

That's it. The client computer now sees the scanner as attached to it and you can use it as such. Note: you'll need the device drivers installed on the client computer - remember, the client sees the device as attached to it. Actually, you need drivers installed only on computers where device is used, i.e. you won't need drivers on the server if you don't use the device there.

The drawback of this approach is the ownership of the device - only one client can own it at same time (you can specify whether new client can take possession of shared device even though somebody else is already using it).

Does it really work? With the version 3.4.6 I installed initially it didn't work when the host computer was running Vista. However it worked if I run VMWare Workstation with Windows XP as guest OS and routing scanner from host to guest OS and from there through USB over Network. It was a temporary hack and an experiment. I notified the Fabulatech support, they acknowledge the problem and fixed it in the current version 3.5.1. Now it works just fine. While this way of sharing USB devices isn't perfect it does elegantly solve issues when you want to share an USB device amongst many clients. It isn't free, the server part is licensed based on the amount of the device you want to share while the client is free.

Posted by Miha Markic | (Comments Off)
Filed under: ,

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):

image

Posted by Miha Markic | 3 Comments

Visual Studio, CodeRush and Silverlight 2

If your Visual Studio 2005 or 2008 freezes while creating a Silverlight project, or any other project then you might try switching off CodeRush add in. Yep, it causes Visual Studio to freeze when creating a shinny new Silverlight 2.0 application. I am sure that Developer Express folks will fix the problem very soon but for the time being just start Visual Studio, go to Tools\Add-in Manager... and uncheck DevExpress Tools item (I guess that will be a hard step to CodeRush addicted people, but don't worry, it is only temporal). You can run Silverlight project wizard now and you can re-enable CodeRush once the project is created.

The workaround and the fact that CodeRush is the culprit has been found in this thread.

Posted by Miha Markic | (Comments Off)
Filed under: ,

XNA Game Studio: I could play video but I'd rather not

Did you ever try to play a video inside your DirectX application, or a newer XNA Game Studio? One could assume that this is a trivial task, right? WPF lets you play it, heck, even Silverlight has no problems playing video - it is a matter of setting a bunch of properties on a proper object and voila.

So, XNA (same goes for DirectX) shouldn't have problem playing videos, too. WRONG. Playing video in XNA is a tricky, difficult and  you don't know when you'll get an unmanaged exception. Every solution out there I saw is based on DirectShow COM thing (luckily, there is a .net wrapper for DirectShow at http://directshownet.sourceforge.net/) like i.e. XNA DirectShow Video Player. But don't think this is an excellent solution. Dealing with video is still very problematic - while I haven't yet tried the mentioned video player I tried some other similar solutions and none of them is rock solid.

The logical question would be: why doesn't Microsoft support video playback in XNA natively (through whatever library as long as one doesn't have to deal with low level details)? Or better, playing video to texture would be more than enough. Didn't they think of it? Sure they did, there is even a very highly rated request at Connect. It is dated back to year 2006! After a week or two it has been marked as Closed - Postponed. That's it.

This issue begs for two questions:

  1. Is it really that difficult to add video to texture playback in XNA/DirectX?
  2. Why bother giving feedback to Connect at all?

I/We are not asking for some obscure feature after all. Having the video manipulation ability opens many interesting possibilities. Interestingly, video to texture playback was introduced with first versions of Managed DirectX library and soon after discarded, I guess because of bugs.

What gives? I guess we'll have to deal with that DirectShow directly in one way or another for a long time to come. Or pay a huge price to a 3rd party. Is there a third solution I am not aware of?

UPDATE [19.10.2008]: I just found Scurvy Media project on CodePlex that does play a subset of AVI video -> texture without messing with DirectShow. It looks quite promising. Perhaps the biggest drawback is lack of audio playback (not sure about this, looks like is roadmapped to next release).

Posted by Miha Markic | (Comments Off)
Filed under:

Minimum database permissions for using SqlDependency with SQL Server 2005

If you wonder what minimum permissions you need to use SqlDependency with SQL Server 2005 then look no further. This code project article definitely works and is the most complete one I've found. Note that setting minimum database permissions for notification isn't exactly the easiest task on the planet. Actually through experimenting I've managed to create a service_queue in sys.objects that I couldn't remove without restoring the database entirely (luckily I am using RedGate's SQL Backup 5 for backing up my databases - it makes the backup and restore process so easy, not to mention the encryption and compression capabilities).

Anyway, after restoring the database to the initial non-notification enabled point (clean state), I managed to apply proper minimum permissions following the mentioned article.

Posted by Miha Markic | (Comments Off)
Filed under: ,