Could not load file or assembly 'Oracle.ManagedDataAccess' - c#

we are developing a windows service which connect to oracle database. We use
Oracle ManagedDataAccess from Nuget package.
When running the windows service we are receving below error. Tried to get details from stackoverflows and nothing is able to resolve the problem.
Our config file is as below
Could not load file or assembly 'Oracle.ManagedDataAccess,
Version=4.122.19.1, Culture=neutral, PublicKeyToken=89b483f429c47342'
or one of its dependencies
Config
<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="eClaimsService.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
<section name="oracle.manageddataaccess.client"
type="OracleInternal.Common.ODPMSectionHandler, Oracle.ManagedDataAccess, Version=4.122.19.1, Culture=neutral, PublicKeyToken=89b483f429c47342"/>
</sectionGroup>
</configSections>
<system.data>
<DbProviderFactories>
<remove invariant="Oracle.ManagedDataAccess.Client"/>
<add name="ODP.NET, Managed Driver" invariant="Oracle.ManagedDataAccess.Client" description="Oracle Data Provider for .NET, Managed Driver"
type="Oracle.ManagedDataAccess.Client.OracleClientFactory, Oracle.ManagedDataAccess, Version=4.122.19.1, Culture=neutral, PublicKeyToken=89b483f429c47342"/>
</DbProviderFactories>
</system.data>
<system.web>
<httpRuntime executionTimeout="3600" requestValidationMode="2.0" maxRequestLength="10240"/>
<sessionState mode="InProc" timeout="60"/>
<pages validateRequest="false" />
</system.web>
</configuration>

In my case just go to Visual Studio 20xx Developer Command Prompt and open as Administrator.
Then run the command
C:\Windows\System32>gacutil /u Oracle.ManagedDataAccess
And you are able to uninstall the data successfully.
Now I am able to access application without any error.

I got this error when my App.Config contained an old version of the DLL, I just removed this entry from the App.Config and it worked

Related

Web.config in Views subfolder ignored on developer machine, why?

I have an ASP.NET MVC application with a root web.config and a secondary Views/web.config added automatically by Visual Studio years ago when the application was created.
Now I have bumped ASP.NET MVC to a newer version (5.2.7), fixed various issues on my developer machine - and everything works for me.
Unfortunately, when pushed to our integration test server, everything fails as there are MVC version references, in the Views/web.config file, that are now invalid for the new MVC version.
I can fix the version issues and everything is 200 OK ... but, and here is my question, why doesn't the errors show up on my local developer machine?
It turns out I can introduce XML syntax errors and what not on my local machine - and nothing happens, everything is okay locally, as if the Views/web.config file is completely ignored by the webserver.
Both machines are running IIS on Windows with the same configuration ... well, except that something apparently is different.
Where should I look to figure out why the Views/web.config is ignored on my developer machine?
The Views/web.config looks like this (with the wrong version numbers included):
<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
<section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
</sectionGroup>
</configSections>
<system.web.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<pages pageBaseType="System.Web.Mvc.WebViewPage">
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="CBrain.F2.SelfService.Mvc.Html" />
</namespaces>
</pages>
</system.web.webPages.razor>
<appSettings>
<add key="webpages:Enabled" value="false" />
</appSettings>
<system.web>
<compilation>
<assemblies>
<add assembly="System.Web.Mvc, Version=5.2.7.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</assemblies>
</compilation>
</system.web>
<system.webServer>
<handlers>
<remove name="BlockViewHandler"/>
<add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
</handlers>
</system.webServer>
</configuration>
Turns out that IIS behaves a bit strange: once the webpage loads correctly first time, I can change the Views/web.config without IIS detecting the change. But then I modify the main web.config ... whereafter IIS detects my changes in Views/web.config. Guess I have to live with that.

Windows application deployment with SQL Server database and Entity Framework error

