Oracle Managed Connection抛出'OracleInternal.Common.ProviderConfig异常的类型初始值设定项

时间:2018-05-10 13:45:44

标签: c# oracle asp.net-web-api owin managed

当尝试从OWIN独立的web api应用程序创建连接时,oracle.manageddataaccess.client会引发异常。

return new OracleConnection( 
                    new OracleConnectionStringBuilder()
                    {
                        DataSource = _server,
                        Pooling = _poolEnabled,
                        MinPoolSize = _minPoolSize,
                        MaxPoolSize = _maxPoolSize,
                        UserID = _username,
                        Password = _password,
                        ConnectionTimeout = _timeout
                    }.ToString()
                );

代码段在OWIN应用程序之外工作。但是当在owin上下文中调用它会抛出异常类型初始化器或'OracleInternal.Common.ProviderConfig'引发异常,并且程序集中的'Microsoft.Owin.OwinContext'未标记为可序列化。

详细例外如下,

System.TypeInitializationException was unhandled by user code
  HResult=-2146233036
  Message=The type initializer for 'OracleInternal.Common.ProviderConfig' threw an exception.
  Source=Oracle.ManagedDataAccess
  TypeName=OracleInternal.Common.ProviderConfig
  StackTrace:
       at Oracle.ManagedDataAccess.Client.OracleConnectionStringBuilder..ctor()
       at XYZ.Habitat.Data.DSXReader.OracleDSXConfig.ConjureConnection() in c:\__work\MIS2\XYZ.Habitat\Data\DSXReader.cs:line 168
       at XYZ.Habitat.Data.DSXReader.get_ConnectionString(String index) in c:\__work\MIS2\XYZ.Habitat\Data\DSXReader.cs:line 235
       at XYZ.Habitat.Kernel.CreateDbConnection(String key) in c:\__work\MIS2\XYZ.Habitat\Kernel.cs:line 202
       at XYZ.REF.Controllers.RefController.List(String id) in c:\__work\MIS2\XYZ.REF\Controllers\RefController.cs:line 66
       at lambda_method(Closure , Object , Object[] )
       at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass6_1.<GetExecutor>b__3(Object instance, Object[] methodParameters)
       at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments)
       at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)
  InnerException: System.Configuration.ConfigurationErrorsException
       HResult=-2146232062
       Message=An error occurred creating the configuration section handler for oracle.manageddataaccess.client: Type 'Microsoft.Owin.OwinContext' in assembly 'Microsoft.Owin, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' is not marked as serializable. (c:\__work\mis2\__build\Debug\XYZ.MIS2.TEST.dll.config line 46)
       Source=System.Configuration
       BareMessage=An error occurred creating the configuration section handler for oracle.manageddataaccess.client: Type 'Microsoft.Owin.OwinContext' in assembly 'Microsoft.Owin, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' is not marked as serializable.
       Filename=c:\__work\mis2\__build\Debug\XYZ.MIS2.TEST.dll.config
       Line=46
       StackTrace:
            at System.Configuration.BaseConfigurationRecord.EvaluateOne(String[] keys, SectionInput input, Boolean isTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult)
            at System.Configuration.BaseConfigurationRecord.Evaluate(FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult, Boolean getLkg, Boolean getRuntimeObject, Object& result, Object& resultRuntimeObject)
            at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
            at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
            at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
            at System.Configuration.BaseConfigurationRecord.GetSection(String configKey)
            at System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(String sectionName)
            at System.Configuration.ConfigurationManager.GetSection(String sectionName)
            at OracleInternal.Common.CustomConfigFileReader.ParseAndCacheConfigParams()
            at OracleInternal.Common.CustomConfigFileReader.ParseConfigFile()
            at OracleInternal.Common.ConfigBaseClass.GetInstance(Boolean bIsManaged)
            at OracleInternal.Common.ProviderConfig..cctor()
       InnerException: System.Runtime.Serialization.SerializationException
            HResult=-2146233076
            Message=Type 'Microsoft.Owin.OwinContext' in assembly 'Microsoft.Owin, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' is not marked as serializable.
            Source=mscorlib
            StackTrace:
                 at System.AppDomain.get_Evidence()
                 at System.AppDomain.get_EvidenceNoDemand()
                 at System.AppDomain.get_Evidence()
                 at System.Configuration.ClientConfigPaths.GetEvidenceInfo(AppDomain appDomain, String exePath, String& typeName)
                 at System.Configuration.ClientConfigPaths.GetTypeAndHashSuffix(AppDomain appDomain, String exePath)
                 at System.Configuration.ClientConfigPaths..ctor(String exePath, Boolean includeUserConfig)
                 at System.Configuration.ClientConfigPaths.GetPaths(String exePath, Boolean includeUserConfig)
                 at System.Configuration.ClientConfigurationHost.RequireCompleteInit(IInternalConfigRecord record)
                 at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
                 at System.Configuration.BaseConfigurationRecord.GetSection(String configKey)
                 at System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(String sectionName)
                 at System.Configuration.ConfigurationManager.GetSection(String sectionName)
                 at System.Xml.XmlConfiguration.XmlReaderSection.get_ProhibitDefaultUrlResolver()
                 at System.Xml.Schema.Parser..ctor(SchemaType schemaType, XmlNameTable nameTable, SchemaNames schemaNames, ValidationEventHandler eventHandler)
                 at System.Xml.Schema.XmlSchemaSet.ParseSchema(String targetNamespace, XmlReader reader)
                 at System.Xml.Schema.XmlSchemaSet.Add(String targetNamespace, XmlReader schemaDocument)
                 at OracleInternal.Common.CustomConfigFileReader.ValidateBaseDocument(XmlDocument doc)
                 at OracleInternal.Common.ODPMSectionHandler.DeserializeElement(XmlReader reader, Boolean serializeCollectionKey)
                 at System.Configuration.ConfigurationSection.DeserializeSection(XmlReader reader)
                 at System.Configuration.RuntimeConfigurationRecord.RuntimeConfigurationFactory.CreateSectionImpl(RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentConfig, ConfigXmlReader reader)
                 at System.Configuration.RuntimeConfigurationRecord.RuntimeConfigurationFactory.CreateSectionWithRestrictedPermissions(RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentConfig, ConfigXmlReader reader)
                 at System.Configuration.RuntimeConfigurationRecord.CreateSection(Boolean inputIsTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentConfig, ConfigXmlReader reader)
                 at System.Configuration.BaseConfigurationRecord.CallCreateSection(Boolean inputIsTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentConfig, ConfigXmlReader reader, String filename, Int32 line)
            InnerException: 

1 个答案:

答案 0 :(得分:1)

我遇到了同样的错误“ OracleInternal.Common.ProviderConfig的类型初始化器抛出异常”。

运行应用程序时,在控制台错误消息中,“定义了重复的'oracle.manageddataaccess.client'部分。”

找出Oracle.ManagedDataAccess的定义是在我的WebAPI web.config和机器配置中。

必须更新此特定machine.config:C:\ Windows \ Microsoft.NET \ Framework64 \ v4.0.30319 \ Config \ machine.config-在“托管”上进行搜索并在3个地方注释掉。