Tag: error handling

无法在网页上评估表达式….

与此问题相关: 无法计算表达式,因为代码已优化或本机框位于调用堆栈之上 我目前在我的例外中看到这个: {无法评估表达式,因为代码已优化或本机框架位于调用堆栈之上。} 这是有问题的代码。 在response.End();上抛出exception DataSet dataSet = new DataSet(); dataSet.Tables.Add(table); // Table is a well-formatted DataTable formed from data stored in a Session variable HttpResponse response = HttpContext.Current.Response; response.Clear(); response.Charset = “”; response.ContentType = “application/vnd.ms-excel”; response.AddHeader(“Content-Disposition”, “attachment;filename=\”ExcelFile.xls\””); using (StringWriter stringWriter = new StringWriter()) using (HtmlTextWriter htmlTextWriter = new HtmlTextWriter(stringWriter)) { DataGrid dataGrid = […]

当我引用windows.phone时,“在模块mscorlib.dll中找不到类型system.systemexception”

我在Windows Phone 8.1上用c#编码,我需要播放.mp3文件。 我知道这样做的唯一简单方法是通过“Microsoft.Phone.BackgroundAudio”引用。 但是,当我尝试通过对象浏览器引用“Microsoft.Phone”时,它会抛出错误“无法在模块mscorlib.dll中找到类型system.systemexception”。 以下是相关代码: using Microsoft.Phone.BackgroundAudio; 当我使用这个我得到“模块mscorlib.dll中找不到类型system.systemexception”错误。 如果我尝试使用BackgroundAudio的函数,稍后在脚本中,它显然会抛出错误并询问引用。 但是参考不起作用。 我尝试了一个完整的重新安装,当我研究这个问题时,在stackoverflow上建议。 任何帮助将非常感激。 谢谢!

错误:无法将类型为“System.Int32”的对象强制转换为“System.String”

我已完成编码注册页面,登录,现在UpdateCustomer页面有错误 – 背景信息:我使用Microsoft Access作为数据源 LabelState.Text = (string)Session[“sState”]; LabelPostalCode.Text = (string)Session[“sPostalCode”]; LabelContactNumber.Text = (string)Session[“sContactNumber”]; LabelEmail.Text = (string)Session[“sEmail”]; LabelPassword.Text = (string)Session[“sPassword”]; 这里的一切都很好,除了LabelContactNumber.Text = (string)Session[“sContactNumber”] 。 我相信这是因为只有Access中的ContactNumber被设置为Int,其余的是Text,因此当我使用(字符串)时没有错误。

从tempdata查看Asp.Net Mvcexception

我在Base控制器中处理错误。 我需要在剃刀视图中显示存储在tempdata,Exception类型中的错误。 我怎样才能做到这一点? 基本控制器代码 protected override void OnException(ExceptionContext filterContext) { // if (filterContext.ExceptionHandled) // return; //Let the request know what went wrong filterContext.Controller.TempData[“Exception”] = filterContext.Exception.Message; //redirect to error handler filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary( new { controller = “Error”, action = “Index” })); // Stop any other exception handlers from running filterContext.ExceptionHandled = true; // […]

捕获.aspx和.ascx页面中的exception

问题说明了一切,拿这个例子代码: 现在,如果在这些控件(位于母版页中)的某个位置抛出错误,它们将取消整个站点,如何捕获这些exception?

C# – ObjectContext实例已被释放,不能再用于需要连接的操作

我很抱歉重复。 我正朝着同样的问题前进,但仍无法处理它。 我正在使用Angularjs框架和Asp.net mvc。 我的class级: public partial class Person { public int PersonID { get; set; } public string FirstName { get; set; } public string LastName { get; set; } public string Telephone { get; set; } public string Adress { get; set; } public int UserID { get; set; } public virtual User […]

如何从HttpResponseMessage检索传递的exception(HttpStatusCode,Exception)

根据以下网站,您可以将exception参数传递给HttpResponseMessage.CreateErrorResponse方法( https://msdn.microsoft.com/en-us/library/jj127064(v=vs.118).aspx ) 我的问题是如何从CreateErrorResponse方法创建的HttpResponseMessage中检索exception信息。 如果无法获取exception信息,那么将exception作为输入进行方法重载的重点是什么? 澄清我不想要的答案……我知道我可以在身体内容中传递一个自定义的错误原因( http://weblogs.asp.net/fredriknormen/asp-net-web-api-exception处理 )但我真的很好奇如何使用HttpRequestMessageExtensions.CreateErrorResponse方法(HttpRequestMessage,HttpStatusCode, Exception )方法重载。 示例WebAPI控制器: Route(“location/{locationName}/Databases/{databasename}/ProcedureSession”)][LocationSetUp] public HttpResponseMessage Post([FromBody] ProcedureSessionData procedureSession) { try { throw new Exception(“test Exception”); } catch (Exception e) { return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e); } } 如何在此代码中选择exception: using (var client = new HttpClient()) { client.BaseAddress = new Uri(“http://localhost/”); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(“application/json”)); string api = “testApi/location/here/databases/testDb/ProcedureSession”; HttpResponseMessage response […]

我想念C#中Visual Basic的“On Error Resume Next”。 我现在该如何处理错误?

在Visual Basic中,我在程序的头部编写了On Error Resume Next ,并在整个项目中抑制了错误。 在C#中我非常想念这个function。 对于每个程序而言,通常的try-catch处理不仅非常耗时,而且会带来不希望的效果。 如果遇到错误,即使已处理,代码也不会从发生的位置继续 。 使用On Error Resume Next ,代码从错误点继续,仅跳过导致错误的函数调用。 我还没有深入参与C#,但也许C#中存在比原始try-catch更好的error handling。 我还想知道发生错误的模块或函数名称以及错误消息中的行号。 到目前为止, Exception类没有提供这些function。 任何想法(当然,托管,不涉及我自己的应用程序上的任何流程类)? 你如何处理大项目中的错误? 我希望我不必为每个方法添加try-catch 。 不知何故C#抛出了许多错误 – 这似乎是该语言的典型。 我发现我的解决方案可以解决我的几个问题: public partial class Form1 : Form { public Form1() { InitializeComponent(); } [STAThread] static void Main() { Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException); //setup global error handler Application.Run(new Form1()); […]

C#最佳实践error handling和传递错误消息

我正在使用asp.net,我总是在努力寻找一种处理错误的简洁方法,如果有的话,将错误消息传递给用户。 例如,我有一个User类,UserManager类和一个Database类。 Imagina我想显示所有用户,显示我从UserManager调用方法GetAllUsers返回User对象列表。 此方法创建一个Database对象并调用方法ExecuteQuery(字符串查询)。 编辑:现在我的问题,想象一下ExecuteQuery()方法出错(无法打开数据库)。 我想在打开数据库连接时通知用户出错了。 我应该怎么做并处理这个整洁的方式? 编辑2: 你会这样做吗? 或者其他? public class Database() { private string _Error; // property error (only get) private void Open() { try { // Open DB // Fails because of error } catch(Exception ex) { _Error = ex.Message; } } public DataSet ExecuteQuery(string query) { try { Open(); // Execute […]

带布局的自定义错误页面

我一直在努力让自定义错误页面工作,并继续寻找回到简单使用静态页面的方法。 虽然静态页面有效,但它需要重新构建我们希望在此时避免的导航栏。 我目前正在使用以下内容指定自定义错误页面。 Asp.neterror handling IISerror handling 有没有一种方法可以实现动态自定义错误页面,可以处理IIS错误和Asp.net错误?