I have a Windows app which I developed with Entity Framework and a code-first approach. It's working perfectly on my own computer. But when I try to deploy the app to a client who has SQL Server installed, it throws the following error. What am I missing here?
System.BadImageFormatException: Could not load file or assembly 'EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The module was expected to contain an assembly manifest.
File name: 'EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' at BLL.BLMasters.BLCompany..ctor()
Here is my app.config file:
<configuration>
<configSections>
<section name="entityFramework"
type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
requirePermission="false"/>
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2"/>
</startup>
<connectionStrings>
<add name="MyDBConnectionString"
providerName="System.Data.SqlClient"
connectionString="Data Source=DESKTOP-NMSSFU8;Initial Catalog=AMSDEV;Integrated Security=True; Max Pool Size=200;" />
</connectionStrings>
<entityFramework>
<providers>
<provider invariantName="System.Data.SqlClient"
type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer"/>
</providers>
</entityFramework>
</configuration>
Can you please check if the project properties of all your projects are set to correct target platform?
Goto your project properties → Build → Target Platform.
Check this is set to either of the values for all your projects: x86, x64, Any CPU.
Try selecting "Any CPU" for all projects in your solution and then deploy it to client machine and check.
This error generally occurs when you have different CPU architecture then the compiled version of the target machine. Selecting Any CPU generally solves the issue.

The ADO.Net provider with Invariant name 'System.Data.SQLite.EF6' is not registered in the machine or application config file

