Vadim’s Weblog

Never stop learning.

Microsoft is offering free e-book featuring Virtualization.

Posted by Vadim on August 26, 2009

9780735693371[1] If you don’t mind to give Microsoft your e-mail (they probably already have it), you can get Understanding Microsoft Virtualization Solutions e-book for free.

This book is written by Mitch Tulloch, who wrote about two dozens of Windows related books.

Understanding Microsoft Virtualization Solutions covers Microsoft’s wide range of virtualization technologies.

Download your free copy!

Posted in Book | Leave a Comment »

Creating an “M” Project in VS 2010.

Posted by Vadim on June 1, 2009

When you install “Oslo”, installation also adds one “Oslo” template in your Visual Studio.  It’s “M” Project. 

oslo_vs_plug-in

However, if you try to create a new “M” Project or open an existing one you probably will get the following error:

This method uses CAS policy, which has been obsoleted by the .NET Framework.  In order to enable CAS policy for compatibility reasons, please use the legacyCasPolicy configuration switch. Please see http://go2.microsoft.com/fwlink/?LinkId=131738 for more information.

English is not my first language, as you probably already realized that by reading my blog, but I thought that word obsolete is an adjective.  In this Microsoft error message it’s used like a verb “obsoleted”.

Well, enough about English.  I’m sure that you can take any of my posts and have a lot of fun criticizing my English.  If you want to do so, please do.  Your criticism probably will improve my English.

Let’s get back to the error.  You can follow the link in the message to read more about Security Changes in the .NET Framework 4.  One of the thing you can find there is that Code Access Security (CAS) policy got replaced by Windows Software Restriction Policies (SRP).

Historically, the .NET Framework has provided code access security (CAS) policy as a mechanism to tightly control and configure the capabilities of managed code. Although CAS policy is powerful, it can be complicated and restrictive. Furthermore, CAS policy does not apply to native applications, so its security guarantees are limited. System administrators should look to operating system-level solutions such as Windows Software Restriction Policies (SRP) as a replacement for CAS policy, because SRP policies provide simple trust mechanisms that apply to both managed and native code. As a security policy solution, SRP is simpler and provides better security guarantees than CAS.

However, it doesn’t tell us how we can fix our problem.  After some research, I got across documentation about legacyCasPolicy Element.

Next I open devenv.exe.config file that is in C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE folder and added following line:

   1: <legacyCasPolicy enabled="true"/>

You should add this line inside <runtime> element.

M_proj_error 

I understand that “Oslo” and VS 2010 are both Beta products so far.  I’m sure that Microsoft will resolve this problem in future releases. 

I realize that this is not the best solution.  However, it worked for me.  Please let me know if you can find a better solution.

kick it on DotNetKicks.com

Posted in Oslo, VS2010 CTP | Tagged: | Leave a Comment »

New May 2009 CTP for Microsoft “Oslo” is out.

Posted by Vadim on May 29, 2009

Oslo_installIf you don’t know what “Oslo” is, it’s set of future Microsoft modeling technologies.  You can find out more at “Oslo” Developer Center.

In this release Microsoft finally is going to include “Quadrant”, a GUI tool for “Oslo”.

As for previous CTPs you need .NET Framework 3.5 SP1, SQL Server 2008, and VS 2008 or higher.  New install for “Oslo” allows to to customize the installation.  If you select “Install Now” instead of “Customize” option, all of “Oslo” is going to be installed.  It includes: “Quadrant, “Oslo” repository, and “Oslo” SDK.  You must to have administrator privileges in order to run installation.  You can find more details by reading Release Notes.

In case you have  a previous CTP installed on your machine, you must uninstall it before installing new CTP.  Also you must drops the ‘Repository’ from your SQL 2008 database. 

Microsoft also provides us with May CTP Samples.

After installing “Oslo” you can find template for “M” Project in your Visual Studio:

oslo_vs_plug-in

