Sunday, October 23, 2016

How to make Node.js Unit tests discoverable in Visual Studio

Today I have stumbled onto an interesting problem: I had unit tests for my Node.JS project in Project A, but after I have moved the file (simple drag&drop in Visual Studio) to Project B, the unit tests were no longer showing up in the Test Explorer window.

There were no "build" errors, nothing, Visual Studio just wasn't discovering them anymore.

So and it has turned out that after the Drag&Drop operation one of the file properties was not preserved: TestFramework. In my case I just had to set it to ExportRunner.

Changing that did the trick :)

Friday, May 13, 2016

Web API Attribute Routing - not as attribute-driven as one would expect

This is a short, but rather important note: when you call MapHttpAttributeRoutes() to configure routing based on attributes, Web API engine looks only for classes which name ends with *Controller.
This seems to be a carryover from convention-based routing, and it is rather unexpected that it is still there.
But if you are like me, and WebAPI came into your world just now, you would not really have that habit of naming all controllers like that, especially in the test project.

Summary: Always follow this pattern for WebAPI controller names: {Name}Controller

And inherit from ApiController, but that's obvious.

Monday, October 12, 2015

Loose hood lock on my old QX4

This post is definitely not about IT.

As almost everybody else in US I own a car. It's an old SUV - QX4. Being on visa does not let you to earn more to keep more, so I have to spend less to keep more :) And so I fix my own car.

Anyway, this particular model is known to have one common problem - loose front hood lock. In many forums you can find the problem described as "hood rattle". I've seen a lot of forum posts about this problem, but I never actually thought that I have this problem as well.

About a week ago I noticed that my hood...shakes. Nothing crazy, but it really did not feel like it was dead on where it was supposed to be. It was definitely a bit loose. And I bet that it was like that for all the previous year!

So after a very easy fix (undo 3 bolts, push the lock down as much as possible, level the lock, tighten the bolts) I took a car for a test drive and I was shocked. All the explainable rattle, muffled clanking on speed bumps and bunch of other symptoms are gone ! I was always blaming the suspension, mounts and any piece that has rubber in it, and all this time the problem was in a front hood lock.... Crazy!

Friday, October 9, 2015

Why does my PC refuse to fall asleep?

I have a Windows 8.1 machine, and it would not sleep no matter what.

The display would turn off, but it just never wanted to go into the Standby mode.

Long investigation revealed two issues:

  1. The common one - media streaming + the homegroup issue (this one is easy to google).
  2. My soundcard driver was keeping the PC awake using SetThreadExecutionState API.
If you are only looking for the first one, you can use powercfg.exe /requests, and look for any requests on the SYSTEM level. You can actually override such requests and if it is the only problem, then it will go away.

The other one can only be detected by running the powercfg.exe /energy command. It generates a report which includes information about everything that Windows knows about Just run that, read the report, read through everything in the Error section. Any problem related to preventing windows from sleeping has to be addressed. In my case I had to install a proper driver instead of a default one.

Btw, a side note on the first issue. In my cases tweaking media sharing settings or the homegroup settings did not actually help. The following this was still showing up in the report from powercfg /requests: "\FileSystem\srvnet"

At the end the solution was quite simple: stop and disable Homegroup Listener and Homegroup Provider services (I do not us the homegroup) and a service called "Windows Media Player Network Sharing Service". That was it, the request for staying awake was gone.

UPDATE: It has turned out that after the restart the sound card driver is still preventing my PC from sleeping. There are two applications that can be blamed for that: Steam and UPlay. Both have some well-known bugs that do not release the sound card resources, and that prevents the PC from entering the Sleep mode. So either have to close the apps, or press the sleep button manually. Eventually I will look into some brute force way of overriding this behavior - I would rather have my PC go to sleep when unattended than not go to sleep unless I remember to press the button...

Monday, July 13, 2015

Signing ClickOnce WPF application

So let's say you have a WPF application that you want to distribute using ClickOnce. Like I am doing with my Visual Task Map.

If you want your users to download and run your application without going through multiple scary red dialog windows with warnings, you need to sing it.

