企业库问题 - 将 Web 项目从 .Net 1.1 切换到 2.0



最近我们决定将网站从 1.1 升级到 2.0。我们使用Visual Studio 2010进行升级,升级工作正常。

该网站使用Enterprise Library 2005,我们一直在努力让它工作。由于 API 的主要差异,我们不希望升级企业库 2006。

为了使企业库正常工作,我们做的第一件事是将其添加到\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="SOFTWAREX" />
                    <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="SOFTWAREX" />
                    <dataTransformer xsi:type="XmlSerializerTransformerData" name="Xml Serializer Transformer">
                        <includeTypes />
                    </dataTransformer>
                </configurationSection>
            </configurationSections>
            <keyAlgorithmStorageProvider xsi:nil="true" />
            <includeTypes />
        </enterpriselibrary.configurationSettings>
    </configuration>

但是每次我调用这个函数时

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

我收到此错误

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: 

当我尝试调用此函数时,我也会遇到相同的错误

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

我想补充一点,这在 1.1 中工作正常,我已经检查过我传入的所有值都不为 null 并且具有合法值。有人知道为什么吗?

.NET 2.0 明确不支持 Entlib 1.1。实际上,它不再受支持,但这是一个不同的问题。

.NET 1.1 和 .NET 2.0 之间存在大量差异。变化很大的一件事是配置系统。

我很幸运地用VS 2005编译entlib 1.1以获得2.0的目标版本,但那是很久以前的事了,我只做了简短的测试。

基本上,这里的规范答案是"切换到 entlib 2"。是的,改变了很多,但 1.1 的东西不再起作用了。

问题已修复。

我们通过下载企业库并将其转换为 .Net 2.0 下的 VS2010 来修复此问题。然后我们确实在VS2003 #define 找到/更换 #define VS2005B2。

然后我们添加了对项目的引用,一切正常。

最新更新