2
votes

oracle.manageddataaccess.client throws exception when try to create the connection from OWIN stand alone web api application.

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

The code snippets work outside OWIN app. But when called inside owin context it throws exception The type initializer or 'OracleInternal.Common.ProviderConfig' threw an exception, and 'Microsoft.Owin.OwinContext' in assembly is not marked as serializable.

The detailed exception is a follows,

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
did you find out the answer to this?darasd

1 Answers

2
votes

I got this same error "The type initializer for 'OracleInternal.Common.ProviderConfig' threw an exception".

When I ran my app, in my Console error messages, "There is a duplicate 'oracle.manageddataaccess.client' section defined."

Turns out the definition for Oracle.ManagedDataAccess was in my WebAPI web.config and also the machine config.

Had to update THIS specific machine.config: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\machine.config - do a search on "managed" and comment out in 3 places.