Search code examples
c#enterprise-library

Enterprise Library issue - Switching web project from .Net 1.1 to 2.0


Recently we have decided to upgrade a website from 1.1 to 2.0. We used Visual Studio 2010 to upgrade and the upgrade worked fine.

The website used Enterprise Library 2005 and we have been having a hell of a time getting it to work. We would prefer not to upgrade Enterprise Library 2006 due to the major difference in the API.

The first thing we did to get the Enterprise Library to work was that we added this to the \Framework\v2.0.50727\Machine.Config

   <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
        <configSections>
            <section name="enterpriselibrary.configurationSettings" type="System.Configuration.IgnoreSectionHandler, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
        </configSections>
        <enterpriselibrary.configurationSettings xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" applicationName="X" xmlns="http://www.microsoft.com/practices/enterpriselibrary/08-31-2004/configuration">
            <configurationSections>
                <configurationSection xsi:type="ReadOnlyConfigurationSectionData" name="dataConfiguration" encrypt="false">
                    <storageProvider xsi:type="RegistryStorageProviderData" name="Registry Storage Provider" registryRoot="LocalMachine" registrySubKey="SOFTWARE\X" />
                    <dataTransformer xsi:type="XmlSerializerTransformerData" name="Xml Serializer Transformer">
                        <includeTypes />
                    </dataTransformer>
                </configurationSection>
                <configurationSection xsi:type="ReadOnlyConfigurationSectionData" name="securityCryptographyConfiguration" encrypt="false">
                    <storageProvider xsi:type="RegistryStorageProviderData" name="Registry Storage Provider" registryRoot="LocalMachine" registrySubKey="SOFTWARE\X" />
                    <dataTransformer xsi:type="XmlSerializerTransformerData" name="Xml Serializer Transformer">
                        <includeTypes />
                    </dataTransformer>
                </configurationSection>
            </configurationSections>
            <keyAlgorithmStorageProvider xsi:nil="true" />
            <includeTypes />
        </enterpriselibrary.configurationSettings>
    </configuration>

But everytime I call this function

Cryptographer.CompareHash( "X", X, X ) 

I get this error

System.InvalidCastException was unhandled
  Message=Specified cast is not valid.
  Source=Microsoft.Practices.EnterpriseLibrary.Configuration
  StackTrace:
       at Microsoft.Practices.EnterpriseLibrary.Configuration.Storage.ConfigurationChangedRegistryWatcher.Poller()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.runTryCode(Object userData)
       at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: 

I also get the same error when I try and call this function

DBCommandWrapper l_sqlWrapper = _db.GetStoredProcCommandWrapper("x");
l_sqlWrapper.AddInParameter("@x", DbType.Int32, "X");

I would like to add that this worked fine in 1.1 and ofcoruse I have checked to see that all values I pass in are not null and have legit value. Would anyone have a clue why?


Solution

  • Issue fixed.

    We fixed the issue by downloading the enterprise library and converting it to VS2010 under .Net 2.0. Then we did find/replace on #define VS2003 to #define VS2005B2.

    Then we added a reference to the project and everything worked.