Answer accepted by question author
Hello @Aman Agrahari ,
This might be happening because when Oracle Client 19c is installed, its installer appears to automatically configure machine-wide settings and the GAC. Because the .NET Framework generally loads machine.config first and checks the GAC before local assemblies, defining the oracle.manageddataaccess.client section again in your .exe.config likely triggers a duplicate section exception, causing the crash.
I would suggest some approaches to help your application run reliably regardless of the host machine's Oracle Client status:
- Remove the
<section>declaration: Try deleting<section name="oracle.manageddataaccess.client"...>from your.exe.configentirely. Since the .NET Framework requires section names to be unique across the configuration hierarchy, removing it can help prevent the duplication error. - Keep the
<DbProviderFactories>tags: What you did here aligns with Microsoft's design. Using the<remove invariant="..." />tag is the standard Microsoft .NET mechanism for clearing inherited collection settings to safely override machine-level configurations. - Configure via code: If you rely on specific Oracle settings (like
TNS_ADMIN), you might consider setting them programmatically using the OracleConfiguration class at application startup. Oracle provides this class specifically to handle settings in code, which can help decouple your app from XML files and any existing machine-level setups.
Disclaimer: Some links are non-Microsoft website. The pages appear to be providing accurate, safe information. Watch out for ads on the site that may advertise products frequently classifies as a PUP (Potentially Unwanted Products). Thoroughly research any product advertised on the site before you decide to download and install it.
I hope this helps with your question. If you found my response helpful, please follow this guide to provide feedback.
Thank you.
-
Aman Agrahari 220 Reputation points
Thank you for the explanation!!
Yes, deleting the
<section name="oracle.manageddataaccess.client" ...>entry from the.exe.configprevents the duplicate section error. However, I would like to confirm the actual purpose of this section and whether removing it permanently could cause any functional issues. In my case, the application packagestnsnames.oraas part of the installer.And I'm keeping
<DbProviderFactories>tags since it safely overrides machine-level configurations.
My goal is to ensure the application runs reliably on machines both with and without Oracle Client installed, without modifyingmachine.config. -
Taki Ly (WICLOUD CORPORATION) 2,145 Reputation points ⢠Microsoft External Staff ⢠Moderator
Hi @Aman Agrahari ,
Regarding your concern about the
<section>tag's purpose and whether removing it permanently is safe:1. The purpose of the
<section>tagAccording to Microsoft's documentation on Configuration Sections, the
<section>tag simply specifies the configuration handler for a custom XML element. It tells the .NET runtime how to parse the custom<oracle.manageddataaccess.client>block if one exists later in your.exe.config.If you remove that Oracle configuration block from your XML and choose to handle settings programmatically instead, this XML parser definition is no longer needed. Therefore, removing it might not cause any functional issues for your app.
2. Handling your packaged
tnsnames.oravia codeSince you are packaging
tnsnames.orawith your installer, you can bypass XML configuration entirely. Based on the OracleConfiguration Class documentation, Oracle provides properties to set these values in your code.You can set the
TNS_ADMINpath programmatically at the very beginning of your application startup. For example, iftnsnames.orais in the same directory as your.exe:C# Example
Oracle.ManagedDataAccess.Client.OracleConfiguration.TnsAdmin = System.AppDomain.CurrentDomain.BaseDirectory;VB.NET Example
Oracle.ManagedDataAccess.Client.OracleConfiguration.TnsAdmin = System.AppDomain.CurrentDomain.BaseDirectoryBy using this code-based approach, your application dynamically locates its own
tnsnames.orafile without relying on the.exe.configormachine.config. This appears to align with your goal of making the application reliable and independent of the host machine's Oracle Client installation.Hope this clears up the details for you.
Sign in to comment