“Oslo” installation also is going to create Repository in your SQL 2008.

oslo_sql

kick it on DotNetKicks.com

Posted in Oslo | Tagged: | Leave a Comment »

Keywords as variables/identifiers. Why?

Posted by Vadim on May 13, 2009

I use words variable and identifier interchangeably.

Have you ever tried to use a keyword as a name of your variable?  Until recently I thought it was impossible.  However, C# and VB.NET allow developers to use keywords as variables.

string string = '' '';
Dim String As String = '' ''

If you try to compile this code, compiler will generate three errors:

  • Error    1    Identifier expected; ’string’ is a keyword
  • Error    2    Identifier expected
  • Error    3    Invalid expression term ’string’ 

To fix this error in C# you just prefix your variable with an @ character.  In VB.NET you surround the variable with square brackets [].  A variable or identifier with an @ prefix is called a verbatim identifier.

string @string = '' '';
Dim [String] As String = '' ''

Why anybody would use keywords as variables?  To me it looks like a very BAD practice.  Variables/identifiers must be descriptive.  Can you think of any keyword that would be descriptive enough to use in your code as a variable?

I found in C# specification why Microsoft includes verbatim identifier in their languages:

The prefix "@" enables the use of keywords as identifiers, which is useful when interfacing with other programming languages. The character @ is not actually part of the identifier, so the identifier might be seen in other languages as a normal identifier, without the prefix.

I still believe it’s a BAD idea.

I also understand that if today I don’t see any reason to use verbatim identifiers, tomorrow I might find a perfect application for it.

If you use it and have a good reason, please let me know.

kick it on DotNetKicks.com

Posted in .Net, C#, VB.NET | 5 Comments »

Shop-2009.com Spam

Posted by Vadim on May 10, 2009

Yesterday I received this email from my wife’s hotmail account:

Dear friend:

       how are you doing recently ? I would like to introduce you a very good company which i knew.They can offer you all kinds of electronical products which you need, such as motorcycles, laptops, mobile phones, digial cameras, TV LCD, xbox, ps3, gps, MP3/4, etc. Please take some time to have a look at it,there must be something you’d like to purchase.

the website:     shop-2009.com

Their Email:     shop09@188.com

Hope you have a good mood in shopping from their company!

Actually this spam was sent to everybody in her contacts.

I did let her know that someone got access to her hotmail account and urged her to change the hotmail password.

An hour later she told me that when she tries to sent an email the same text appears in all her messages.  After further investigation, it was obvious that the message was in her mail signature.

How to change your Live Hotmail signature.

What happen is that my wife logged on someone else computer that had a key logger, and her hotmail identity was stolen.  She is lucky that her password wasn’t change.

I took following steps to make sure that my wife’s account doesn’t have any foreign fingerprints left.  Please let me know if you think that I missed something.

  1. Changed Password.
  2. Changed the secure question and the secret answer.
  3. Made sure that there’s no alternate e-mail addresses that we don’t recognize.
  4. Made sure that there’s no mobile number and PIN we don’t recognize.
  5. Made sure that we recognize all emails in “Send and receive mail form other e-mail accounts section.
  6. Made sure that our “Vacation reply” wasn’t tempered.
  7. Removed tempered signature.
  8. Made sure that Reply-to address wasn’t tempered.

Posted in Security | 18 Comments »

Integrate FxCop 1.36 & VS 2008

Posted by Vadim on May 9, 2009

Update: Visual Studio Team System (VSTS) has Code Analysis feature.  It’s not FxCop but it does serve the same purpose and is built using the same engine as FxCop.  Unfortunately I’m working with VS Professional that doesn’t include Code Analysis.

FxCopI was looking for way to integrate FxCop 1.36 with Visual Studio   2008.  I even asked the same question on StackOverflow.  The only answer I got was a link to MSDN article.  I follow direction in the article but wasn’t successful.  I assume that if you have only one project and don’t have a solution it will work for you but it’s not my case.  I have many project in my solution.  However, the MSDN article got me going.  Let me present you my solution of integration.

