最近我们决定将网站从 1.1 升级到 2.0。我们使用 Visual Studio 2010 进行升级,升级工作正常。
该网站使用 Enterprise Library 2005,我们一直在努力让它工作。由于 API 的主要差异,我们不希望升级 Enterprise Library 2006。
为了让 Enterprise Library 工作,我们做的第一件事就是将它添加到 \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>
但是每次我调用这个函数
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 并且具有合法值。有人知道为什么吗?