System.ApplicationException

时间:2012-10-19 15:52:20

标签: c# entity-framework

我试图浏览我的应用程序,我收到以下错误: System.Web.HttpUnhandledException:抛出了类型'System.Web.HttpUnhandledException'的异常。

在**代码行附近抛出异常:

public void LoadFromEntity(bool editable, string TabKey)
    {
        //Getting the FormMaster collection
        **FormTemplate formTemplate = PolicyClassCollection.CachedPolicyClasses.FindBy((int)EnumPolicyClasses.PNI).FormTemplateCo**llection.Find(ft => ft.PolicyClassId == Utility.GetCurrentPolicyClassId() && ft.DocumentType.DocumentTypeId == (int)EnumDocumentTypes.Coverage_Summary && ft.PolicyTypeId == Utility.GetCurrentAccount().CurrentRisk.PolicyTypeId);

        if (formTemplate != null)
        {
            //Set context string with current option number
            this._Account.CurrentRisk.FormContextData = this.OptionNum.ToString();

            //getting FormMasterID
            Guid vsDatabaseId = formTemplate.FormFilingHistoryId;
            string accountXmlString = this._Account.ToXML();

            //Setting the parameters in PDFServiceParms class that are to be used in "PDFService.aspx" page.
            PDFServiceParms pdfParams = new PDFServiceParms(FORM_MODE_EDIT, vsDatabaseId.ToString(), Model.AppConstants.FORM_TYPE_SELECTED_FORM, accountXmlString);

            //Saving the parameters in the session. PDFService.aspx page reads the parameters from the session. Session key is passed in the 
            //query string when calling the PDFService.aspx page.
            Session[AppConstants.SK_SUMMARY_PDF_PARAMS] = pdfParams;

            //Setting the iFrame's source to PDFService.aspx page. The PDF document generated in this page is displayed in the iFrame.
            this.iframePdf.Attributes["src"] = ResolveClientUrl(AppConstants.PAGE_NAME_PDFSERVICE) + "?datakey=" + AppConstants.SK_SUMMARY_PDF_PARAMS;
        }
        else
            throw new ApplicationException("FormMaster not found for PolicyClass = " + Utility.GetCurrentPolicyClassId().ToString() + " and DocumentType = " + ((int)EnumDocumentTypes.Coverage_Summary).ToString());
    }

抛出异常:

System.Web.HttpUnhandledException: Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> System.ApplicationException: FormMaster not found for PolicyClass = 2 and DocumentType = 27
   at PNI_SqbpeCovInfoPNISummary.LoadFromEntity(Boolean editable, String TabKey) in C:\TFS\Navigate Development\NavigateWebApp\PNI\SqbpeCovInfoPNISummary.aspx.cs:line 95
   at SQBPECoverageInformationMasterPNI.LoadFromEntity() in C:\TFS\Navigate Development\NavigateWebApp\PNI\SQBPECoverageInformationMasterPNI.master.cs:line 188
   at SQBPE.Page_Load(Object sender, EventArgs e) in C:\TFS\Navigate Development\NavigateWebApp\SQBPE.master.cs:line 55
   at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
   at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
   at System.Web.UI.Control.OnLoad(EventArgs e)
   at System.Web.UI.Control.LoadRecursive()
   at System.Web.UI.Control.LoadRecursive()
   at System.Web.UI.Control.LoadRecursive()
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
   --- End of inner exception stack trace ---
   at System.Web.UI.Page.HandleError(Exception e)
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
   at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
   at System.Web.UI.Page.ProcessRequest()
   at System.Web.UI.Page.ProcessRequest(HttpContext context)
   at ASP.pni_sqbpecovinfopnisummary_aspx.ProcessRequest(HttpContext context) in c:\Windows\Microsoft.NET\Framework64\v2.0.50727\Temporary ASP.NET Files\navigatewebapp\253cae21\57ec5e1d\App_Web_sqbpecovinfopnisummary.aspx.41d7eb59.1z9y4p0a.0.cs:line 0
   at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

有人可以告诉我需要做些什么。

1 个答案:

答案 0 :(得分:3)

抱歉,编辑整个答案,之前只有正确的一半

父例外是HttpUnhandledException。内部异常似乎很清楚,并说:

  

找不到PolicyClass = 2和DocumentType = 27

的FormMaster

该错误在您自己的代码中。 ApplicationException是在您引用的行上发生。该行的结果是formTemplate为空,并且您的代码抛出此异常。

这是抛出异常的一行:

throw new ApplicationException("FormMaster not found for PolicyClass = " 
    + Utility.GetCurrentPolicyClassId().ToString() 
    + " and DocumentType = " 
    + ((int)EnumDocumentTypes.Coverage_Summary).ToString());

(友情提示,请改用string.Format

这是返回null的行:

FormTemplate formTemplate = PolicyClassCollection.CachedPolicyClasses
    .FindBy((int)EnumPolicyClasses.PNI).FormTemplateCollection
    .Find(ft => ft.PolicyClassId == Utility.GetCurrentPolicyClassId() 
    && ft.DocumentType.DocumentTypeId == (int)EnumDocumentTypes.Coverage_Summary
    && ft.PolicyTypeId == Utility.GetCurrentAccount().CurrentRisk.PolicyTypeId);

(一个友好的提示:通过多行写出来。这有助于设置断点和可读性)


你的下一个问题应该是:为什么它会回归null?答案,我不知道。在我之前的回答尝试中,我说了一些关于第三方代码的事情。这正是这个,因为类PolicyClassCollection不是一个众所周知的类,互联网上没有文档。所以要么它是你自己的,在这种情况下你可以尝试单步执行(设置一个断点)或者是别人的,在这种情况下你可以尝试调用供应商或尝试在删除“只是我的代码”设置后单步执行。