So I've been struggling to try and get this resolved for a week or so now. When I attempt to run my application on another computer other than my development machine, I get the following error:
Schema specified is not valid. Errors:
EntityFramework.RemManagerDBModel.ssdl(2,79): error 0175:
The ADO.Net provider with invariant name 'System.Data.SQLite.EF6' is either not registered in the machine or application config file, or could not be loaded. See the inner exception for details.
I attempted to retrieve the inner exception using this method, but to no avail. I'm not sure why it seems to think there is an inner exception, when in fact there isn't?
With regard to attempting to fix the issue myself, I have tried (I believe) all of the relevant possible solutions that are found under this SO question.
Currently my app.config looks something along the lines of what is shown below. An example of the connection string that is created is also included. The application uses Entity Framework 6 from a database first configuration. The entity model and diagram have been newly generated from the database file. I am able to open the entity diagram with no problems and regenerating it via the "run custom tool" option hasn't made any difference. The issue only seems to be present if I try to run the installed application on another computer. In this case, the computer is a totally clean (factory restored) version of Windows 10.
If any more information is required, I can add it in as necessary.
App.config file:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="RemManager.Forms.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<connectionStrings>
<!-- See Datasource.ConnectionController for the connection string builder.-->
</connectionStrings>
<entityFramework>
<providers>
<provider invariantName="System.Data.SQLite.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6, Version=1.0.106.0, Culture=neutral" />
<provider invariantName="System.Data.SQLite" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6, Version=1.0.106.0, Culture=neutral" />
</providers>
</entityFramework>
<system.web>
<membership defaultProvider="ClientAuthenticationMembershipProvider">
<providers>
<add name="ClientAuthenticationMembershipProvider" type="System.Web.ClientServices.Providers.ClientFormsAuthenticationMembershipProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" />
</providers>
</membership>
<roleManager defaultProvider="ClientRoleProvider" enabled="true">
<providers>
<add name="ClientRoleProvider" type="System.Web.ClientServices.Providers.ClientRoleProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" cacheTimeout="86400" />
</providers>
</roleManager>
</system.web>
<system.data>
<DbProviderFactories>
<remove invariant="System.Data.SQLite.EF6" />
<add name="SQLite Data Provider"
invariant="System.Data.SQLite"
description="Data Provider for SQLite"
type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" />
<add name="SQLite Data Provider (Entity Framework 6)"
invariant="System.Data.SQLite.EF6"
description=".NET Framework Data Provider for SQLite (Entity Framework 6)"
type="System.Data.SQLite.EF6.SQLiteProviderFactory, System.Data.SQLite.EF6" />
</DbProviderFactories>
</system.data>
</configuration>
Example Connection String:
metadata=res://*/EntityFramework.RemManagerDBModel.csdl|res://*/EntityFramework.RemManagerDBModel.ssdl|res://*/EntityFramework.RemManagerDBModel.msl;provider=System.Data.SQLite.EF6;provider connection string="data source=C:\Users\MacbookPro\AppData\Roaming\RemManager\Datasource\RemManagerDB.db;default timeout=5000;failifmissing=True;read only=False;version=3"
I found the fix here: SQL DDEX for EF6 as I had installed VS into a new laptop.
steps:
Install latest SQLCEToolbox (this is a .vsix add-on to be able to open SQLite DB within VS IDE). Follow the installer prompts, it may need to stop tasks you need to click "End Task" to continue the install
Install SQLite in GAC (note: x86 not x64)
Once per machine. Download the latest sqlite-netFx46-setup-bundle-x86-2015-1.0.xxx.0.exe (from https://system.data.sqlite.org/index.html/doc/trunk/www/downloads-unsup.wiki)
Select all checkbox: "Full Installation", Install the assemblies into the global assembly cache and Install VS designer components
Restart VS
to check:
in VS main menu: Tools, there is a new entry SQLite/SQLServer compact toolbox. Click on that and it will open a new tab where Solution Explorer is located near it. Click the About (question mark icon) and check both GAC and DDEX provider are "Yes"

Run time Error in converting application from .NET 2.0 to 4.5.1

I'm trying to convert my application from .NET 2.0 to 4.5.1 but I got the with the run time version of my application.
Could not load file or assembly '...dll' or one of its
dependencies.This assembly is built by a runtime newer than the
currently loaded runtime and cannot be loaded.
How can I can get rid off this?
Did I forgot something to add or modify on my Web.config?
The process of publishing the application is through local and the published files will be copy paste on the application server in Virtual Machine.
I just solved the issue by publishing the application locally in VS2013,get the published version and add & modified the web.config of the application server instance with the ff:
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="[myDllname].Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
</sectionGroup>
</configSections>
<system.web>
<globalization uiCulture="auto" culture="auto"/>
<customErrors mode="Off"/>
<pages validateRequest="false" controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID">
<controls>
<add tagPrefix="csla" namespace="Csla.Web" assembly="Csla, Version=3.0.3.0, Culture=neutral, PublicKeyToken=93be5fdc093e4c30"/>
</controls>
</pages>
<!--
Set compilation debug="true" to insert debugging
symbols into the compiled page. Because this
affects performance, set this value to true only
during development.
-->
<compilation debug="true" targetFramework="4.5.1">
<assemblies>
<add assembly="System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</assemblies>
</compilation>
<identity impersonate="true"/>
<authentication mode="Windows"/>
</system.web>
Just make sure that the target framework is in compatible mode. In my case, I'm using old CSLA version.

Multiple Configuration Sources for Enterprise Library 4.1?

We use the caching and logging application blocks from entlib 4.1. We want to keep the configuration of those two in seperate files. How can we achieve this?
It looks like entlib is always using the selectedSource as it configuration.
I tried the following:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="enterpriseLibrary.ConfigurationSource" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ConfigurationSourceSection, Microsoft.Practices.EnterpriseLibrary.Common, Version=4.1.0.0, Culture=neutral, PublicKeyToken=9057346a2b2dcfc8" />
</configSections>
<enterpriseLibrary.ConfigurationSource selectedSource="messagesCache">
<sources>
<add name="messagesCache" filePath="Configuration\\messagesCache.config" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common, Version=4.1.0.0, Culture=neutral, PublicKeyToken=9057346a2b2dcfc8" />
<add name="logging" filePath="Configuration\\logging.config" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common, Version=4.1.0.0, Culture=neutral, PublicKeyToken=9057346a2b2dcfc8" />
</sources>
</enterpriseLibrary.ConfigurationSource>
</configuration>
But this doesn't work because the application blocks always use the selectedSource attribute value.
As noted in External configuration files in Enterprise Library for .NET Framework 2.0:
[...] while you can configure as many
Configuration Sources as you want
using the tool, only one is ‘selected’
to be the one which Enterprise Library
will automatically use [...]
What I have done is use the configSource attribute:
<configuration>
<configSections>
<section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<section name="exceptionHandling" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration.ExceptionHandlingSettings, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<section name="validationConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Validation.Configuration.ValidationSettings, Microsoft.Practices.EnterpriseLibrary.Validation, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</configSections>
<loggingConfiguration configSource="logging.config"/>
<exceptionHandlingConfiguration configSource="exceptionHandling.config"/>
<dataConfiguration configSource="dataAccess.config"/>
<validationConfiguration configSource="validation.config"/>
</configuration>
It works great, but the downside is that if you are editing your application/web config file using the configuration tool and save your configuration it will be saved inside the application/web config file.

Categories