Create FxCop project using FxCop GUI.

Important:
- Save the project file in the same directory where your solution is.
- Project name must be the file name of your solution (including .sln extension).  For example: If your solution file is MySolution.sln, the FxCop project name must be MySolution.sln.FxCop.

FxCop - Name project

Add FxCop to VS External Tools.

In Visual Studio select Tools->External Tools…  You should see the External Tools dialog box.

You must fill following fields:

Title: FxCop
Command: C:\Program Files\Microsoft FxCop 1.36\FxCopCmd.exe
Arguments: /c /p:"$(SolutionDir)\$(SolutionFileName).fxcop" /cXsl:"C:\Program Files\Microsoft FxCop 1.36\Xml\VSConsoleOutput.xsl"
Initial Directory: C:\Program Files\Microsoft FxCop 1.36
Use output window Must be checked

If you install FxCop in different location than C:\Program Files\Microsoft FxCop 1.36, you need to use your own path.

FxCop-ExternalTools

In case you want to grok the switches we use, you can read more about FxCopCmd options.

Run FxCop from Visual Studio.

We are done.  Now we just need to run FxCop.

Tools –> FxCop should analyze your code and because we checked “Use Output window” in External Tools dialog result should appear in VS output window.

FxCop - result

kick it on DotNetKicks.com

Posted in FxCop, VS2008, Visual Studio | 9 Comments »

Underfoot is not an Overhead.

Posted by Vadim on April 21, 2009

Jeff Brown is trying to coin a new term “Underfoot”.

You can use underfoot where you use overhead.  Here’s an example from Underfoot post:

Building this proposed multi-tier platform will have an initial 20% underfoot while we retool and lay the foundation.  Once that is done we will be 50% more efficient though we will have to spend an additional recurring 5% underfoot to keep the axles greased.

Overhead means expense; how much extra you pay to get something.
Underfoot means investment; how much you invest in order to get more of something.

I personally like “Underfoot”; however, it’s not a household term.  If you like it too, use it in your blogs and link to Jeff’s post.

I linked to it three times in this short article.

Posted in Software Engineering | Leave a Comment »

ReSharper 4.5 complains about my private fields.

Posted by Vadim on April 9, 2009

I just downloaded ReSharper 4.5.  I probably will blog more about my experience with it.

The first thing I noticed after upgrading to R# 4.5 is that I got a lot of complains (blue underlines) about my naming of non public fields. 

RS_privateFields

Like many developers I like to prefix my private variables with an underscore.  I know for the fact that I’m not alone that what Jeff Prosie says:

As a matter of personal preference, I typically prefix the names of private fields with an underscore (for example, _connection).  When I read the code back after a time away, this makes it obvious to me which fields are not intended for public consumption.  This conventions is used quite a lot in the .NET Framework – for example, in System.NET.HttpWebRequest and System.Web.HttpContext – but it is not used throughout.

Next thing I did is to check what controls this blue lines.  I went to ReSharper/Options/Naming Style.

RS_NamingStyle_Dialog

To satisfy my naming style I click on Edit button to open an Edit “Instance fields (non public)” Rule Settings… window and typed an underscore (_) in Name Prefix text box:

RS_privateFields_Fixed 

After modifying “Instance fields (not public)” rule, ReSharper will not complain when we  add underscore to our private, internal, and protected fields.  But what if we want this rule for private fields only.  Well, in this case we need to define our own rule.  Naming Style window has two list boxes, the second one (User defined naming rules) allows us to define our own rule.

RS_ExstendedNamingRule

kick it on DotNetKicks.com

Posted in ReSharper | Tagged: | 2 Comments »

Stub HttpContext

Posted by Vadim on March 23, 2009

