neha
neha

Reputation: 63

Unrecognized Guid format

I am working on c# application where i am getting this error.

Here is Stack Track of error:

Stack Trace: at System.Guid.GuidResult.SetFailure(ParseFailureKind failure, String failureMessageID, Object failureMessageFormatArgument, String failureArgumentName, Exception innerException) at System.Guid.TryParseGuid(String g, GuidStyles flags, GuidResult& result) at System.Guid..ctor(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) at System.Web.UI.WebControls.MultiView.OnActiveViewChanged(EventArgs e) at System.Web.UI.WebControls.MultiView.set_ActiveViewIndex(Int32 value) at System.Web.UI.WebControls.Wizard.set_ActiveStepIndex(Int32 value) at Projects_AddProject.proxy_Navigate(Object sender, HistoryEventArgs e) at System.Web.UI.ScriptManager.RaiseNavigate(HistoryEventArgs e) at System.Web.UI.ScriptManager.LoadHistoryState(String serverState) at System.Web.UI.ScriptManager.RaisePostBackEvent(String eventArgument) at System.Web.UI.ScriptManager.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)

From the error its happening when its converting the string to guid. The method this occurs is wizCreateProject_ActiveStepChanged.It looks some Guid Conversion issue.

Here is method that generate error:

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;
        }
    }

Upvotes: 0

Views: 11956

Answers (1)

matt-dot-net
matt-dot-net

Reputation: 4244

The error is here:

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

You can see that internally the Guid constructor is using Guid.TryParse() which is what you should be doing. I would add a validator to the ddlProjTemplates to make it required and you also need to make sure that it only contains valid Guids.

Upvotes: 3

Related Questions