Blog Image

Peter Nilsson's .Net Blog

About the Blog

- To share and learn.

Blog closed

General Posted on Thu, August 04, 2016 11:09:07

I have closed this blog and the new one can be found at www.peternilsson.me. Please go and visit it.



AutoMapper 5.0.2

General Posted on Fri, July 15, 2016 11:45:50

I’m
migrating my app from Silverlight to UWP. At the same time, I’m changing from
VS 2013 to VS 2015. It was a while since I worked with the app and noticed that
there where a new version of AutoMapper available in Nuget Package Manager, but
I couldn’t install it. I tried to find a solution on the Internet, but didn’t
find any. After several hours of struggling, I managed to install it after
removing the contents of both bin
and obj folders from all projects in
my solution. I tried several times to just remove from bin, but wasn’t enough.



Upgrade to NHibernate 3.0.0

NHibernate Posted on Thu, February 10, 2011 22:26:34

I recently upgraded to NHibernate 3.0.0. NHibernate 3.0.0 has a good backward compatible with version 2.1.2. It includes a new Linq provider that fully supports Linq. When upgrading to NHibernate 3.0.0 I stumble into the following issues:

· The new Linq provider is included in NHibernat 3.0.0 and I didn’t have to download it separately.

· The method session.Linq<T>() is replaced by session.Query<T>().

· The new Linq provider has full support for Linq and I had to update some Linq queries. For example, it manages eager load differently. It includes new methods, Fetch and FetchMany, to define what shall be fetched eagerly.

So, it was quite easy to upgrade and I didn’t have that much trouble. Still need to explore all new features and re-factor the code whenever possible to take advantage of them. First impression of NH 3.0.0 is very good.



IE crashes when opening document in Sharepoint

Misc Posted on Thu, October 07, 2010 22:00:15

For some reason my browser started to crash when I tried to open documents in Sharepoint. After some investigation I found out that I had multiple versions of an assembly called Owssupp.dll confusing IE. One version from Office 2003 and another from Office 2007. The later one was installed while evaluating Onenote 2007. I solved the problem by uninstalling Onenote 2007. I found a link that describes the problem http://geekswithblogs.net/redwards/archive/2007/06/18/113287.aspx. Additional information can be found here http://support.microsoft.com/kb/833714.



Exception has been thrown by the target of invocation

Visual Studio Team System Posted on Fri, August 20, 2010 18:42:33

I was leading a lab today. The first exercise has a starting solution with some basic code that you are suppose to enhance during the implementation. One of the very first thing you shall do is to run the unit tests to make sure that the code works. It has always worked! That is, until today. One of the participants couldn’t execute any of unit tests. Visual Studio kept on displaying the same error message for every attempt to run any of the unit tests: “Exception has been thrown by the target of invocation”.

We searched on the Internet and found many suggestions on what might cause the problem. Finally we found out that the reason was that his development environment wasn’t connected to TFS. The lab is of course checked into TFS and there is a bug in VS 2008 that causes this problem if you open a bounded solution in a studio disconnected from TFS (http://blogs.msdn.com/b/shitals/archive/2009/12/31/9942725.aspx).



Troubleshooting NHibernate

NHibernate Posted on Wed, July 07, 2010 22:45:56

There are many different ways to troubleshoot NHibernate. I mainly use show_sql, log4net and SQL Server Profile.

show_sql

In the configuration of NHibernate, there is a property called show_sql. If you set this to true, NHibernate will output all generated sql to the console.

You enable show_sql by adding the following piece of code to the configuration file.

<property name=”show_sql”>true</property>

To view the output from a unit test, you must select the unit test in the Test Result window and use View Test Result Details.

The unit test’s result window displays the output.

log4Net

If you need more detailed debug information you can use log4net. Log4Net is an open source library that NHibernate uses to log all interesting events. You can use it to log information to a file, the console or both. To use it, you have to add some information to the configuration file. First declare the log4net section.

<configSections>
<section name=”hibernate-configuration” type=”NHibernate.Cfg.ConfigurationSectionHandler, NHibernate” />
<section name=”log4net” type=”log4net.Config.Log4NetConfigurationSectionHandler, log4net”/>
</configSections>

Here is an example how you can configure log4net to write events from NHibernate both to a file and the console. Read more about log4net on the homepage.

<log4net>
<appender name=”NHibernateFileLog” type=”log4net.Appender.RollingFileAppender”>
<file value=”c:\nhibernate2.txt” />
<appendToFile value=”true” />
<rollingStyle value=”Size” />
<maxSizeRollBackups value=”10″ />
<maximumFileSize value=”100KB” />
<staticLogFileName value=”true” />
<layout type=”log4net.Layout.PatternLayout”>
<conversionPattern value=”%d{HH:mm:ss.fff} [%-5p] %c – %m%n” />
</layout>
</appender>
<appender name=”Console” type=”log4net.Appender.ConsoleAppender, log4net”>
<layout type=”log4net.Layout.PatternLayout,log4net”>
<param name=”ConversionPattern” value=”%d{ABSOLUTE} %-5p %c{1}:%L – %m%n” />
</layout>
</appender>
<root>
<level value=”DEBUG”/>
<appender-ref ref=”Console” />
</root>
<logger name=”NHibernate” additivity=”false”>
<level value=”DEBUG”/>
<appender-ref ref=”NHibernateFileLog”/>
<appender-ref ref=”Console” />
</logger>
</log4net>

You also have to initialize log4net from the application

//Start Log4Net
log4net.Config.XmlConfigurator.Configure();

The output now contains much more information about the internal works of NHibernate:

SQL Server Profiler

SQL Server Profiler can be very useful when you line step an application and want to view each database call NHiberante makes. In this way you can follow how NHibernate flushes changes to the database and manages caching. SQL Server Profiler can be started from SQL Server Management Studio.

To use it your user must be a member of sysadmin.

When the Profiler is started, you can create a new trace and view each database call NHibernate makes.



Slow Menus in VS 2010

Visual Studio Team System Posted on Sat, June 05, 2010 13:55:56

In one of my assignment they use VS 2010 and I recently had to install it. My first impression wasn’t very good. The menus in VS 2010 were extremely slow. Tried different settings in the environment but nothing helped. I looked if Google could give me any answer, and it could! It turned out that my computer was configured to use 16 bit colour quality. By increasing it to 32-bit, the problem went away.



Domain Driven Design

Misc Posted on Sun, May 23, 2010 22:07:56

I recently attended to a course that covered Domain Driven Design (DDD). After the course, I asked some of the attendees how they would summarize DDD in one sentence. There were a couple of interesting suggestions, and here is the one I think summarized DDD in the best way.

“A mindset based on object oriented principles to drive the understanding of the business context.”



Next »