MEL 5.0 and ODP.Net error on Windows 7 box, Perfectly works on Windows XP

Topics: Data Access Application Block
Oct 29, 2010 at 6:08 AM

I have changed the target framework to full .Net Framework 4.0, now the error is different and as follows

"Could not load file or assembly 'Microsoft.Practices.ServiceLocation, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified."

Please provide any useful pointers.

 

Are you targeting the .NET 4.0 Client Profile?  If yes, change it to target the full .NET Framework 4.0.  The reason behind this is that the OracleClient assembly is not included in the client profile.

 

Going forward, please post all your questions in the EntLib forum.  We're not encouraged to answer questions privately.

 

Thank you for using Enterprise Library.

 

Sarah Urmeneta

Avanade Support

 

Subject: MEL 5.0 and ODP.Net error on Windows 7 box, Perfectly works on Windows XP

Team,

 

I am trying to execute a console c#.Net program which connects to Oracle DB, this program uses .Net 4.0 Fwl, MEL 5.0 and ODP.Net provider. The sample is working fine on Windows XP box and not working on Windows 7 box. We are using the same code on both the machines. We have tried options suggested at this link but of no use.

http://entlib.codeplex.com/Thread/View.aspx?ThreadId=232371

 

The error message is

Activation error occurred while trying to get instance of type Database, key "OracleSource"

 

Inner exception

 

{"Resolution of the dependency failed, type = \"Microsoft.Practices.EnterpriseLibrary.Data.Database\", name = \"OracleSource\".\r\nException occurred while: while resolving.\r\nException is: InvalidOperationException - The type Database cannot be constructed. You must configure the container to supply this value.\r\n-----------------------------------------------\r\nAt the time of the exception, the container was:\r\n\r\n  Resolving Microsoft.Practices.EnterpriseLibrary.Data.Database,OracleSource\r\n"}

 

Please find the config file below.

 

<?xml version="1.0" encoding="utf-8" ?>

<configuration>

 

  <configSections>

    <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data" />

  </configSections>

 

  <connectionStrings>   

    <add name="OracleSource" connectionString="Data Source=10.2.2.106/WMST4U;User Id=FORMS;Password=forms;" providerName="Oracle.DataAccess.Client"/>  

  </connectionStrings>

 

  <dataConfiguration defaultDatabase="OracleSource" />

 

</configuration>

 

The code fails at

 

Database db = DatabaseFactory.CreateDatabase("OracleSource");

 

Thanks,

Ravi

Oct 29, 2010 at 6:13 AM

I'm not sure why it's looking for that assembly, I only reference that if I use EnterpriseLibraryContainer.Current to get an instance of a Database object.  But there's no harm in doing so, so go ahead and add reference to it.

Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

Oct 29, 2010 at 6:28 AM

On second thought, is that assembly deployed in the same location where you referenced the Microsoft.Practices.EnterpriseLibrary.Data assembly?  If not, try adding it, no need to reference.

 

Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

Oct 29, 2010 at 6:55 AM

I have referred/added servicelocation dll, then it asked me to add unity dll which i added too. Finally it shows the same old error message which says

Activation error occured while trying to get instance of type Database, key "OracleSource"

 

Oct 29, 2010 at 6:57 AM
Edited Oct 29, 2010 at 7:04 AM

Oops, I thought you were using the ADO.NET provider for Oracle. 

 

Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

Oct 29, 2010 at 7:02 AM

I do not see any option here to attach my source code files, shall i send you thru email?

Oct 29, 2010 at 7:15 AM
Edited Oct 29, 2010 at 7:18 AM

No need.  I figured out the problem.  There should be an entry for the Oracle.DataAccess.Client data provider in the DbProviderFactories section.  Refer here for the sample.  Using

Database db = DatabaseFactory.CreateDatabase("OracleSource");

will give you an instance of GenericDatabase.  You should decide whether using this will be enough for you or if you need to create a new database provider for ODP.NET in entlib.  This topic from the documentation should help.  

 

Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com 

Oct 29, 2010 at 7:31 AM

i am working on this suggested solution ....but how it is working on windows xp box? why this special setting is required on windows 7 box?

 

 

Oct 29, 2010 at 7:37 AM

Probably, there's already an entry in the <DbProviderFactories> for the Oracle.DataAccess.Client in your machine.config file.  That entry can be in the machine.config or in your application's configuration file.

 

Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com 

Oct 29, 2010 at 10:50 AM

Yes you are correct, DBProviderFactory and Oracle Data Access Client entries are there on Windows XP box machine.config on which this sample is working fine. On Windows 7 box, i found that there are no such entries and i have modified app.config on this machine. Still no Luck.

Can you try the sample on Windows 7 box and make it work, also send me the config file or changes you have done to make it work. 

 

Oct 29, 2010 at 4:21 PM

The operating system shouldn't be a problem.  Are you still getting the same exception?  If it's a different one, kindly post it.

I don't know if it's relevant but did you run Visual Studio with elevated permissions (Run as Administrator)?  I've already tried doing this on a Windows 7 machine, just not with the Oracle.DataAccess.Client provider and it works as expected.

 

Sarah Urmeneta
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com 

Nov 2, 2010 at 6:56 AM

We are running visual studio run as administrator, we are getting the same error. No clue what is happening here?

We tried googled everywhere...No LUCK

 

 

Nov 3, 2010 at 1:56 AM

I'm also encountering an error but not the ActivationException, instead, I'm getting the TargetInvocationException.  Could you check if you have the same entry for the DbProviderFactories as with mine?

<system.data>
  <DbProviderFactories>
   <add name="Oracle Data Provider for .NET" invariant="Oracle.DataAccess.Client" description="Oracle Data Provider for .NET"
type="Oracle.DataAccess.Client.OracleClientFactory, Oracle.DataAccess, Version=4.112.1.2, Culture=neutral, PublicKeyToken=89b483f429c47342"/>
  </DbProviderFactories>
</system.data>

 

Sarah Urmeneta
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com 

Nov 3, 2010 at 1:24 PM

i have absolutely same config details even in my application......let me know once u solve this issue.

Nov 4, 2010 at 3:43 AM
Edited Nov 4, 2010 at 3:54 AM

I saw that the inner exception (2nd level) is actually an OracleException with this message: "The provider is not compatible with the version of Oracle client".  I think you're gonna have to ask this over the ODP.NET forum.

 

Sarah Urmeneta
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com 

Nov 4, 2010 at 8:51 AM

I think that your project is reference Oracle.DataAccess.Client assembly is not compatible with version of Oracle Client Provider for .NET

Please checking your version of Oracle.DataAccess.Client.dll is same as Oracle.DataAccess.Client.dll in odp.net folder (This folder is in oracle client installed folder).

 

In my opinion this case will occur when install multiple version of Oracle Client Provider for. NET, Please see my scenario.

1) Install ODP for 10G

2) Create project and reference Oracle.DataAccess.Client from ODP for 10G

3) Install ODP for 11G and remove ODP for 10G

In this case your Oracle.DataAccess.Client.dll that reference in your project is not compatible with currently Oracle Client Provider for .NET version


Sittichok S.