GetInstance<Database>(anything) gives ActivationException when platform target set to x86

Topics: Data Access Application Block, Enterprise Library Core
Oct 28, 2014 at 3:44 AM
Edited Oct 28, 2014 at 3:50 AM
Hi,

I get an ActivationException when I try to get an instance of a database using the code below. It does not matter what the instance name is.

Database db = EnterpriseLibraryContainer.Current.GetInstance<Database>("DEV64");

This only happens when the platform target is set to x86 in the build settings. The computers which are tested on are Windows 7 64bit. It does not happen on the developers PC's which are also Windows 7 64bit but I don't know what the differences are between the builds.

I am using Enterprise Library 5.0.505 with EntLibContrib 5.0.505 as the database driver is ODP.Net. I am using Visual Studio 2012. If I set the platform to Any CPU then it works - but I will have to set it to x86 when I release it.

So, I guess what I need is advice on what would cause the error on one build but not on another. What is the operation doing that causes the problem? Obviously I am trying to find the differences between the builds but knowing what is happening may give me the solution.

Thanks
Jason
FYI - the exception is:
An exception of type 'Microsoft.Practices.ServiceLocation.ActivationException' occurred and was caught.
...
Type : Microsoft.Practices.ServiceLocation.ActivationException, Microsoft.Practices.ServiceLocation, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
Message : Activation error occured while trying to get instance of type Database, key "DEV64"
Oct 28, 2014 at 4:26 AM
Edited Oct 29, 2014 at 2:29 PM
My first thought is that the DbProviderFactories are not configured properly. If EntLib cannot locate the provider it won't register the Database in the container which will then cause an exception to be thrown when resolving the database.

It could be that the DbProviderFactories are not configured in both machine.config locations. See this post: http://entlib.codeplex.com/discussions/394482 .

As a test you could add the following to your web/app.config to see if it helps:
<system.data>
    <DbProviderFactories>
        <remove invariant="Oracle.DataAccess.Client" />
        <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=2.102.2.20, Culture=neutral, PublicKeyToken=89b483f429c47342" />
    </DbProviderFactories>
</system.data>

Replacing with the specifics for the version you are using.

~~
Randy Levy
entlib.support@live.com
Enterprise Library support engineer
Support How-to
Oct 28, 2014 at 12:27 PM
Edited Oct 28, 2014 at 12:32 PM
Thanks.

Just to be clear on this - which machine.config am I getting the information from, for this setting? I assume you mean the one on the non-working machine as that is my target?

As it fails on x86 build setting - which machine.config file would be used? 'Any CPU' setting works.
Oct 28, 2014 at 2:14 PM
Yes, the interesting machine.config would be on the non-working machine. machine.config should be in %WINDIR%\Microsoft.NET\Framework\v4.0.30319 depending on the version you are using (perhaps C:\Windows\Microsoft.NET\Framework\v2.0.50727\CONFIG).

It wouldn't hurt to compare x86 vs. x64 machine.configs on both a working and non working machine just to see what the differences were (with the DbProviderFactories). i.e. see of you can spot any easy environmental differences.


~~
Randy Levy
entlib.support@live.com
Enterprise Library support engineer
Support How-to
Oct 28, 2014 at 3:19 PM
Thanks - I do think we are getting close.

So, if I set my build platform to x86, I should look under Framework and if I set it to x64 or 'Any CPU' on a 64bit PC, then I need to look at Framework64?
Oct 29, 2014 at 12:40 AM
smallmj wrote:
So, if I set my build platform to x86, I should look under Framework and if I set it to x64 or 'Any CPU' on a 64bit PC, then I need to look at Framework64?

Basically, yes. If the config (for Oracle DbProviderFactories) is the same in both machine.config files then I would recommend seeing if the ActivationException's InnerException can provider any more information.
Marked as answer by smallmj on 10/29/2014 at 4:13 AM
Oct 29, 2014 at 12:14 PM
Thanks

That solved the problem.