加载组合框wix时出错

时间:2015-05-26 14:15:58

标签: c# combobox wix windows-installer

我有C#自定义操作,它将可用的服务器证书加载到组合框中。一切正常,但安装程序无法在客户端系统上运行自定义操作。首先我认为IIS方面存在一些问题,但后来发现安装程序在加载到组合框时会抛出错误。

以下是我的C#代码:

public static ActionResult ListCertificate(Session session)
        {
            session.Log("ListCertificate: Begin");
            try
            {
                int Index = 1;
                List<string> list = new List<string>();
                X509Store certificateStore = new X509Store(StoreName.My, StoreLocation.LocalMachine);
                certificateStore.Open(OpenFlags.OpenExistingOnly | OpenFlags.ReadWrite);

                foreach (X509Certificate2 certificate in certificateStore.Certificates)
                {
                    String ApplicationCertificate = certificate.FriendlyName;
                    list.Add(ApplicationCertificate);
                }
                certificateStore.Close();

                List<string> DistinctCertificateList = list.Distinct().ToList();

                View view = session.Database.OpenView("DELETE FROM ComboBox WHERE ComboBox.Property='APPLICATION_CERTIFICATE_NAME'");
                view.Execute();

                view = session.Database.OpenView("SELECT * FROM ComboBox");
                view.Execute();

                foreach (string DistinctApplicationCertificate in DistinctCertificateList)
                {
                    if (!string.IsNullOrWhiteSpace(DistinctApplicationCertificate))
                    {
                        Record record = session.Database.CreateRecord(4);
                        record.SetString(1, "APPLICATION_CERTIFICATE_NAME");
                        record.SetInteger(2, Index);
                        record.SetString(3, DistinctApplicationCertificate);
                        record.SetString(4, DistinctApplicationCertificate);

                        view.Modify(ViewModifyMode.InsertTemporary, record);
                    }
                    Index++;
                }
                view.Close();

                session.Log("ListApplicationCertificate: End");
            }
            catch (Exception ex)
            {
                Record record = session.Database.CreateRecord(2);
                record.SetString(1, session["LISTCERTIFICATE_ERROR"]);
                record.SetString(2, ex.Message);
                session.Message(InstallMessage.FatalExit, record);
                session["ERRORMSG"] = ex.Message;
                session["ERRORSHOW"] = session["LISTCERTIFICATE_ERROR"];
                session.Log("ListApplicationCertificate: exception: {0}", ex.Message);
                return ActionResult.Failure;
            }

            return ActionResult.Success;
        }

我的wix UI代码是:

<Control Id="ApplicationCertificateLabel" Type="Text" X="20" Y="190" Width="130" Height="15" TabSkip="no" Text="!(loc.ApplicationCertificateLabel)" />

        <Control Id="ApplicationCertificateComboBox" Type="ComboBox" X="130" Y="185" Width="200" Height="18" Property="APPLICATION_CERTIFICATE_NAME" ComboList="yes">
          <ComboBox Property="APPLICATION_CERTIFICATE_NAME">
            <ListItem Text="[APPLICATION_CERTIFICATE_NAME]" Value="[APPLICATION_CERTIFICATE_NAME]" />
          </ComboBox>
        </Control>

我在详细日志中遇到以下错误: &#39;执行期间功能失败。数据库:。第2列&#39;

中的更新数据类型无效

我好几天都在摸不着头脑。请帮我解决这个问题。

提前致谢。

0 个答案:

没有答案