草庐IT

custom-exceptions

全部标签

c# - Visual Studio - 抑制某些 "Exception thrown"消息

您能否在某些方法(某些代码区域)的输出中隐藏“抛出异常”消息?我使用HttpWebRequest进行服务器通信。我定期检查服务器是否可用(每秒几次)。当服务器不可访问时,HttpWebRequest会抛出异常。我捕获它并将启用的GUI元素设置为false。问题是当服务器无法访问时,输出窗口会被“抛出的异常”消息弄得乱七八糟。我知道您可以右键单击输出窗口并取消选中“异常消息”。但我不仅是一个从事该项目的人,而且可能有人希望看到一些其他异常消息(在他们的项目部分)。我需要的例子://Keepshowing"Exceptionthrown"messageinthismethod.static

c# - 验证 JWT 签名时出现 SecurityTokenSignatureKeyNotFoundException

我正尝试为我的组织实现OpenIDConnect规范。我在测试依赖方应用程序中使用Microsoft的OpenIDConnectOWIN实现来验证我的协议(protocol)实现。我公开了以下元数据文档:{"issuer":"https://acs.contoso.com/","authorization_endpoint":"http://localhost:53615/oauth2/auth","token_endpoint":"http://localhost:53615/oauth2/token","userinfo_endpoint":"http://localhost:53

c# - 模拟 DataReader 并获取 Rhino.Mocks.Exceptions.ExpectationViolationException : IDisposable. Dispose();预期#0,实际#1

我正在尝试模拟一个SqlDataReaderSqlDataReaderreader=mocks.CreateMock();Expect.Call(reader.Read()).Return(true).Repeat.Times(1);Expect.Call(reader.Read()).Return(false);Expect.Call(reader.HasRows).Return(true);Expect.Call(reader.Dispose);Expect.Call(reader["City"]).Return("Boise");Expect.Call(reader["State

c# - 为什么堆栈在 Exception.StackTrace 中被截断?

为什么堆栈的高位部分(在Exception.StackTrace中)被截断?让我们看一个简单的例子:publicvoidExternalMethod(){InternalMethod();}publicvoidInternalMethod(){try{thrownewException();}catch(Exceptionex){//ex.StackTraceheredoesn'tcontainExternalMethod()!}}这似乎是“设计使然”。但是这样奇怪的设计的原因是什么?它只会使调试变得更加复杂,因为在日志消息中我无法理解是谁调用了InternalMethod(),而通常

c# - ASP.NET MVC3 : Set custom IServiceProvider in ValidationContext so validators can resolve services

2012年12月18日更新由于这个问题似乎有很多观点,我应该指出,接受的答案不是我使用的解决方案,但它确实提供了构建解决方案的链接和资源,但是,对我来说请注意,这不是理想的解决方案。我的回答包含MVC框架标准部分的替换;并且您应该只在您愿意检查它们是否仍适用于future版本时才使用它们(一些私有(private)代码已从官方来源中删除,因为基类中没有足够的可扩展性)。不过,我可以确认这两个类也适用于Asp.NetMVC4和3。也可以为Asp.NetWebAPI框架重复类似的实现,这是我最近完成的。结束更新我的类型有很多“标准”验证(必需等),但也有一些自定义验证。某些验证需要获取服务

c# - 捕捉 System.Exception 总是不好的做法吗?

请考虑以下代码,它抛出三种不同的异常(即System.Configuration.ConfigurationErrorsException、System.FormatException和System.OverflowException):intSomeInt=Convert.ToInt32(ConfigurationManager.AppSettings["SomeIntValue"]);异常是不同的,所以在实践中我应该有三个不同的catchblock来处理每个特定的异常。但是,在这种特殊情况下,所有异常的处理方式都相同:将日志写入事件查看器,并显示一条通知配置错误的消息......在

c# - 如何: Use async methods with LINQ custom extension method

我有一个LINQ自定义扩展方法:publicstaticIEnumerableDistinctBy(thisIEnumerableitems,Funcproperty){returnitems.GroupBy(property).Select(x=>x.First());}我是这样使用它的:varspc=context.pcs.DistinctBy(w=>w.province).Select(w=>new{abc=w}).ToList();但问题是我不想要ToList()我想要这样的东西varspc=awaitcontext.pcs.DistinctBy(w=>w.province).

c# - ASP.NET Core 2.0 预览版 1 : How to set up Cookie Authentication with custom login path

在ASP.NETCore2.0中,.UseAuthentication()中间件有一个重大更改,不再允许oldsyntaxmentionedhere去工作。新版本似乎在addAuthentication中处理配置,但我无法在任何地方找到任何关于如何更改指定自定义登录和注销url的旧代码的详细信息。services.AddAuthentication(o=>{//WherecanIspecifythis?????varopt=newCookieAuthenticationOptions(){LoginPath="/api/login",LogoutPath="/api/logout",}

c# - string.split() "Out of memory exception"读取制表符分隔文件时

我在我的C#代码中使用string.split()来读取制表符分隔的文件。我正面临下面代码示例中提到的“OutOfMemory异常”。这里我想知道为什么文件大小为16MB时会出现问题?这是正确的方法吗?using(StreamReaderreader=newStreamReader(_path)){//...........Loadthefirstlineofthefile................stringheaderLine=reader.ReadLine();MeterDataIPValueListobjMeterDataList=newMeterDataIPValueL

c# - 起订量参数 TargetParameterCountException : Parameter count mismatch Exception

以下是我的通用基础存储库界面publicinterfaceIRepository{IQueryableAllIncluding(paramsExpression>[]includeProperties);}我的实体publicclassSdk{publicSdk(){this.Identifier=Guid.NewGuid().ToString();}publicvirtualICollectionAccessibleResources{get;set;}publicstringIdentifier{get;set;}}下面是具体的repopublicinterfaceISdkRepo