I installed the odp.net 32 bit installation for Visual Studio 2012. I set a reference to the Oracle.DataAccess.dll and my connection to Oracle seems to be working.
When I build the project (.net 4) I get the following error. The project is set to build AnyCPU (my workstation is 64 bit and the server where we will ultimately deploy to is 32bit)
'There was a mismatch between the processor architecture of the project being built "MSIL" and the processor architecture of the reference Oracle.DataAcess, Version 4.112.3.0, Culture=neutral, PublicKeyToken=89b483f429c47342, processorArchitecture=x86, "x86". This mismatch may cause runtime failures. Please consider changing the targeted processor architecture of your project through the Configuration Manager so as to align the processor architecture between your project and the references, or take a dependency on reference with a processor architecture that matches the targeted processor architecture of your project'
This is only a vs.net warning however is there any way to get rid of this?
Like you said, it's just a warning. Because ODP.net is not "AnyCPU" the warning indicates that you have a dependency that is not going to adapt to the host operating system as your own application is. As long as your odp.net install matches the os in terms of bits, you'll be fine. But the compiler is unable to make that determination and is trying to give you a heads up.
I did find a connect article on this which includes a possible change (i'm assuming to the proj file) to disable the error:
<PropertyGroup>
<ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch>None</ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch>
</PropertyGroup>
In any case, your "AnyCPU" application will run fine on your server as long as the 32 bit odp.net you install on the server is the same version as the 64 bit odp.net you referenced (or publisher policies are properly installed to redirect to a later version). To eliminate any confusion i generally set "Copy Local" for the reference to "false." In otherwords, I compile against a specific version of the dll but let it run against what it resolves from the GAC (which includes publisher policies that most of the odp.net installations include).
You can also install the 32 bit odp.net on your dev machine (ideally the same version again) in order to run/debug 32 bit applications or to use the integrated tooling that comes "with Oracle Developer Tools for Visual Studio" inside of Visual Studio.
All that said, there's more than meets the eye here. If you're application is in fact running (which is implied with "it's only a warning"), as 64 bit, than it is NOT using your 32 bit installation. I would guess your machine already has the 64 bit version installed (multiple oracle homes).
Another solution:
Download ODAC 11.2 Release 5 (11.2.0.3.20) and set your compiler to x86. I am 100 % sure it will clean all warnings related to oracle.
Set namespace to: using System.Data.Odbc;
Then make a database connection.
This is only a vs.net warning however is there any way to get rid of
this?
I believe there is no way to get rid of that, since you want to deploy on 32 bit machine and you create on 64 bit. This is just a warning that informs you that there may be sth wrong with the driver. Nothing to worry about if you now what you're doing.
You should expect it - you use 32 bit libraries on 64 bit architecture.
Related
I am using Visual Studio, Test Complete and C#. I am basing it off another project which also uses the same. This other project uses Oracle to query and works fine.
I based all my settings on the other project (any CPU, all the same references, etc). However, when I run it and attempt to connect to oracle I get an exception about a bad image (this happens when you run 64 bit and try to load a 32-bit client). I copied all the references, and tried all combinations of build. I do think I am running 64-bit because when I am debugging and try to insert a line it says it is disallowed in 64-bit mode. On the other application it lets me insert lines during debugging.
Here is the exception:
e {"Attempt to load Oracle client libraries threw BadImageFormatException. This problem will occur when running in 64 bit mode with the 32 bit Oracle client components installed."} System.Exception {System.InvalidOperationException}
I try replacing the oracle library but it always seems to go back. Better would be to run in 32-bit mode. As you can see from the picture, for some reason "Prefer 32-bit" is disabled (also in the application that works).
Any idea what to do? This will also, once it runs on my machine, be transferred to another.
This is Visual Studio 2012 (11.061219.00)
Use connection.GetType().Assembly.Location to check which DLL is actually loaded.
Typically (and simplified, see How the Runtime Locates Assemblies) assemblies are loaded from GAC (Global Assembly Cache) or from directory where your .exe is stored. Note, the GAC takes precedence!
If a .exe or .dll file is x86 or x64, you can check with sigcheck tool.
In Oracle Client 12.1 Setup and later the ODP.NET is not added to GAC anymore, you need to add it manually.
You may use my Oracle Connection Tester which could show you the problem of your installation.
Is there any way to make my .NET application use either 32 bit or 64 bit reference, depending on whichever one is available on the running environment?
I've a MSIL built application that currently references the 32-bit version of Oracle.DataAccess, because that's the version installed on my machine. Problem is, some machines only have 64-bit Oracle.DataAccess installed. Is there a way to set my application so that it dynamically references the available dll, regardless of its word size?
Have you tried using the Managed Oracle Data Provider (ODP) for .NET driver? I use it for all my .NET (3.x and 4.x) applications that communicate with an Oracle database. It and the Oracle Instance Client are simple to install and use via XCOPY or NUGET.
With a windows smart client application, it runs fine on my (development) machine, but when I installed it on a user's machine, I get this error:
Requires log4net version 1.2.10 be installed in GAC
On my development machine, I have 2 log4net files that are GACed: one x86, one 64 bit. The user machine has only the x86 version. So I guess the user needs the 64 bit, yes?
If so, how do I install a 64 bit version of log4net?
Note that this is a different error than this:
Error: Could not load log4net assembly
I've discovered another difference. If I publish in Development/Debug configuration, it works. If I publish in Release config, I get the error.
There seems to be no direct log4net references. It is use in either CrystalReports or NHibernate or both.
In Debug Configuration, the application is running as 32bit, in Release Configuration, the application is running as 64bit. If I could get the Release Configuration to run as 32bit, I think that would solve the problem. Can anyone say how that is done?
You can change the Release configuration to x86 in Visual Studio => Project properties => Compile => Advanced Compile options
Check if you have Copy local=true on the log4net reference. If it is false the log4net has to be installed in the GAC, when it is true it is included in the application bin directory.
If you want to install it in the gac you can use gacutil to install the log4net.dll into the gac. Check if you application runs in 64bit (process explorer), if so, you need to install the 64bit version.
I faced similar issue with my ClickOnce application. I tried to put log4net dll in GAC and publish, but didn't work. It was also not related to 32/64 bit version as well.
The solution worked foe me is
Remove and add log4net references in all the required projects from local folder.
Check log4net reference properties and make sure property "CopyLocal=True" for all references. (In my case one of the referenced project was referring log4net with "CopyLocal=False" and thus looking for DLL in GAC)
(For ClickOnce deploy applications) Remove and add referenced DLLs (which refer log4net) in the main project. This will force all the DLLs to be downloaded to client's machine again.
Hope this helps.
I'm using the Oracle Data Access(ODP.NET) in a mvc3 project.
the odp.net has both x64 and x86 versions separately and i want to use the x64 version.
I set "Platform target" to x64 and add a reference to x64 version of odp.net, there is no problem to publish on iis server, but i can't run the project for develop and test, however Razor views display errors on c# statements.
How i can develop the project in x64 platform?
I would say the immediate problem is forcing your platform target to x64. The asp.net development server is 32 bit. Either leave it as "Any CPU" or run a 64 bit dev server (either the local IIS server or compile cassinidev as 64 bit). If you do leave it as any cpu so you can continue to use the out of the box dev server, you'll get the same error with the 64 bit version of oracle.dataaccess.dll for the exact same reason.
I install the 32 bit version on my machine (i also install the 64 bit version but I mention that only to note that they run fine side by side). The reference to Oracle.DataAccess.dll does not include bit-ness, only version. So as long as you have the same version (or later with publisher policies) of the 64 bit flavor on the server, everything will run fine once you deploy.
My .NET 3.5 WPF application has started showing a bunch (14) of the the following warning (with different dlls):
Referenced assembly 'C:\WINDOWS\assembly\GAC_32\Microsoft.TeamFoundation
\9.0.0.0__b03f5f7f11d50a3a\Microsoft.TeamFoundation.dll'
targets a different processor than the application.
I am running on a 32 bit machine. The only project in my solution is set to compile to "Any CPU". (A rebuild all does not fix it.)
I would rather not recreate my solution. Does anyone else know another fix/workaround for this issue?
NOTE: I am using Visual Studio 2008 SP1 and Windows XP 32 bit.
Haven't seen that one specifically but the download samples for C++ by default build for Itanium - did you install the wrong version of those libs?