A lot of information on this topic is scattered all over the web. Microsoft has a good set of articles about it. There are bunch of answered questions on Stack Overflow. But sometimes you just want the short version. So here it is.


  1. To sing any code you need to buy a code signing certificate
  2. Update project settings to sign and timestamp the ClickOnce manifest.
  3. Add a BeforePublish target into your project to sign the executable before it becomes part of the ClickOnce package.
I am using Comodo timestamping server - http://timestamp.comodoca.com/authenticode, but there are plenty of other servers to chose from. For example you can use this one: http://timestamp.verisign.com/scripts/timstamp.dll. It does not make any difference, any timestamping server will work.

Signing the manifest is simple as you just go o the project properties, Signing tab, and use your certificate (the one that you just bought, the one that has the private key) to sign the manifest. That is also where you can specify the timestamping server that will be used to timestamp the manifest.

You might also assume that signing the executable is as easy as signing the manifest because there is one more checkbox in the same dialog that says "Sign the assembly". You would be wrong. This is where you provide a certificate, used to create a Strong Name for your assembly, and your awesome new certificate won't work. Also, you don;t actually care about the strong-naming your executable. This is a good article about the difference between what VS does and what you need.

So how do you sing the executable ? There are no easy project options that will allow you to do that. And when you are dealing with ClickOnce, it all becomes a bit more complicated as ClickOnce sources binaries from the Obj folder, not the usual Bin folder, and the executable in the Obj folder has to be signed precisely at the right time: after it was actually built, but before the ClickOnce publishing mechanism has picked it up.

You can read more details about this here, and then here.
But the short version is that you need to add a call to singtool.exe into your project file. Something like this:
<Target Name="BeforePublish" Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
  <Exec Command=""C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\signtool.exe" sign /n "My Name" /t http://timestamp.comodoca.com/authenticode $(ProjectDir)obj\$(ConfigurationName)\$(TargetFileName)" />
</Target>

One important thing to remember is that the BeforePublish action works incorrectly with WPF applications in VS2013 RTM (and AfterCompile option did not work for me either). But this problem has been resolved in VS2013 Update 4 - be sure to install it.

Where to get a code signing certificate

Recently I wanted to sign some code and I had to find and buy a certificate for that purpose.

Short version of the story: I got this one. It was frustrating and cheap. Had to notarize a personal statement, provide a photocopy of driver license, credit card and a utility bill. Also had to publish all my personal contact info on manta.com.

Now, the long version.

First of all, not all certificates are equal - it has to be a code signing certificate (or at least it has to include that capability).

But the majority of code signing certificates are the same. I found an interesting article on this topic.

I compared VeriSign, Thawte, Comodo, K-Software and StartSSL.

First two are crazy expensive and can/should only be used by enterprises that have extra money, so I decided to ignore them from the very beginning. Prices are above 300$

Comodo and K-Software are both selling same certificates (issues by Comodo), but K-Software offers them at lower price. This is the option that I ended up going with.

The last one is StartSSL. The price is very low (59$ for 2 years for the individual certificate). But they do not support time stamping, which means that once your certificate expires your code is no longer signed. (So all of sudden your users start getting errors and warnings and would be forced to contact support or just download the latest version).

About the actual process. K-Software side of the deal is very straightforward and it is very nice dealing with their support. Really nice and helpful.

But once you start to deal with the Comodo side of the deal, it feels like some parallel universe where nothing makes sense. From my conversations it looks like all of their staff is in India and their call center is in India. Those guys are trying their best to work with you, but they still fail.

To get a certificate you have to be authenticated as future owner of the certificate. This means that you will be asked to provide a government-issued photo ID (Driver License), a document that ties you to your home address (for example, a utility bill), and a document that ties you to a financial institution. (Credit card or bank statement). They ask you to fill in an notarize a personal statement about you being you and living where you said you are. This was easy, as any UPS store has a notary in it and it costs around 10$ to notarize that one statement.

The email from Comodo says that you must mail the papers overnight to them - that's extra 50-60$ right there. But a quick call to their support has revealed that it is not necessary - just scan the papers and submit online.

The most frustrating part about that process is that they must find your phone number online in one of the public databases, like www.whitepages.com or www.manta.com. If you own a company, then it's not a big deal - the phone number and the address of  your company are both public. But when you are an individual software engineer you do not want your contact information in the public directories.

