It’s end of January 2012 by now, but I decided to share some stats on what was going on with this blog in 2011. If you fancy reading my stuff (is there anybody?
) you might find it interesting.
Let’s get down to the business:
- only 3 posts that year
busy? lazy? …?
- nevertheless, I was observing constant interest growth (more and more vistst, by Google Analytics):
- 196,717 Visits (+45% comparing to 2010)
- 178,770 Unique Visitors (+46% comparing to 2010)
- 222,258 Pageviews (+42% comparing to 2010)
- most popular post: C#, decimal.toString(), and how to get rid of trailing zeros – 17,302 pageviews
What if you need to undelete a file or bunch of files that at some point have been deleted from TFS? Naive option would be to get the content of the file, copy it, create a new file, and paste the copied content to just created file. Of course, this is not a good option because history of changes to the file(s) will be lost.
Continue reading ‘Visual Studio TFS: How to undelete file(s)’
Published on
January 9, 2012 in
.net and c#.
Tags: .net, c#.
How to get service name listening at specific port in C#? What you have as input is only two pieces of information: host name and the port number the service is listening at.
Solution
Apparently, .NET does not provide such feature so one needs to stretch a bit to get the answer. What I can suggest (I’m far from saying it’s good approach, though) is to get the name in two steps:
- Use
netstat -a -o and parse the output (ouch!) to get ID of the process (PID) that is listening at given port number
- Perform a WMI call to get the name of the service:
SELECT Name FROM Win32_Service where ProcessId = PID
Following this will give you what you want, but to be honest any time I need to parse output to get some information I feel anxious… This is the first place in the code where errors can be introduced.
If there is/are better/safer way(s) to retrieve service name having the host name and port it’s listening at, please share it.
If you have never used RockScroll you are probably most comfortable with standard scrollbar Visual Studio offers. I guarantee you, however, that the moment you install RockScroll and work with it for a while, you will miss it a lot if you switch to Visual Studio that’s not extended with it. I’ve experienced that many times when kneeled at a teammate’s desk trying to help him move on with their task. This is probably best moment when you will realize that Visual Studio misses a thing without RockScroll
Here are most important pros that make me think RockScroll is must-have plugin for Visual Studio:
Continue reading ‘Visual Studio: Improved navigation through the files with RockScroll’
Published on
December 10, 2011 in
c++.
Tags: c++.
What is the outcome of the simple program below?
#include <iostream>
#include <conio.h>
using namespace std;
class Base
{
public:
void DoSth(int tmp)
{
cout < < "Base::DoSth(int)\n";
}
void DoSth(char tmp)
{
cout << "Base::DoSth(char)\n";
}
};
class Derived : public Base
{
public:
void DoSth(int tmp)
{
cout << "Derived:DoSth(int)\n";
}
};
int main()
{
Derived d;
d.DoSth(5);
d.DoSth('c');
getch();
return 0;
}
Continue reading 'C++: Overriding methods – problem with hiding overloads in the base class'
One of the sessions I liked most on Microsoft Technology Summit 2011 was one delivered by Krzysztof Bińkowski – it was about certificates and PKI in context of Windows Server 2008. I’m not going to describe the session here, but wanted to share the tool that might help better understand the world of cryptography.
To better explain theory provided on his slides, Krzysztof used CrypTool. Let me cite the authors of this tool to give you a basic idea on what CrypTool is:
CrypTool is a free, open-source e-learning application, used worldwide in the implementation and analysis of cryptographic algorithms. It supports both contemporary teaching methods at schools and universities as well as awareness training for employees and civil servants.
Continue reading ‘CrypTool – understanding cryptography with examples’

I find this book relevant and very informative. If you want to master LINQ lingo, just read it.
For broader evaluation see my review on DZone.
P.S. DZone’s IT Book Zone is another great initiative. In short DZone gives you a free copy of a book and expects to receive its review in return. Fair agreement – one can stretch the envelope of IT domains for free, while DZone broadens thier public resources.
This was not an easy one… I was trying to run a unit test with MSTest but I was always getting the following error:
Unit Test Adapter threw exception: Type is not resolved for member ‘XXX,XXX Version=1.0.0.0, Culture=neutral, PublicKeyToken=null’
As usual in such case – a message which does not really say what’s wrong. I googled the problem but there was not much about it on the web. The best resource I found was post titled VSTS Unit Test ‘Type is not resolved’ exception. It describes how VSTestHost process runs the test and explains what the possible problem might be in this case.
The author suggests that data required for test (e.g. a dll file) is not found in base directory for AppDomain (i.e. unit test ‘Out’ directory) because it’s already switched back to directory that holds VSTestHost.exe. There are two links to MSDN given where Microsoft admits this is a known bug and provides a hack to work around the problem – supply VSTestHost with copies of required artifacts (again, this is described in details in above mentioned post).
Unfortunately that didn’t work with my case. I’ve found the root cause though…
Continue reading ‘MSTest: Unit Test Adapter threw exception: Type is not resolved for member XXX’
Published on
September 13, 2010 in
c#.
Tags: c#.
Microsoft recommends if you overload Equals method you should also overload GetHashCode. Now, how to properly implement GetHashCode? There are many resources on the web that describe it. A good starting point might be this article on Stack Overflow.
Following MSDN guidlines GetHashCode must fulfill these requirements:
- If two objects of the same type represent the same value, the hash function must return the same constant value for either object.
- For the best performance, a hash function must generate a random distribution for all input.
- The hash function must return exactly the same value regardless of any changes that are made to the object.
Sticking to first bullet, you (probably?) should consider the same fields in Equals and GetHashCode methods. Let’s have a look at the example in which I did so:
public class Contact
{
public int ID { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public override bool Equals(object obj)
{
// If parameter is null return false.
if (obj == null)
{
return false;
}
// If parameter cannot be cast to Contact return false.
Contact c = obj as Contact;
if c == null)
{
return false;
}
// Return true if the fields match:
return ID == c.ID
&& FirstName == c.FirstName
&& LastName == c.LastName;;
}
public override int GetHashCode()
{
return ID.GetHashCode()
+ FirstName.GetHashCode()
+ LastName.GetHashCode();
}
}
Now, what is wrong with this example of GetHashCode? There’s one drawback here. The hash is calculated as a sum of three integer values, which might give a value that is greater than int.MaxValue and that will result in OverflowException.
Continue reading ‘C#: GetHashCode() might cause OverflowException’
A few days ago I decided to add ‘Donate’ button on my blog (see the sidebar to the right). This is a feature provided by PayPal.
If you want to prove you are really delighted with my help or simply you have too much spare money
, it’s possible to pay me a kind of tip. That can be a dollar or two, that’s not really important; every little helps. All in all that could help pay for the hosting.
Of course I’m still blogging for fun so treat this as a feature – use it only if you really want to