Search This Blog

15 December 2010

Use Outlook as interface against Lotus Notes

During my work as consultant I often find myself in positions where I get a new mail from a customer during a project. Since I already have a couple of email addresses, at least one from my company and one private. I'm using Office Outlook to gather all these mail accounts in one place to avoid having to look through multiple places and get access to all my mails easy and fast.

With my latest customer I was required to get a Lotus Notes mail address and when looking over the web to find a method to use Outlook as interface with this mail too I started to think that this wasn't possbile without the use of DAMO (Domino Access for Microsoft Outlook) which is a program that IBM stands for that makes this possible.

I don't really fancy using an extra tool for making this possible and continues to look around and eventuelly I found a solution that is blatant obvious. All you need is to know that adress of your Domino server and your account information.

Add a new account and choose to create manually then select an internet mail account of type IMAP. Add the correct information with using your domino server as incomming and the correct server as outgoing. Your technicians should know what settings you need here.

After that leave all other settings as default and Voilá you can start using your outlook as interface against Lotus notes.


08 November 2010

Using reflection to obtain type information in runtime (C#)

Usually you know which type that you are working with but once in a while you only know what basetype you are working with but doesn't know what subtype you currently have.

During these times reflection is the way to go. Using reflection you are able to find out what type you are working with and create actions based on the fields, events and properties of the type.

I'll start with a short example to show the usage of reflection:

If you send information about events that happens by a webservice and these events are prone to change and it is possible that new events can be added too. If then the webservice usages is so that a presentation of theses events should be created you need to have some way to create a default view of the properties of the different events.

We have three classes defined, one base class and two classes that inherites from this one and defines some properties of themself.

public abstract class MyBaseObject 
   public string Message;
   public string Felmeddelande;

public class MyDateTimeObject : MyBaseObject
   public DateTime StartTime { get; set; }

public class MyOccurenceObject : MyBaseObject
   public int NumberOfTimes{ get; set; }
   public string[] Values { get; set; }
   public string[] Headers { get; set; }

If we now have a method that accepts a parameter of MyBaseObject and want to create functionallity of examining the content of the object we can do as follows:

public class ObjectInspector
   public static InspectObject(MyBaseObject obj)
      var typ = obj.GetType();
      var fields = typ.GetFields();
      var properties = typ.GetProperties();

      foreach(var field in fields)
         Console.WriteLine(string.Format("{0} : {1}", field.Name, field.GetValue(obj));      

      foreach(var prop in properties)
           Console.WriteLine(string.Format("{0} : {1}", prop.Name, prop.GetValue(obj, null));      

A warning, ifyou are to use GetValue of properties then you need to make sure that the method CanRead returns true. This method examines the accessor methods for the different properties and makes sure that the property is readable. Likewise the method CanWrite returns information is the property have a setter.

More information about this can be found in these two articles:

15 September 2010

Avoding hardcoded propertynames in C# .NET

Using strings that denote the name of fields and properties of objects in code are always a bad thing. The reasons are many, its hard to refactor code that contains hardcoded strings with properties names here and there in the code and its easy to make a typo and write some of the property wrong.

Wouldn't it be better if it was possible to avoid this and gather the property from the object directly instead and thereby avoid having to make the typo in the first place?

Luckily this is quite possible with a bit of functionallity added into the project. The below code picks out the name of the property or field of and object and returns the string name for this item. I got this idé from David Morgantini blogpost

public static string GetFieldName<TObject>(Expression<Func<TObject, Object> exp)
     return Regex.Match(exp.ToString(), @"\.(.*)")
               .Groups[1].Value.TrimEnd(new[] { ')' });

The code can be used as this

GetFieldName<Book>(b => b.Title)

This will give the string "Title" which can be presumed to be a property of an object named Book.

A more informativ place to use this code is when using NHibernates criteria API which can be cluttered by string constants.

public IList<Book> GetBooksByAuthor(string author)
    return Session.CreateCriteria(typeof(Book))
             .Add(Restrictions.Eq("Author", author)

Can instead be written as

public IList<Book> GetBooksByAuthor(string author)
    return Session.CreateCriteria(typeof(Book))
             .Add(Restrictions.Eq(GetFieldName(b =>
                                              b.Author), author)

Hopefully this can help you out with getting more managed code which is easier to maintain in a good state.

27 August 2010

Productivity Power Tools for Visual Studio

Began using Power Tools just recently and already I'm finding that I depend on this tool more and more. handling large solutions with many files and where people conduct refactoring on a daily basis.

Is much easier to get a good organisation if you are able to overlook what you have changed without having to search all around for changes that have been made. Another good thing with this tool is that its relativitly lightweight.

Last but not least this tool helps you out when files and classes are being written with different styles with regards to tab or spaces for example.

13 August 2010

Cold not load type '...' from assembly '...' during builds on different targets

A hard to track down error occured during my current project that required several hours of work before finally getting solved by a very simple solution so I feel I should give some information about my problem and the solution found to save others from doing the same work.

The problem is that we are using multiple build configurations with substitution files for Test, Development and Production environment.When building for some environment and then switching configuraton and adding some classes, or when other classes are checked in, in some circumstances a problem will occur when different assemblies cannot not be found.

The thing that makes this even harder to figure out is the fact that while using MS Test to run the test the tests will fail but if you enter debug mode the tests will pass without any problems.

The solution is to make a clean of the entire solution not just the current configuration, either by switching between the configurations and cleaning or running a batch build and cleaning all different configurations and cleaning them up and rebuilding.

The reason while this is happening is that some files cannot be deleted for some reason and the build actually fails to rebuild the assemblies needed.

11 August 2010

Mocking of objects

When testing an application that interacts with other external systems or that access a database you need some handling for this to make this work correctly.

Either you need some test versions of the systems and setup the database similar as the production database which is cubersome and lot of work to make each test work. A slight change in the object model would require that the tests also are changed.

A better method is to use some mocking framework to simulate that certain calls are being made and check that this really happens in the test. There exists several such mocking frameworks that have different advantages and disadvantages.

In the projects I'm currently working with we use a mocking framework developed by Mikael Waltersson which is called Simple Mock. This mock framework is as the name specifies very simple to use but don't be fooled the easy of use doesn't imply that the mock framework lacks functionallity, instead it has the functionallity that is required for a mock framework.

Try it, the time you spend learning how to setup the framework for your project will be earn quick enough once you start writing more and more tests.

Link to the development page on codeproject:


05 July 2010

HTTP could not register URL http ....

Almost everytime you switch computer while in a project you encounters one or more problemes since you miss things that you haven't though of. I of course ran into such problems but the good thing about these problems is that they are farily easily solved.

I howevered also ran into a problem that was much harder to understand why it suddenly appared. When I was attempting to run my tests that uses locally created servicehosts any test that created such a service failed with some version of the error message below.

HTTP could not register URL http://+:8000/. Your process does not have access rights to
this namespace (see for details).

The reason for this is apparent but the solution isn't. Since I'm not running as the Administrator when debugging in Visual Studio, the service fails to start when I run it because if missing privileges. To make sure that you have the rights to setup these servicepath you need to add them using the command shell tool netsh.

One other solution for this problem is to run Visual Studio in administrator mode.

More information about how this can be done can be found in the excellent blog.

14 May 2010

Mounting network drives

How many time shave you mounted a network drive, supplied the "correct" identifications and then detected that you made an error and then needs to reboot the computer just to "get ride" of the connection to the network drive that isn't working?

I grew tired of this and looked for another way to handled this since it takes far to much time to reboot just because you made a slight error.

Open a command prompt and type the command NET USE you will see a list of connected network drivers. This command is quite good a adressing problems with net work drives. You can change the logged in user by typing NET USE / USER: or remove the connection by typing  NET USE /delete.

Hopefully this helps some out there so you lose less time dealing with this problem.

Initializations during test cases

In any larger project a complex test suite should be built, a test suite that when run through should cover most of the code that handles buisness logic, aggregations and such. Presentations aren't always that important even if it is good to include those parts in the tests too,When the tests starts to increase they will take longer and longer to complete which will impact on the performance of the developers since these have to wait for tests to complete during verficiations of changes.

There are several methods for dealing with this one is the use of a common initializations class that setup the basic structure and adds basic data needed for the tests. The problem with this approach is that if you need to add some new data or change data in the setup you will have a huge impact on the tests and maybe changing a few that  should have given indications on a problem that has been introduced. Its often better to separate the tests and let each test setup the data required for just that test and clean up afterwards. If using a database the setup and teardown of the database could be a common setup that is run first in the testclass and teardown occured at the end after all tests. In such an instance you need a way to clean out the database without tearing it down compleatly.

Of course these are just my thoughts and there a several methods in dealing with this. One that we often use is the use of mocking of objects since you then don't need a real database just the apperance of one. from the systems point of view. This makes that test much much more efficient and faster but has the drawback that you aren't really testing the database which also needs to be done.

I any circumstance test ARE important and you should never feel that a test is useless and remove them if you aren't compleatly and absolutly sure since there is often a very good reason for that the test was created in the first place.

Happy testing!

12 March 2010

Language pack and Windows 7 Professional

If you are using a version of Windows 7 that haven't gotten integrated user control of how to install language packs you need to do some manual work to get it working.

First of all you need the file for you language of choice, can be found in the language pack ISO file on MSDN and possible also in other places on the net.

Once you have the language file follow these few steps and you can have you Windows version in the language of your choice.

* Start a command windows with administror rights
* Type: DISM /Online /Add-Package /PackagePath:
* Type bcdedit /set {current} locale
* Type bcdboot %WinDir% /l
* Start a register editor with administator rights
* Locate HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Control/MUI/UILanguages
* Delete en-us
* Restart computer and you have your own selected language

Example to add swedish to Windows 7
DISM /Online /Add-Package /PackagePath C:\
bcdedit /set {current} locale sv-se
bcdboot %WinDir% /l sv-se

15 February 2010

Nhibernate and mapping Enums

When using NHibernate one has to be careful in certain circumstances to avoid small errors that may have a huge impact. In one area an "error" might be hidden for a long time without anybody noticing it and everything working as it should. 

As soon as you create a mapping file with properties that are explicitly given types your should be aware what you are doing. If you for instance create a mapping file where you map a bit column and specify that the type for this column is Int32 and then in the mapping class define this property as an Enum you might be getting into problems. 

Since the class that is used for the mapping in the project might differ from the actual values in the database NHibernate will have problems understanding that nothing really has changed.

For example if you have the following in your mapping file, maybe for mapping up a user and specify gender for the user.
<property name="Gender" not-null="true" type="Int32" />

And the following class defined: 

public class Person
     public enum GenderEnum
        Male = 0,
     public GenderEnum Gender;

Once you load this element into memory the property Gender will be tranformed from being an Int32 value in the database to a GenderEnum type in the project. Later on when you either want to unload this object or load another object of the same type or any operation on the object that might trigger an update event for NHibernate such an event will indead be triggered, regardless if you have changed any values or not. The reason for this is that NHibernate detects a change of in the object, the property that is mappped as being Int32 in the database is now returned as an Enum. 

To fix this problem remove the type declaration in the mapping file and let NHibernate resolve the type itself.

A more extensive information about this problem can be found in the following links:

Reading of text files

In more or less every medium sized or bigger project there will be a need for reading text files sooner or later. Most of the time the text files will be quite good organized either as fixed post files or separated file (comma, tab and newline being the most common separator).

If the file is of type fixed post file one of the best method is to match the file structure into a class structure in the program and read line by line an instance of such an object. This supports multiple instances of subsections for elements and such too. Serializing the file becomes quite easy and goes farily smooth and if there is some error in the filecontent it will propagate and show early instead of being hidden away. Also it is possible to store information from the file in a database farily easy with this approch since a direct mappping to a database structure is possible. If you are using NHibernate (or Hibernate for Java) it is even possible to create a mapping file where the underlying class is the same for the database as for the textfile. One more advantage is the possibility to create automatic tests for the objects use to verify that the business rules are followed in the application.

With a file that is using some sort of separators to differentiate between the different post many times the easies way is to read up the entire file (or row by row) and run a split over the separators and then parse each element into a underlying object that holds the structure of the file. Using this approch measn its easy to detect errors in length of each element in the file as well as each field for each element. This also means that if the file becomes corrupt or changed in the future (not uncommon) this will be detected and can be handled correctly.

When it omes to have to actually read the text from the files it differes from project to project as well as from language to language but most of the times some simple loop expression is easy enough to use and quite effective at the same time. Don't complicate things, keep it easy and you will earn stability and readability of the source code.

09 February 2010

MSN and AVG antivirus setting

I'm using the free version of AVG antivirus ( at home and recently had to setup my computer again, reinstallation problems. When I sat up MSN i saw that my settings for virus scanning didn't work. Regarless to say I wanted to have a antivirus scan of files that arrives and searched the internet for solutions.

There is some parameters for AVG scanner that SHOULD work but to really get it to workw ith msn you need to make some extra handling, otherwise it will just say that scan completed but if you look at the logs no files have been scanned.

To make it so that AVG really scans incomming files you need to create a batchfile that is run instead of the pure exeutable. Don't ask me why!

The looks of the batch file should be as follows:

@echo off
"\avgscan?.exe" /SCAN=%1 /HEUR /ARC /PUP /CLEAN

where you either use avgscanx.exe or avgscana.exe depending on if you are using 32 or 64-bit version of the program.

Below is a more extensive presentation of this and the source of where I found this information.

05 February 2010

Test driven development

During software development one must take actions to ensure that the software contains as few errors as possible, no software will be completely error free. There are several paths to consider and they all have their advantages and disadvantages.

There are people that argue for not using testing at all since it costs to much and gives to few advantages, I for one think this is as stupid as standing on the freeway and hiding your head in the ground just hoping that there won't be any cars comming your way. At the minimum there should at least be some basic testing done before releasing a software. Either some of the users should perform test or some sort of automatic test should be written.

Unit testing is a very good method for minimising the errors within a single unit. The hard part with unit testing is to make sure that the test really are UNIT test and not integrations test. Only direct calls to an object should be tested in a single test and no dependencies of other objects implementation should be required. If one begin to couple objects and the test depends on other objects you aren't anymore using Unit testing. The reason for makeing sure that the objects only depends on themself in a test is that by doing this one can make it much easier to maintain a good test suite.

Integrations testing on the other side is a good method for making sure that all components in the project works as designed even if changes are made in the underlying code. These test should match the business cases detected to make sure that no errors are introduced into the code. It often here you need to remake the tests when a bug is detected to make sure that the test catches the bug and also can give a clear information that the bug has been removed and fixed.

User tests are a good way to detect errors in communication since the users will be the most capable persons to make sure that the application behaves and functions as it should. It can be hard to make sure that these tests really are performed.

Automatic GUI testing is good but often time consuming and hard to write so they cover all possible events and possibilities in the application. Needless its a good idé to creates such tests, especilly if there isn't any real users test in the system.

04 February 2010

Util programs and plugins to make work easier

Many of the programs that are default on a computer are inadecvat for a software developer since they are lacking in functionallity or otherwise have some limitations. I have been using many different tools to make my everyday work situation easier and more fun.

With this post I wanted to share my view of some of these programs and give you a reason why you should check them out. Since I'm a software developer with focus on .NET I'm using Visual Studio and as a IDE the environment is fairly good and one of the best things about VS is the ability register plugins, record macros and customize the look and feel of the IDE. Whenever I have the need to reinstall Visual Studio I always have some plugins athat I really need to add to the IDE before I can use the IDE to my full potential:

DPack ( A very valuable tool that help to track down methods, classes and files within the solution in an easy and quick way.

ReSharper ( One of the most know tools for Visual Studio and recognized as being well worth the money. There is also the possibility to download Nightly Builds which are free to use for 30-days and at the end of the trial period you may download a new build and reset the time limit.

WinMerge ( Not strictly a plugin for Visual Studio but a great tool in its own too. I have set it up to use for comparing files when using source control and need to resolve conflicts since Visual Studios own tool isn't near as good.

WebAii ( More of a thrid party tool than a plugin for Visual Studio. If you ever need to create complex GUI tests for you software be sure to check out this little goodie. Sure it takes a while to understand at the start but it really makes it a lot easier to make sure that nothing has been broken during the last build.

Other programs that I use to make my work situation easier and more fun that aren't integrated into Visual Studio.

soapUI ( Great tool for using beside Visual Studio to examine and create small test applications for either your own webservices or external webservices that you are using in your solution.

Notepad++ ( Sure there are several text editors out there and we all find our own favorite. One of the reasons why I like Notepad++ is the multitude of plugins created and suits more or less any task needed for text files. Also Notepad++ gives information that a current open file have been changed on disc which is invaluable during control of logging.

These are just a little bit of all tools that I use in my everyday job, we all find tools that we use either just to make it easier to create or maintain applications and perform our job.

03 February 2010

Reason for this blog

As I have now work with software development for a couple of years and often have searched for solutions on various problems during projects and found more or less good answers to my question I decided that I should at least give something back.

This blog will contain post related to development and problems and solutions with software as well as different approches to solutions in different circumstances. Most of the posts will be in english but there will probably even be posts in swedish.

If there is somebody out there that has any questions or problems which I might be able to answer don't hesitate to contact me and I'll see if there is something that I might be able to answer.