Unfortunately there was no way to work around this requirement - I had to publish my info on manta.com, they took a phone number from there, a machine called me on that number and gave me some verification code.

After that you get your certificate. It will be installed straight into the certificate store on your machine, so don't be surprised when the final page just says "Success" and nothing else happens. Just export the certificate from the certificates store and you'll have your file.

Tuesday, November 4, 2014

Missing Code Map in VS2013

So today I have decided to upgrade my VS2012 to VS2013 at home. Luckily, I had an Ultimate Edition laying around, so I could get access to all the goodness that Microsoft has for it's fans and followers.

Right after installing the VS2013 I opened my solution, and started exploring new features. At some point I realized that none of the buttons that were referring to the Code Map feature did anything. No errors, no messages, no other actions in response to my clicks on those menu items.

I googled a bit, but I could not find any useful information. So I started thinking, and in a minute I realized that I have not been asked for the license key yet and that might be somehow related, as this feature is only available in Ultimate edition and so developers probably have tons of checks all over the place to ensure that user has the right to use that feature.

So I went into Help->About->Product License Information and registered a product.

Ta-daam, the Code Map works now just fine. This made my day a bit better.

Wednesday, October 8, 2014

Sooo...I am kind of into pictures now, so I'll be posting some from time to time

Thursday, September 16, 2010

Popcorn Hour and Windows 7

To watch any video on my TV I use networked media tank (NMT) called Popcorn Hour. It does not make any sound (I did not install HDD in it) and it can access any shared resource across the network.

But recently I faced one serious problem - I upgraded to Windows 7 on one of my PCs (which btw have the largest storage space in my apartment) and I was not able to connect to it with my NMT. So I started to look for solutions.

Turned out that this problem is widely known and discussed, but usually it is solved somehow...easier than in my case, so I think that edition of Windows 7 matters in this case. (in my case it's Windows 7 Ultimate Edition)

After some investigation turned out that the exact solution for my problem is to disable this setting in Local security policy: "Restrict anonymous access to Named Pipes and Shares"

To do that you should go to "Control Panel/Administrative Tools/Local Security Policy/Local Policies/Security Options/Network Access: Restrict anonymous access to Named Pipes and Shares" and set it to Disabled.

Warning: Changing that setting could compromise security of your PC, so if your PC is not inside some private home network, than you should not do that change.

Also if you still cannot access your PC from NMT (or any other linux-based device), then probably this will help: http://anime.aoselectronics.com/wordpress/how-to-access-windows-7-shares-from-network_181/

Sunday, September 12, 2010

Ignore previous post about WPF

If you read my previous post, than you probably know that I no longer work on WPF.

But right now that is not true anymore. First of all I do huge amount of work on Silverlight, and it's quite close to WPF.
Also I work on several projects on my own when I have some spare time. Actually I do not have any spare time so I do all the work instead of having a decent sleep or any kind of rest. But soon you will be able to see result of my work - I am going to get the product to the market in a month or two and those who read this blog will get the application for free or almost for free :) I'll give it some more thinking.

Also I would like to mention that Silverlight is much worse than WPF in any way - performance for the end user sucks as much as possible performance of developer :)

Monday, March 9, 2009

No more WPF for me

Several months ago I changed my job, so now I am not involved in WPF development any more (at least at working hours - at home I used WPF to create one usefull utility - eMule Link Submitter ).
But now I do some other funny staff, like creation of reports using SQL Server Reporting Services (SSRS) and SQL Server Analysis Services. And I do not like that. No, I do like the result of my work, and I do like SSRS itself - it is really a greate product created by some really smart guys from Microsoft, but I really hate the process of creation of reports, like when you add 0.005 inches and look to preview to see whether that change was enough, and whether you report still fits one page and does not split into two.
Also I do not like Dundas Charts for SSRS, and here is my reason:
Dundas Charts are rendered as bitmap using GDI+ and that means that you will get the same DPI on screen and on printer, and you will have to set it manually (dispite the lack of features, standard chart looks much better).
Also there are some things, that I just don't get - some coordinates are in percents, some of them are in inches, some settings just do not work as expected, text is blurry and so on.
But still, Dundas did a lot of work for us and we do not have to create our own buggy charts :)

