Friday, June 10, 2011

.NET code problem on Windows Server 2003 solved

I spent several hours hunting down a problem a customer had with JTB FlexReport on Windows Server 2003 SP2. The solution was in the end a single row. Things worked fine on Windows XP, Windows Vista, Windows Server 2008, Windows Server 2008 SP2  and Windows 7, but for some reason it failed on Windows Server 2003.

In the code I narrowed down that this call failed but I could not figure out why:

Database db = DatabaseFactory.CreateDatabase();

I got this error using Microsoft Enterprise Library 2.0:

Object reference not set to an instance of an object.

I was wondering if it had to do with the Enterprise Library version but I got this error using Microsoft Enterprise Library 5.0:

Activation error occured while trying to get instance of type Database, key ""

I then wondered if the problem was that I had one .exe made by VB.NET and a DLL made by C#, or that it was running as a Windows Service, or that some code had been upgraded all the way from VB6 etc.

Eventually I was able to scale away a copy of my program to just a few rows and still had the problem. Then I created a similar program from scratch and got it running. I could then start to compare the two file by file using DiffMerge and eventually I was able to find that in app.manifest I had to add the following:

<assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>

just before <trustInfo

Now that I found the solution I looked up more details and found that reading any configuration settings from the applications .config file is not working. I also found that it actually is due to a bug in Windows Server 2003. Calls to System.Configuration.ConfigurationManager.AppSettings return null. In Windows Server 2003, if the application has the following SxS manifest, then CLR will not use the application config file even if it exists. This bug does not exist in Windows XP, Windows Vista or Windows 7. Application config file is not used if the application has certain SxS manifest and Lesson Learned: Missing language attribute in ‘assemblyidentity’ element can cause SxS (SideBySide) application loading failure on Windows XP and Server 2003

No comments:

Post a Comment