Sunday, April 26, 2009

Second monitor preview

If you want to see what is on your second monitor (for example on your TV that is connected on your comp) you can use this application:

http://sites.google.com/site/mijalko/Home/second-monitor-preview

MSTest and TeamCity trouble

When I run test from Visual Studio all tests pass but when I setup test environment from Teamcity half of my test fails.

Problem was because some of assemblies was missing in mstest environment. Actually, I have used Enterprise library and I had custom trace listener. Test project had that trace listener in references. But when Teamcity runs mstest my assembly was missing in build agent working folder.

All assemblies that are not used directly in test (for example class from my assembly was dynamically loaded by enterprise library application logging block) will not be copied to test folder. Therefor, those test methods should be decorated with attribute like:


[DeploymentItem("MyTraceListener.dll")]


Somehow, this was not necessary when you run tests from Visuals Studio IDE.

I hope that I save you some time.

Wednesday, March 11, 2009

Hibernate (NHibernate) and Polymorphism

If you use lazy loading on base class, NHibernate will create proxy class of base class so you will not be able to use is operator to check type of object. For example:


abstract class Base
{
};

class A : Base
{
}

class B: Base
{
}

class C
{
public virtual Base BaseClass {get; set;}
}


If you now list all C objects from database and try to check of what type is C.BaseClass with

if (c.BaseClass is A)
{
}
else if (c.BaseClass is B)
{
}
else
{
//ERROR
}


you will get an error.

Simplest way to solve this problem is to add method in base class that will returns instance to itself:


abstract class Base
{
public virtual Base This()
{
return this;
}
};


Now, you can check:

if (c.BaseClass.This() is A)
{
}
else if (c.BaseClass.This() is B)
{
}

Tuesday, March 10, 2009

Firefox hangs

It happened to me that firefox won't shutdown. Also, when I choose to start new instance of firefox it fails.

I found that problem was in skype's addon for firefox . I uninstalled it (in firefox: Tools => Addon=> Extension) and everything works OK now.

Friday, February 20, 2009

Missing svc handler

Windows 2008 comes with installed .NET framework 3.5 but without installed IIS. When you install IIS you don't have support for WCF (there is no handler for svc). To install support for svc open command prompt and go to .net framework 3.0 location (:\Windows\Microsoft.NET\Framework\v3.0\Windows Communication Foundation\) and run:

servicemodelreg -i

Wednesday, February 04, 2009

An error occurred when verifying security for the message

One of the possible reasons:

- Check if the time on the server and the time on the client does not match.

Thursday, January 08, 2009

Resharper, Stylecop and type members layout

In order to resort type members layout to match requirements of StyleCop using ReSharper open ReSharper's settings, choose "Type Members Layout" and paste following XML:


<Patterns xmlns="urn:shemas-jetbrains-com:member-reordering-patterns">


 


  <!--Do not reorder COM interfaces-->


  <Pattern>


    <Match>


      <And Weight="100">


        <Kind Is="interface"/>


        <HasAttribute CLRName="System.Runtime.InteropServices.InterfaceTypeAttribute"/>


      </And>


    </Match>


  </Pattern>


 


  <!--Special formatting of NUnit test fixture-->


  <Pattern RemoveAllRegions="true">


    <Match>


      <And Weight="100">


        <Kind Is="class"/>


        <HasAttribute CLRName="NUnit.Framework.TestFixtureAttribute" Inherit="true"/>


      </And>


    </Match>


 


    <!--Setup/Teardow-->


    <Entry>


      <Match>


        <And>


          <Kind Is="method"/>


          <Or>


            <HasAttribute CLRName="NUnit.Framework.SetUpAttribute" Inherit="true"/>


            <HasAttribute CLRName="NUnit.Framework.TearDownAttribute" Inherit="true"/>


            <HasAttribute CLRName="NUnit.Framework.FixtureSetUpAttribute" Inherit="true"/>


            <HasAttribute CLRName="NUnit.Framework.FixtureTearDownAttribute" Inherit="true"/>


          </Or>


        </And>


      </Match>


    </Entry>


 


    <!--All other members-->


    <Entry/>


 


    <!--Test methods-->


    <Entry>


      <Match>


        <And Weight="100">


          <Kind Is="method"/>


          <HasAttribute CLRName="NUnit.Framework.TestAttribute" Inherit="false"/>


        </And>


      </Match>


      <Sort>


        <Name/>


      </Sort>


    </Entry>


  </Pattern>


 


  <!--Default pattern-->


  <Pattern RemoveAllRegions="true">


 


    <!--Delegates-->


    <Entry>


      <Match>


        <And Weight="100">


          <Access Is="public"/>


          <Kind Is="delegate"/>


        </And>


      </Match>


      <Sort>


        <Access Order="public internal protected-internal protected private" />


        <Name/>


      </Sort>


    </Entry>


 


    <!--Fields and constants-->


    <Entry>


      <Match>


        <Or>


          <Kind Is="field"/>


          <Kind Is="constant"/>


        </Or>


      </Match>


      <Sort>


        <Access Order="public internal protected-internal protected private" />


        <Kind Order="constant"/>


        <Readonly/>


        <Static/>


        <Name/>


      </Sort>


    </Entry>


 


    <!--Enums-->


    <Entry>


      <Match>


        <Kind Is="enum"/>


      </Match>


      <Sort>


        <Access Order="public internal protected-internal protected private" />


        <Name/>


      </Sort>


    </Entry>


 


    <!--Constructors. Place static one first-->


    <Entry>


      <Match>


        <Kind Is="constructor"/>


      </Match>


      <Sort>


        <Static/>


        <Access Order="public internal protected-internal protected private" />


      </Sort>


    </Entry>


 


    <!--Destructors. Place static one first-->


    <Entry>


      <Match>


        <Kind Is="destructor"/>


      </Match>


      <Sort>


        <Static/>


        <Access Order="public internal protected-internal protected private" />


      </Sort>


    </Entry>


 


    <!-- Events -->


    <Entry>


      <Match>


        <Kind Is="event"/>


      </Match>


      <Sort>


        <Access Order="public internal protected-internal protected private" />


        <Name/>


      </Sort>


    </Entry>


 


    <!--Properties-->


    <Entry>


      <Match>


        <And>


          <Kind Is="property"/>


          <Not>


            <Kind Is="indexer"/>


          </Not>


        </And>


      </Match>


      <Sort>


        <Access Order="public internal protected-internal protected private" />


        <Static/>


        <Abstract/>


        <Virtual/>


        <Override/>


        <Name/>


      </Sort>


    </Entry>


 


    <!--Indexers-->


    <Entry>


      <Match>


        <Kind Is="indexer"/>


      </Match>


      <Sort>


        <Access Order="public internal protected-internal protected private" />


        <Static/>


        <Abstract/>


        <Virtual/>


        <Override/>


        <Name/>


      </Sort>


    </Entry>


 


    <!--Methods-->


    <Entry>


      <Match>


        <And>


          <Or>


            <Kind Is="method"/>


            <Kind Is="operator"/>


            <HandlesEvent />


          </Or>


          <Not>


            <Kind Is="destructor"/>


          </Not>


        </And>


      </Match>


      <Sort>


        <Access Order="public internal protected-internal protected private" />


        <Static/>


        <Abstract/>


        <Virtual/>


        <Override/>


        <Name/>


      </Sort>


    </Entry>


 


    <!--all other members-->


    <Entry/>


 


    <!--nested types-->


    <Entry>


      <Match>


        <Kind Is="type"/>


      </Match>


      <Sort>


        <Access Order="public internal protected-internal protected private" />


        <Static/>


        <Abstract/>


        <Virtual/>


        <Override/>


        <Name/>


      </Sort>


    </Entry>


  </Pattern>




Now, choose Cleanup Code.

( tnx to Jordan Dimitrov)

Monday, December 29, 2008

Add file header

To add C# file header according to StyleCop's SA1633 you can use this macro:



Sub AddFileHeader()


        DTE.ActiveDocument.Selection.StartOfDocument()


        DTE.ActiveDocument.Selection.Text = "//-----------------------------------------------------------------------"


        DTE.ActiveDocument.Selection.NewLine()


        DTE.ActiveDocument.Selection.Text = "// <copyright file=""" + DTE.ActiveDocument.Name() + """ company=""MyCompany d.o.o."">"


        DTE.ActiveDocument.Selection.NewLine()


        DTE.ActiveDocument.Selection.Text = "//    Copyright (c) MyCompany d.o.o. All rights reserved."


        DTE.ActiveDocument.Selection.NewLine()


        DTE.ActiveDocument.Selection.Text = "// </copyright>"


        DTE.ActiveDocument.Selection.NewLine()


        DTE.ActiveDocument.Selection.Text = "//-----------------------------------------------------------------------"


        DTE.ActiveDocument.Selection.NewLine(2)


    End Sub


Friday, December 26, 2008

Visual Studio - Create Blank Solution

If you want first to create blank solution in Visual Studio on specific location and then to add existing projects or create new one you will be very disappoint if you expect to find "Create Blank Solution" item under the New menu.
To create blank solution do the following:
  1. On the File menu, select New and then click Project.

  2. In the Project types pane, select Other Project Types and then select Visual Studio Solutions.

  3. In the Templates pane, select Blank Solution.

Thursday, December 18, 2008

Visual studio test environment and provide additional files

If you want, for example, to copy additional files to test location for some unit test, for example, some XML file, do the following:
  1. Add test.xml to test project
  2. Set "Copy to output directory" property of file to "Copy always"
  3. For test method add [DeploymentItem("test.xml")] attribute.