0

我正在处理出现此错误的 c# 应用程序。

这是错误的堆栈跟踪:

堆栈跟踪:在 System.Guid.TryParseGuid(String g, GuidStyles flags, GuidResult& result) 在 System.Guid..ctor 的 System.Guid.GuidResult.SetFailure(ParseFailureKind failure, String failureMessageID, Object failureMessageFormatArgument, String failureArgumentName, Exception innerException) (String g) at Projects_AddProject.wizCreateProject_ActiveStepChanged(Object sender, EventArgs e) at System.Web.UI.WebControls.Wizard.OnActiveStepChanged(Object source, EventArgs e) at System.Web.UI.WebControls.Wizard.MultiViewActiveViewChanged(Object source, EventArgs e) 在 System.Web.UI.WebControls.MultiView.OnActiveViewChanged(EventArgs e) 在 System.Web.UI.WebControls.MultiView.set_ActiveViewIndex(Int32 值) 在 System.Web.UI.WebControls.Wizard.set_ActiveStepIndex(Int32 值) 在 Projects_AddProject。在 System.Web.UI.ScriptManager.LoadHistoryState(String serverState) 在 System.Web.UI.ScriptManager.RaiseNavigate(HistoryEventArgs e) 在 System.Web.UI.ScriptManager.RaisePostBackEvent(String eventArgument) 的 proxy_Navigate(Object sender, HistoryEventArgs e)在 System.Web.UI.ScriptManager.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(字符串 eventArgument)

从将字符串转换为guid时发生的错误。发生这种情况的方法是 wizCreateProject_ActiveStepChanged。它看起来是一些 Guid 转换问题。

这是产生错误的方法:

protected void wizCreateProject_ActiveStepChanged(object sender, EventArgs e)
    {
              switch (wizCreateProject.ActiveStepIndex)
        {
                       case 0:
                if (rbFrmTemp.Checked)
                {
                    int tenantID = TenantUtils.getTenantId(Page);
                    EzProject templateProject = DBAccessProjects.GetProject(tenantID, new Guid(ddlProjTemplates.SelectedValue));

                    txNme.Text = templateProject.ProjectName;
                    txDesc.Text = templateProject.ProjectDescription;
                    CheckLoadWorkType(tenantID, ddlWrkType);

                    if (templateProject.WorkTypeID != null)
                    {
                        ListItem workItem = ddlWrkType.Items.FindByValue(templateProject.WorkTypeID.ToString());
                        if (workItem != null)
                        {
                            ddlWrkType.SelectedValue = templateProject.WorkTypeID.ToString();
                        }
                    }

                    if (templateProject.ProjectType == (int)ProjectType.Reoccurring)
                    {
                        CheckGroupedRadioButton(rbReoccurring);
                        txBilFreq.Text = templateProject.BillingFrequency.ToString();
                        if (templateProject.LastDate != null)
                        {
                            txtDate.Text = ((DateTime)templateProject.LastDate).ToShortDateString();
                        }
                        ListItem prdItem = ddlBilPrd.Items.FindByValue(templateProject.BillingPeriod);
                        if (prdItem != null)
                        {
                            ddlBilPrd.SelectedValue = prdItem.Value;
                        }
                        ScriptManager.RegisterClientScriptBlock(upPnlProject, typeof(UpdatePanel), upPnlProject.ClientID, "TypeChanged();", true);

                        wizCreateProject.ActiveStepIndex = 2;
                    }
                    else
                    {
                        wizCreateProject.ActiveStepIndex = 3;
                    }
                    BtnADD.Visible = true;
                }
                else
                {
                    if (rbReoccurring.Checked)
                    {
                        ScriptManager.RegisterClientScriptBlock(upPnlProject, typeof(UpdatePanel), upPnlProject.ClientID, "TypeChanged();", true);
                    }
                }
                break;
            case 3:
                txNme.Focus();
                ScriptManager.RegisterClientScriptBlock(upPnlProject, typeof(UpdatePanel), upPnlProject.ClientID, "InitNames();", true);
                break;
            default:
                break;
        }
    }
4

1 回答 1

3

错误在这里:

EzProject templateProject 
         = DBAccessProjects.GetProject(tenantID, new Guid(ddlProjTemplates.SelectedValue));

您可以在内部看到 Guid 构造函数正在使用Guid.TryParse()您应该执行的操作。我会向 ddlProjTemplates 添加一个验证器以使其成为必需,并且您还需要确保它仅包含有效的 Guid。

于 2013-09-03T14:54:15.440 回答