Later I will write more about all that stuff, but that will be in one of my next posts, and now I will get to sleep :)

Thursday, November 6, 2008

WPF Windows in WinForms project

Sometimes we need to add WPF windows to the Windows Forms project in Visual Studio. But, from all the WPF items,  Visual Studio allows to create only UserControl.
So I can think of two possible solutions here: a) we can create a custom item template for Visual Studio, or b) we can think something out of the UserControl.
If we do not need to create WPF windows on a constart rate, the second approach can be used.
So, we create new WPF UserControl and than replace UserControl with Window in both xaml and cs  files - in this way we get a WPF window in a WinForms project :)

Wednesday, July 23, 2008

WPF experience - different stages

It seems to me that the experience could be split into several different stages when you work with WPF.

1. You are amazed: You type xml tags and something shows up! Cool! And those animations - ultra cool!!!

2. Trying to develop...a lot...gain experience....and still happy :)

3. You begin to understand how things work, you learn what the ItemsControl is from inside, you understand how to implement the application in a "correct" way and know how are you expected to use the framework in a right way. Now you are a bit disappointed because of the limitations - the WPF does not handle everything...

4. You implement something that is....incompatible with WPF. WPF is not as great as before, or you even start hating it.

5. You understand all benefits and limitations of WPF and start using its best parts and omit bad parts. You finally recall what the development is about (some think that it is about the usage of a technology and not about making the product). Life becomes better :)

6. You are really happy with what you are doing; you make the product and do not worry about the technology limitations.

7. You are ready to move to the next technology to be able to mix them in future.

Seems that I am currently on stage 6 and WPF is really great when you need GUI :) 

Monday, July 21, 2008

GET, POST and fetching HTTP with HttpWebRequest

Once upon a time there was a HttpWebRequest.  He tried to GET some HTML from YouTube to feed his web browser. HttpWebRequest had default settings and only the URL was unique, so YouTube said - Go request yourself, Bad Request 400!

I have done some basic investigation and found out that usually it is important to provide the Referrer field. So when I added that field  (request.Referrer = url;) - the request worked fine for the moment...

But later I decided that I would like to POST some data to the site...I set the request method to POST (request.Method = "POST";), set content type to "multipart/form-data", specified multipart boundary and updated ContentLength (request.ContentLength = xxx;). I opened the request stream (request.GetRequestStream();) and started writing POST form data to it (and calling stream.Flush() from time to time).

After I sent the request I needed the response, so I called request.GetResponse() and read out all data from the stream it returned. (BTW - do not forget to close streams :) )

I noticed that the data is not correct, or at least some part of it is missing (the one at the beginning), so I proceeded with the investigation.

I found out that the header Expect is set to 100-continue, and the web site was against that approach. So I needed to turn it off - I used such setting : request.ServicePoint.Expect100Continue = false;

Usually I also set the UserAgent field and Accept field.

Thursday, June 5, 2008

Two names of a single element

It turned out that one element in WPF can have two (or even more!) names. For example you create UserControl, and add it to the Window. Like that:

<Window>
    <MyControl Name="Control1"/>
</Window>

And inside the control (I mean the XAML file that defines the control) you make a Binding to the control itself, so you need to specify the ElementName. Like that:

<MyControl Name="Root">
    <TextBlock Text="{Binding Path=Property1, ElementName=Root}"/>
</MyControl>

So, as you can see, MyControl element has two different names at the same time: Control1 and Root. But how is it possible? The answer will be like following: Different name scopes (I mean NameScope class that implements INameScope interface).

So how did we get two different name scopes for a single element? The secret is that when the UserControl is defined in XAML, and it's XAML definition is loaded, new name scope is created for the control automatically, and all names, that are set inside the control's XAML file or inside its visual tree, goes to its own name scope. And the name, defined in a window definition (like Control1 ), is registered in a windows name scope.

So that is all the magic you need :)

Monday, May 26, 2008

How do I provide custom collection view for collection in WPF?

