C# 自定义操作出错。有人知道这个错误吗?

C# Custom Action goes in error. Anyone got idea of this error?

在这个 CustomAction 中有一个到 Oracle 数据库的连接,很简单。 我必须从 table 中检索名字。问题是无法连接。事实上,在安装序列中,我得到了另一个自定义操作,它可以进行连接并且可以正常工作。

这是代码

using System;
using System.Collections.Generic;
using System.Text;
using WixToolset.Dtf.WindowsInstaller;
using Oracle.DataAccess.Client;
using System.IO;
using System.Data.SqlClient;
using System.Web;


namespace CustomAction1
{
   public class CustomActions
   {
     [CustomAction]
     public static ActionResult CustomAction1(Session session)
      {
        string ConnectionString = "User Id=NO;Password=NO;Data Source=NO";
        string properties;
        using (OracleConnection con = new OracleConnection(ConnectionString))
        {

            con.Open();
            using (OracleCommand retreive = new OracleCommand("select TABLE_EL from TABLE", con))
            using (OracleDataReader rd = retreive.ExecuteReader())
            {
                properties = null;
                int i = 0;
                while (rd.Read())
                {
                    if (properties != null)
                        properties = properties + "," + rd.GetString(0).Trim();
                    else
                        properties = rd.GetString(0).Trim();
                    i++;
                }
            }
        }
        session["ELENCODITTE"] = properties;
        return ActionResult.Success;
    }
}

这是抛出的异常

Exception thrown by custom action:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.TypeInitializationException: The type initializer for 'Oracle.DataAccess.Client.OracleConnection' threw an exception. ---> System.TypeInitializationException: The type initializer for 'Oracle.DataAccess.Client.RegAndConfigRdr' threw an exception. ---> System.Configuration.ConfigurationErrorsException: Configuration system failed to initialize ---> System.Configuration.ConfigurationErrorsException: Unrecognized configuration section startup. (C:\Users\davanzo\AppData\Local\Temp\MSI9D8D.tmp-\CustomAction.config line 3)
   at System.Configuration.ConfigurationSchemaErrors.ThrowIfErrors(Boolean ignoreLocal)
   at System.Configuration.BaseConfigurationRecord.ThrowIfParseErrors(ConfigurationSchemaErrors schemaErrors)
   at System.Configuration.ClientConfigurationSystem.EnsureInit(String configKey)
   --- End of inner exception stack trace ---
   at System.Configuration.ClientConfigurationSystem.EnsureInit(String configKey)
   at System.Configuration.ClientConfigurationSystem.PrepareClientConfigSystem(String sectionName)
   at System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(String sectionName)
   at System.Configuration.ConfigurationManager.GetSection(String sectionName)
   at Oracle.DataAccess.Client.RegAndConfigRdr..cctor()
   --- End of inner exception stack trace ---
   at Oracle.DataAccess.Client.RegAndConfigRdr.ReadEntriesForRegistryAndConfig()
   at Oracle.DataAccess.Client.OracleInit.Initialize()
   at Oracle.DataAccess.Client.OracleConnection..cctor()
   --- End of inner exception stack trace ---
   at Oracle.DataAccess.Client.OracleConnection..ctor(String connectionString)
   at CustomAction1.CustomActions.CustomAction1(Session session) in C:\Users\davanzo\source\repos\FetchDitte\FetchDitte\CustomAction.cs:line 20
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object arguments, Signature sig, Boolean constructor)
   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object parameters, Object arguments)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object parameters, CultureInfo culture)
   at WixToolset.Dtf.WindowsInstaller.CustomActionProxy.InvokeCustomAction(Int32 sessionHandle, String entryPoint, IntPtr remotingDelegatePtr)
CustomAction FetchDitte.CA.dll_1 returned actual error code 1603 (note this may not be 100% accurate if translation happened inside sandbox)
Action ended 15:31:25: FetchDitte.CA.dll_1. Return value 3.
MSI (c) (4C:28) [15:31:25:353]: Doing action: FatalError
Action 15:31:25: FatalError. 
Action start 15:31:25: FatalError.

解释在错误本身: System.Configuration.ConfigurationErrorsException: 无法识别的配置节启动。 我认为您忘记在配置文件的 configSections 中添加正确的设置,告诉框架如何处理自定义部分的配置。

通过安装nuget包解决Oracle.ManagedDataAccess。