我正在处理c#应用程序,我收到此错误。
这是Stack Track of error:
堆栈跟踪: 在System.Guid.GuidResult.SetFailure(ParseFailureKind失败,String failureMessageID,Object failureMessageFormatArgument,String failureArgumentName,Exception innerException)at System.Guid.TryParseGuid(String g,GuidStyles flags,GuidResult& 结果)在System.Guid..ctor(String g)at Projects_AddProject.wizCreateProject_ActiveStepChanged(对象发送者, EventArgs e)at System.Web.UI.WebControls.Wizard.OnActiveStepChanged(Object source, EventArgs e)at System.Web.UI.WebControls.Wizard.MultiViewActiveViewChanged(对象 来源,EventArgs e)at 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.proxy_Navigate(对象发送者, 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) 在 System.Web.UI.ScriptManager.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(字符串 eventArgument)
从将字符串转换为guid时发生的错误。发生这种情况的方法是wizCreateProject_ActiveStepChanged。它看起来有些Guid Conversion问题。
以下是生成错误的方法:
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;
}
}
答案 0 :(得分:3)
错误在于:
EzProject templateProject
= DBAccessProjects.GetProject(tenantID, new Guid(ddlProjTemplates.SelectedValue));
你可以看到Guid构造函数内部正在使用Guid.TryParse()
,这就是你应该做的事情。我会在ddlProjTemplates中添加一个验证器来使它成为必需的,你还需要确保它只包含有效的Guids。