EntLibConfig.exe

The Enterprise Libarary Configuration Tool
 

If you use Microsoft’s Enterprise Libraries at all then you may have seen this tool before…

I found this tool while doing some research on the Enterprise Library entries in an app.config file and realised it could be very useful for the application I was working on. My problem came when I tried loading the app.config file into the EntLibConfig.exe as it reported that one or more errors had occurred during the loading process. The errors I were getting appeared as "…The located assembly’s manifest definition does not match the assembly reference." at the bottom of the screen. The app.config file was valid as my application had been running without any issues.

My search for an answer took me to this page – http://blogs.msdn.com/tomholl/archive/2007/04/19/avoiding-configuration-pitfalls-with-incompatible-copies-of-enterprise-library.aspx – which explained that I was trying to load an app.config file referencing assemblies that were not signed. Taking a look at my entries in the app.config file for the Microsoft.Practices.EnterpriseLibrary  I found that all the PublicKeyToken values were null. Since the EntLibConfig.exe was using signed assemblies this was the reason for the errors.

My next task was to find out what the Public Key Token value was for the Enterprise Library assemblies. For that I used the Strong Name Utility (sn.exe). This link gave me some useful information about using SN.exe – http://blogs.msdn.com/miah/archive/2008/02/19/visual-studio-tip-get-public-key-token-for-a-stong-named-assembly.aspx

Having entered the correct Public Key Token values into the app.config my configuration file now loaded into the EntLibConfig.exe without any errors and I was able to do the necessary editing.

ForeignKeyReferenceAlreadyHasValueException

Updating a Foreign Key value using LINQ
 

Table A has a Foreign Key (integer) field that is referencing a Primary Key (integer) field in Table B. I wanted to be able to set the value of the integer in Table A to a new value using my entity object property for Table A. When I tried to set the value of the integer field I got a ForeignKeyReferenceAlreadyHasValueException and the message ‘Operation is not valid due to the current state of the object.’

The solution is not to try and set the integer value of the field but define the value for the whole entity. For example;

// Dont assign just the ID value

EntityName.ForeignKeyFieldID = myIntegerValue;

// Assign the entity

EntityName.ForeignKeyField = myEntity;