Have you ever tried to TDD objects that use HttpContext, HttpResponse, or HttpRequest?  If you did, you probably created wrappers for these classes.  No more.  With .NET 3.5 Microsoft gave us System.Web.Abstractions.dll that extends System.Web namespace.  In this post I’d like to show an example how to stub HttpContext.

Here’s the system under test:

    public class MyContext
    {
        private readonly HttpContextBase _context;

        // This constructor is called by production system.
        public MyContext() : this(new HttpContextWrapper(HttpContext.Current))
        {}

        // Test calls this constructor
        public MyContext(HttpContextBase context)
        {
            _context = context;
        }

        public bool IsItemCached(string item)
        {
            return _context.Cache[item] != null;
        }
    }

Here are the unit tests:

    [TestFixture]
    public class MyContextTester
    {
        private HttpContextBase _contextStub;
        private MyContext _myContext;

        [SetUp]
        public void StartTest()
        {
            _contextStub = MockRepository.GenerateMock<HttpContextBase>();
            _myContext = new MyContext(_contextStub);
        }

        [Test]
        public void IsItemCached_if_Cache_item_is_null_return_false()
        {
            _contextStub.Stub(x => x.Cache).Return(HttpRuntime.Cache);
            Assert.IsFalse(_myContext.IsItemCached("NotThere"), "False is expected.");
        }

        [Test]
        public void IsItemCached_if_Cache_item_is_NOT_null_return_true()
        {
            HttpRuntime.Cache.Insert("I am HERE", "value");
            _contextStub.Stub(x => x.Cache).Return(HttpRuntime.Cache);
            Assert.IsTrue(_myContext.IsItemCached("I am HERE"), "True is expected.");
        }
    }

kick it on DotNetKicks.com

Posted in .Net, TDD | Tagged: , , , , , | 2 Comments »

Review of Roy Osherove’s review.

Posted by Vadim on March 20, 2009

I just finished watching video by Roy Osherove where he reviews Unit Tests for NetDinner MVC source code.

I liked the video and many points Roy makes are very valid.  However, let me concentrate on the things I didn’t like.

  1. During the video Roy complains how tired he is because it’s 2 AM and he has to record the video.  Who’s fault is that?  I’m as a viewer prefer for my presenter to be fresh and energetic.  Roy, I want to you to teach me, I don’t want to know that you’re tired and that your wife and the kid sleep in another room.
  2. Roy also criticize people who created a test with multiple asserts.  In that particular case the test method had two asserts.  I personally don’t see big problem to use more than one Assert as long as the test name describe what is tested.  He also gives viewers a doctor analogy which I fail to find appropriate.
  3. I was very surprised when after complaining about multiple asserts in a single unit test, Roy recommends using RowTest feature of MbUnit / NUnit.  Roy, how do you describe what is the difference between the first row and second row tests? About three years ago when I was a rookie in TDD world,  I switched to MbUnit from NUnit because of RowTest attribute.  NUnit didn’t have this feature at the time.  However, I stopped using RowTest in my unit tests because it’s not clear what is tested.  However, I still use this RowTests for my integration tests.
    Here are couple of reasons why I stopped using RotTest attribute in my unit tests.

    a. Let assume that you have a test that fails if a value is null or empty string.  Here’s an example:

    [Row(&quot;&quot;)]
    [Row(null)]
    public void UserName_property_should_faile_when_value_is_empty_or_null(string userName)
    

    The problem is that when one of row test fails, it’s hard to see which one failed.

    b. I use TestDriven.NET.  When you run Row tests, TestDriven.NET executes all the row tests. To execute only one row I had to comment out all the other rows.

    Instead of example above, I prefer to create two tests like this:

    [Test]
    public void UserName_property_should_faile_when_value_is_empty()
    
    [Test]
    public void UserName_property_should_faile_when_value_is_null()
    

Roy, no hard feelings.  I personally believe that you are doing a great job of educating people of better development practices.  I myself learned a lot from you.  Just don’t talk like Roy’s way is the only way.

Posted in TDD | 4 Comments »