Some time ago, while "surfing" the WindowsBase.dll with Reflector, I have found one interesting interface: ICollectionViewFactory.
I made some digging, and found out that there are folks that are interested what is this interface doing (along with some other interesting interfaces...)
MSDN says nothing about this interface, but it turned out that it could be quite useful in fact.
Here is how it is declared:

/// An interface that enables implementing collections to create a view to their data. Normally, user code does not call methods on this interface.
public interface ICollectionViewFactory
{
/// Creates a new view on the collection that implements this interface. Typically, user code does not call this method.
/// The newly created view.
ICollectionView CreateView();
}

It turned out that when you try to create a default collection view for the collection(or when you provide your collection as an items source for the ItemsControl), databinding engine checks whether your collection implements ICollectionViewFactory interface, and if it does - your CreateView() method is called, so in case you want to implement some specific logic, like optimized grouping, or specific filtering - you just implement your own collection view and return it in CreateView() method.

Tuesday, May 20, 2008

My level in XAML :)

Several hours ago The Moth (seems to be Daniel in real life) have posted an article on the levels of XAML understanding.

The proposed leveling is as following:
Level 100 – truly understand all of the above.
Level 200 – confidently read XAML (e.g. as spat out by VS2008 or Blend).
Level 300 – be able to type XAML yourself with an aim to create a structure of a bland GUI (setting basic properties and hooking events etc).
Level 400 – create styles, templates, animations and set gradient colours by hand.

I think, that everyone, who created at least one custom control for WPF (well, I mean something that could be sold), have already achieved the XAML competency level 400 :) At least most of my coworkers did and so did I. I even think that there should be one more level - 500, like God-Like...I do not think that I have achieved such level but it seems that I am somewhere between 400 and 500.

Level 500 means that you definitely know how to implement something in code that could be used correctly in XAML :) Also such level includes knowing how every tag and attribute in XAML works (like the problem with focus scopes, when you should know from the beginning that moving element to the new focus scope will change the behavior of standard WPF controls).

But any way - now we have some kind of competency levels for XAML writers :) Great!

Sunday, May 18, 2008

Post2Blog - Windows client for Blogger, or blogging outside the IE

Recently I have decided that I do not like to make posts in my blog using it’s web-interface, so I have decided to find some windows client for Blogger engine. I have done some search and found a post about the Post2Blog software, so now I am writing this post using that program, and also I am thinking on how can I make money on something like that :-) BTW - funny notice - at the time when a guy wrote his post about this staff, it costed about $40, and now it is free. If I were him, I would be a bit upset now :-)


Post2Blog is really cool application - it supports a variety of blogging engines (Blogger and WorldPress for example), it supports automatic images upload (I do not think that I will use that feature, but still - it is there for free :-)), and finally - it is FREE.


There is one thing that seems to be missing - Blog2Post is all about posting to the blog and not managing the blog, so the access to the recent posts is a bit confusive...but still - great staff, wonder could it be abandoned and became free...

Friday, April 25, 2008

Great resource for SEO-beginners

Hm... recently I have googled into one veeeery usefull (for SEOs) post
I found that blog while I was searching for the ways to trackback my own posts from other blog-engines so that I could see the list of the links to my posts...

Thursday, April 24, 2008

XAML+LoadComponent VS pure code - where are my name scopes???

Recently my coworker faced one interesting problem. He was looking through the sample for the Josh's article on 3D in WPF, and said that he had noticed one strange thing - whenever you try to replace the loading of the Viewport3D from XAML with in-code creation, you get an exception in RegisterName methods, saying that there is no name scope for the provided element.
So, what is the difference between loading XAML and creating element from code? I made a short research using the greatest tool in a .NET world, Reflector, and it turned out that in case when XamlReader (or, to be more specific, BamlRecordReader) meets some element, that does not support INameScope interface, it creates the namescope itself, and attaches it to the element (NameScope.SetNameScope(dependencyObject, new NameScope());).
Finally, to resolve the issue with an exception, we have manually created the NameScope and attached it to the viewport.
Also, XamlReader calls BeginInit and EndInit methods whenewer the loaded element supports ISupportInitialize interface. So you should remember to use that too when you create visual element in code.