C#、Asp.Net Web 应用程序中出现奇怪的 System.***Exception 错误
Posted
技术标签:
【中文标题】C#、Asp.Net Web 应用程序中出现奇怪的 System.***Exception 错误【英文标题】:Strange System.***Exception error in C#, Asp.Net web app 【发布时间】:2016-08-16 03:25:29 【问题描述】:这是我见过的最奇怪的错误,我不知道原因是什么。在 VS2013 中,我有一个使用 datatables.net 和中继器的 aspx 页面。页面加载正常并正确显示,然后几秒钟后我得到了
"System.Web.dll 中发生'System.***Exception' 类型的未处理异常"
奇怪的是,如果我在我的 SQL 中执行“TOP 76”,我不会收到该错误,但是如果我执行“TOP 77”或更高版本,我会收到该错误。
我已经多次重新启动,删除并重新创建了不同名称的页面。尝试删除 datatables.net。我尝试替换单引号(认为这可能会弄乱我的标记)。但似乎没有任何效果。
这很奇怪,因为我在其他页面上具有相同的类型/样式/代码,但数据越来越少,而且它们都可以正常工作。
下一步是重新安装 VS2013,因为我想不出其他可以尝试的方法。任何帮助将不胜感激,因为我很困惑。
Click here for the data (csv)
StackTrace
这显示了 Visual Studio 放弃之前的 5,000 个条目
System.Runtime.Serialization.dll!System.Runtime.Serialization.TypeHandleRefEqualityComparer.GetHashCode(System.Runtime.Serialization.TypeHandleRef obj)
mscorlib.dll!System.Collections.Generic.Dictionary<System.Runtime.Serialization.TypeHandleRef,System.Runtime.Serialization.IntRef>.FindEntry(System.Runtime.Serialization.TypeHandleRef key)
mscorlib.dll!System.Collections.Generic.Dictionary<System.Runtime.Serialization.TypeHandleRef,System.Runtime.Serialization.IntRef>.TryGetValue(System.Runtime.Serialization.TypeHandleRef key, out System.Runtime.Serialization.IntRef value)
System.Runtime.Serialization.dll!System.Runtime.Serialization.Json.JsonDataContract.JsonDataContractCriticalHelper.GetId(System.RuntimeTypeHandle typeHandle)
System.Runtime.Serialization.dll!System.Runtime.Serialization.Json.JsonDataContract.JsonDataContractCriticalHelper.GetJsonDataContract(System.Runtime.Serialization.DataContract traditionalDataContract)
System.Runtime.Serialization.dll!System.Runtime.Serialization.Json.XmlObjectSerializerWriteContextComplexJson.WriteDataContractValue(System.Runtime.Serialization.DataContract dataContract, System.Runtime.Serialization.XmlWriterDelegator xmlWriter, object obj, System.RuntimeTypeHandle declaredTypeHandle)
System.Runtime.Serialization.dll!System.Runtime.Serialization.XmlObjectSerializerWriteContext.SerializeAndVerifyType(System.Runtime.Serialization.DataContract dataContract, System.Runtime.Serialization.XmlWriterDelegator xmlWriter, object obj, bool verifyKnownType, System.RuntimeTypeHandle declaredTypeHandle, System.Type declaredType)
System.Runtime.Serialization.dll!System.Runtime.Serialization.Json.XmlObjectSerializerWriteContextComplexJson.SerializeWithXsiType(System.Runtime.Serialization.XmlWriterDelegator xmlWriter, object obj, System.RuntimeTypeHandle objectTypeHandle, System.Type objectType, int declaredTypeID, System.RuntimeTypeHandle declaredTypeHandle, System.Type declaredType)
System.Runtime.Serialization.dll!System.Runtime.Serialization.XmlObjectSerializerWriteContext.InternalSerialize(System.Runtime.Serialization.XmlWriterDelegator xmlWriter, object obj, bool isDeclaredType, bool writeXsiType, int declaredTypeID, System.RuntimeTypeHandle declaredTypeHandle)
System.Runtime.Serialization.dll!System.Runtime.Serialization.XmlObjectSerializerWriteContextComplex.InternalSerialize(System.Runtime.Serialization.XmlWriterDelegator xmlWriter, object obj, bool isDeclaredType, bool writeXsiType, int declaredTypeID, System.RuntimeTypeHandle declaredTypeHandle)
[Lightweight Function]
/* lots of lines omitted */
System.Runtime.Serialization.dll!System.Runtime.Serialization.Json.JsonCollectionDataContract.WriteJsonValueCore(System.Runtime.Serialization.XmlWriterDelegator jsonWriter, object obj, System.Runtime.Serialization.Json.XmlObjectSerializerWriteContextComplexJson context, System.RuntimeTypeHandle declaredTypeHandle)
System.Runtime.Serialization.dll!System.Runtime.Serialization.Json.XmlObjectSerializerWriteContextComplexJson.WriteDataContractValue(System.Runtime.Serialization.DataContract dataContract, System.Runtime.Serialization.XmlWriterDelegator xmlWriter, object obj, System.RuntimeTypeHandle declaredTypeHandle)
System.Runtime.Serialization.dll!System.Runtime.Serialization.XmlObjectSerializerWriteContext.SerializeWithoutXsiType(System.Runtime.Serialization.DataContract dataContract, System.Runtime.Serialization.XmlWriterDelegator xmlWriter, object obj, System.RuntimeTypeHandle declaredTypeHandle)
System.Runtime.Serialization.dll!System.Runtime.Serialization.XmlObjectSerializerWriteContext.InternalSerialize(System.Runtime.Serialization.XmlWriterDelegator xmlWriter, object obj, bool isDeclaredType, bool writeXsiType, int declaredTypeID, System.RuntimeTypeHandle declaredTypeHandle)
System.Runtime.Serialization.dll!System.Runtime.Serialization.XmlObjectSerializerWriteContextComplex.InternalSerialize(System.Runtime.Serialization.XmlWriterDelegator xmlWriter, object obj, bool isDeclaredType, bool writeXsiType, int declaredTypeID, System.RuntimeTypeHandle declaredTypeHandle)
[Lightweight Function]
System.Runtime.Serialization.dll!System.Runtime.Serialization.Json.JsonCollectionDataContract.WriteJsonValueCore(System.Runtime.Serialization.XmlWriterDelegator jsonWriter, object obj, System.Runtime.Serialization.Json.XmlObjectSerializerWriteContextComplexJson context, System.RuntimeTypeHandle declaredTypeHandle)
System.Runtime.Serialization.dll!System.Runtime.Serialization.Json.XmlObjectSerializerWriteContextComplexJson.WriteDataContractValue(System.Runtime.Serialization.DataContract dataContract, System.Runtime.Serialization.XmlWriterDelegator xmlWriter, object obj, System.RuntimeTypeHandle declaredTypeHandle)
System.Runtime.Serialization.dll!System.Runtime.Serialization.XmlObjectSerializerWriteContext.SerializeWithoutXsiType(System.Runtime.Serialization.DataContract dataContract, System.Runtime.Serialization.XmlWriterDelegator xmlWriter, object obj, System.RuntimeTypeHandle declaredTypeHandle)
The maximum number of stack frames supported by Visual Studio has been exceeded.
这是aspx
<%@ Page Title="" Language="C#" MasterPageFile="~/OxintMaster.master" AutoEventWireup="true" CodeBehind="inactivereport.aspx.cs" Inherits="oxint.com._40.admin.contrib.inactivereport" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<div class="grid">
<div class="row cells12">
<div class="cell colspan12">
<h3>Companies assigned to Inactive Contributors Report (<asp:Literal runat="server" ID="litCount" ></asp:Literal>)</h3>
</div>
</div>
<table id="mysearchresultstable" class="dataTable striped" data-page-length='25'>
<thead>
<tr>
<th>Contributor</th>
<th style="text-align:center;">Count</th>
<th style="text-align:center;">Action</th>
</tr>
</thead>
<tbody>
<%try
%>
<asp:Repeater runat="server" ID="rptData1">
<ItemTemplate>
<tr>
<td style="white-space:nowrap;">
<a href='/admin/contrib/cndisplay.aspx?id=<%#Eval("Items[0].Value")%>'>
<asp:Literal runat="server" ID="litName"></asp:Literal>
</a>
</td>
<td style="white-space:nowrap;text-align:center;"><%#Eval("Items[3].Value")%></td><!--count-->
<td style="white-space:nowrap;text-align:center;">
<a href='/admin/contrib/inactiveview.aspx?id=<%#Eval("Items[0].Value")%>'><span class="mif-info"></span>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
<%
catch (Exception ex) Response.Write(ex.Message); %>
</tbody>
</table>
</div>
<script>
$(document).ready(function ()
/*$.fn.dataTable.moment('dd MMM yyyy HH:mm');*/
$('#mysearchresultstable').dataTable(
/*"order": [[1, "asc"]],*/
/*responsive: true,*/
"lengthMenu": [25, 50, 100],
"pagingType": "full",
"oLanguage": "sSearch": "Filter:" ,
"aoColumns": [null, null, "bSortable": false ]
);
);
</script>
</asp:Content>
下面是代码
using ApplicationClasses;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace oxint.com._40.admin.contrib
public partial class inactivereport : System.Web.UI.Page
private int iCount get; set;
protected void Page_Load(object sender, EventArgs e)
if (!IsPostBack)
rptData1.ItemDataBound += rptData1_ItemDataBound;
string sData = "SELECT contributor.referenceno,contributor.firstname,contributor.lastname,COUNT(contributor.referenceno) As Count " +
"FROM ((Contribprofile inner join contributor on Contribprofile.referenceno=contributor.referenceno) " +
"inner join Profilecompany on Contribprofile.companyid=Profilecompany.companyid) " +
"where Contribprofile.iscurrent =1 and not contributor.status in ('Full','Trial') " +
"group by contributor.Referenceno,contributor.firstname,contributor.lastname ";
rptData1.DataSource = new DataAccessFunctions.DataAccess().GetData(sData, null);
rptData1.DataBind();
void rptData1_ItemDataBound(object sender, RepeaterItemEventArgs e)
GenericData oData = (GenericData)e.Item.DataItem;
iCount += ApplicationSystemFunctions.SystemFunctions.ParseInt(oData.Items[3].Value);
litCount.Text = iCount.ToString();
Literal oLiteral = (Literal)e.Item.FindControl("litName");
oLiteral.Text = string.Format("0 1", oData.Items[1].Value, oData.Items[2].Value.Replace("'", "-"));
【问题讨论】:
为什么你的 html 上有一个 try-catch 块? 堆栈跟踪怎么样? 嗯,这似乎是一个显而易见的问题,但是您的数据库中的记录是否超过 76 条? Try/Catch 是绝望,它没有帮助。堆栈跟踪“源不可用”当错误窗口弹出时,您可以确定并继续,按任一结束执行。 DB 查询返回 246 条记录。它们在附件中。 (以上链接) 在 IIS Express 和发布 IIS 中是否发生? 【参考方案1】:我遇到了这个确切的问题,我最终将其追溯到为我的 DataList 设置模板的 aspx 代码。我在行 html 标记 tr" 中有一个错字,其中引号是删除以前的样式信息时留下的。删除引号后,错误就消失了。
【讨论】:
天啊。我不敢相信就是这样。有一个td
缺少内联样式的双引号。这太不可思议了,我实际上已经对 aspx 和 html 代码睁一只眼闭一只眼了。我在笑这样一个愚蠢的简单错误
我遇到了同样的问题,如果不是这个答案,我想我不会解决它。就我而言,我正在生成一些 HTML 服务器端,并且段落缺少关闭标记。它在调试时导致堆栈溢出,这发生在页面呈现后 - 页面需要刷新 5 次才能生成错误。
Asp.Net MVC。忘记在 foreach 中关闭 html <foo></foo>
导致了这个错误【参考方案2】:
对我来说,问题是这样的。
UserControl tempUIPart1Form = (UserControl)Page.LoadControl("UIPart1Form.ascx");
UserControl tempUIPart2Button = (UserControl)Page.LoadControl("UIPart2Button.ascx");
UIPart1Form.Controls.Add(tempUIPart1Form);
UIPart2Button.Controls.Add(tempUIPart2Button);
我使用的是变量名 tempUIPart1Form 和 tempUIPart2Button 而不是 UIPart1Form 和 UIPart2Button(控件的名称)。
由于某种原因,没有编译错误,但它确实崩溃并出现错误“System.Web.dll 中发生'System.***Exception'类型的未处理异常”
【讨论】:
以上是关于C#、Asp.Net Web 应用程序中出现奇怪的 System.***Exception 错误的主要内容,如果未能解决你的问题,请参考以下文章
如何在asp.net c# web应用程序中使用asp.net vb页面
在 ASP.NET C# Web 应用程序中使用 ADO.NET 和 XML
如何在 Web 应用程序(ASP.Net、C#、IIS)中进行文件上传
如果未使用 C# 登录 ASP.NET Web 表单,则将用户重定向到登录
为啥 .Mobile.cshtml 未在 ASP.NET Core C# Razor Pages Web 应用程序中呈现?