Tag: exception

更新Autofac后出现奇怪的exception

我之前有一个MVC4应用程序,我已经更新了Autofac版本,每件事都运行正常,现在我有这个奇怪的例外。 请帮忙!? Method not found: ‘Autofac.Builder.IRegistrationBuilder`3 Autofac.Builder.IRegistrationBuilder`3.InstancePerMatchingLifetimeScope(System.Object)’. Line 22: var builder = new ContainerBuilder(); Line 23: builder.RegisterFilterProvider(); Line 24: builder.Register(x => new AuthorizationService()).As().InstancePerHttpRequest(); Line 25: builder.Register(x => new HeaderRepository()).As().InstancePerHttpRequest(); Line 26: builder.Register(x => new PageBuilder()).As().InstancePerHttpRequest(); 堆栈跟踪: [MissingMethodException: Method not found: ‘Autofac.Builder.IRegistrationBuilder`3 Autofac.Builder.IRegistrationBuilder`3.InstancePerMatchingLifetimeScope(System.Object)’.] Autofac.Integration.Mvc.RegistrationExtensions.InstancePerHttpRequest(IRegistrationBuilder`3 registration) +0 Application.UI.Web.Services.HttpDependencyInjectionResolver.RegisterDependencies() in c:\Users\user\Documents\Visual Studio 11\Projects\MyProject\Application.UI.Web\Services\HttpDependencyInjectionResolver.cs:24 Application.UI.Web.MvcApplication.Application_Start() in c:\Users\user\Documents\Visual Studio 11\Projects\MyProject\Application.UI.Web\Global.asax.cs:42 […]

你如何看待在VS2015中使用Intellisense抛出哪些exception?

这已在VS2015 Update 1中得到解决和修复 有没有办法在VS2015中显示例外情况? VS2015 VS2013

在foreach条件下抛出exception

我有一个foreach循环,在foreach本身的情况下在循环中断开。 有没有办法try catch抛出exception然后继续循环的项目? 这将运行几次,直到exception命中然后结束。 try { foreach(b in bees) { //exception is in this line string += b; } } catch { //error } 这根本不会运行,因为exception是在foreach的条件下 foreach(b in bees) { //exception is in this line try { string += b; } catch { //error } } 我知道你们中的一些人会问这是怎么回事,所以这就是:Exception PrincipalOperationException被抛出,因为在GroupPrincipal (蜜蜂)中找不到Principal (在我的例子中为b)。 编辑:我添加了以下代码。 我还发现一个组成员指向一个不再存在的域。 我通过删除该成员轻松解决了这个问题,但我的问题仍然存在。 你如何处理在foreach条件下抛出的exception? PrincipalContext ctx […]

System.Web.Services.Protocols.SoapException:服务器无法识别HTTP标头SOAPAction的值:

当我尝试在Web服务上调用方法时,会发生exception: System.Web.Services.Protocols.SoapException: Server did not recognize the value of HTTP Header SOAPAction: http://localhost:53460/3Development/MyWebService.asmx/GetBasePath. at System.Web.Services.Protocols.Soap11ServerProtocolHelper.RouteRequest() at System.Web.Services.Protocols.SoapServerProtocol.RouteRequest(SoapServerMessage message) at System.Web.Services.Protocols.SoapServerProtocol.Initialize() at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing) Web服务的命名空间: [WebService(Namespace = “http://internaltest.temp.us/MyWebService.asmx”)] 我做了一些研究,发现这个exception流程是因为项目中引用的Web服务命名空间与服务器Web服务的命名空间不同,但我尝试删除Web引用并在项目中再次添加它,但结果仍然是相同。 我的情况类似于下面的文章: Server did not recognize the value of HTTP Header SOAPAction 来自文章: 所以基本上Web服务从http://foo.com/servicename转移到http://bar.com/servicename但是Web服务的“命名空间”仍然是http://foo.com/servicename,因为没有人改变了 问题是: 如何更改Web引用的命名空间?

Serilog的例外解构

Serilog有一种方便的方法来解析对象,如下例所示: logger.Debug(exception, “This is an {Exception} text”, exception); logger.Debug(exception, “This is an {@Exception} structure”, exception); 第一行导致记录器将exception记录为纯文本(通过调用ToString()),第二行使记录器将exception属性写为单独的字段。 但是这个重载呢: logger.Debug(exception, “This is an exception”, exception); 这个作为第一个参数使用exception,它总是写成一个字符串。 我想要做的是以结构化的方式启用日志记录exception。 是否可以配置Serilog来实现这一目标? UPDATE。 我想这个问题会导致记录exception的另一个方面:如何确保消息通过exception属性进行丰富(因此它们以结构化的方式记录到富散问件,如Elasticsearch),而无需将所有exception属性写入呈现的文本消息(所以纯文本记录器没有填满大量的exception细节)。

如果输入无效,是否可以抛出exception?

我有一个简单的ANLTR语法和随附的访问者。 除非输入无效,否则一切都很好。 如果输入无效,则吞下错误并且我的计算器输出错误。 我已经尝试实现一个错误监听器,而不是使用词法分析器的Recover方法,以及……好吧……今天还有其他几十件事。 有人可以告诉我如何简单地抛出错误而不是吞下糟糕的“代币”吗? (我使用引号,因为它们根本不是标记。我的语法中的字符未定义。) 有效输入: 1 + 2 * 3 – 4 输入无效: 1 + 2 + 3(4) 如果解析器/词法分析器遇到括号(或任何其他未定义的字符),我想抛出ArgumentException 。 目前,无效字符似乎只是消失在以太中,解析器就像没有错一样。 如果我使用grun命令在控制台中运行它,我会得到以下输出,因此它会在某个级别识别无效的标记。 第1:9行令牌识别错误:’(’ 第1:11行令牌识别错误:’)’ 这导致解析树。 BasicMath.g4 grammar BasicMath; /* * Parser Rules */ compileUnit : expression+ EOF; expression : expression MULTIPLY expression #Multiplication | expression DIVIDE expression #Division | expression ADD expression #Addition […]

C# – 当应用程序使用其他语言时,以英语获取exception消息?

我正在尝试本地化我的程序,但我希望发送给开发人员的错误消息以英文显示。 我无法找到一种方法来实现这一点,因为如果在抛出错误时将UI文化设置为另一种语言,则会抛出该语言。 由于我自己并没有编写这个程序,并且它非常大,我认为创建新的try catch块以尝试在发生错误或可能发生错误时将文化设置回英语是不切实际的。 目前,CurrentCulture和DefaultThreadCurrentCulture在整个应用程序中始终设置为英语,而CurrentUICulture设置为最终用户的语言。 当我解决方法时,我目前有一个函数已经遍历错误列表(使用System.Resources.ResourceSets(我假设是Windows错误,但我还需要一种方法来查找.NET错误,以便我可以迭代)这个字符串替换了其他语言中的匹配错误,并用它们的英语等价物替换它们,以便在应用程序崩溃时构建一个大的错误消息发送给开发人员。真的,我没有太多的翻译,因为大部分的message是服务器堆栈跟踪并显示抛出exception的位置。最大的问题是转换内部exception消息,有时是主exception消息,因为有时抛出的错误不会出现在ResourceSet中,有时会使用格式化项目,如'{0 }”。 这是我到目前为止翻译剩余错误的代码。 我仍在努力添加正则表达式模式来翻译使用“{0}”之类的错误,所以如果有人对此提出建议或更好的方法,我会很感激建议。 public static string TranslateExceptionMessageTest(string exmsg, Exception e, CultureInfo currentui) { CultureInfo test = Thread.CurrentThread.CurrentUICulture; string matchingstr = “”; string newstr = exmsg; string resourcecollection = “”; Assembly a = e.GetType().Assembly; ResourceManager rm = new ResourceManager(a.GetName().Name, a); ResourceSet rsOriginal = rm.GetResourceSet(currentui, true, true); ResourceSet rsTranslated = rm.GetResourceSet(new […]

格式化TimeSpans

我正在尝试使用以下代码行格式化TimeSpan : .ToString(“[d.]hh:mm:ss”) 它抛出一个FormatException ,但当我删除: , []和.时,exception消失了. 。 我也不能包含空格。 有谁知道为什么会这样? 在这个 msdn页面上,它清楚地表明您可以包含这些字符。 我正在使用.Net framework 4.5.2 btw。 谢谢。

如何阻止DevForce吞噬EntityManager.EntityChanged事件中的exception

这是来自DevForce论坛的线程的另一个延续。 问题是如果更改是由查询或导入触发的,DevForce将默默地吞下EntityManager.EntityChanged事件抛出的任何exception。 相关代码如下所示: internal virtual void OnEntityChanged(EntityChangedEventArgs args) { EventHandler entityChanged = this.EntityChanged; if (entityChanged == null) return; try { entityChanged(this, args); } catch { if (args.Action != EntityAction.AddOnQuery && args.Action != EntityAction.AddOnImport) { throw; } } } 正如论坛post中提到的,这种方法的行为已经改变了一点加class。 现在吞下的东西比我第一次抱怨时少。 但对于我们的应用程序,我们真的需要知道什么时候出错。 仅仅因为我在执行查询或导入操作时碰巧出错并不意味着我不关心exception。 在上一篇论坛post中,这种行为的理由是: 吞咽在AddOnQuery(和AddOnImport)期间抛出的exception的论点是“在查询中间失败通常不是开发人员实际想要的”,因为它更可能由于编写错误的事件处理程序而发生 也许我们不常见:-),但在我们的应用程序中,事件处理程序如下所示: EntityManager.EntityChanged += (sender, e) => { if (e.Action == EntityAction.AddOnAttach […]

MVC4 OAuth HasLocalAccount方法抛出InvalidOperationException

我有一个MVC4应用程序,它在本地花费调试过程而不启用Register External站点客户端(如twitter等)。 我正在使用自定义成员资格用户和角色提供程序。 但不幸的是,当我浏览“管理”页面时出现此错误: 由于对象的当前状态,操作无效。 并且堆栈跟踪: [InvalidOperationException:由于对象的当前状态,操作无效。] Microsoft.Web.WebPages.OAuth.OAuthWebSecurity.VerifyProvider()+91 Microsoft.Web.WebPages.OAuth.OAuthWebSecurity.HasLocalAccount(Int32 userId)+41 Melk .Controllers.AccountController.Manage(Nullable 1 message) in C:\Users\AmirMehr\documents\visual studio 2010\Projects\Melk\Melk\Controllers\AccountController.cs:141 lambda_method(Closure , ControllerBase , Object[] ) +153 System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +14 System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary 2 parameters)+211 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext) controllerContext,ActionDescriptor actionDescriptor,IDictionary 2 parameters) +27 System.Web.Mvc.Async.c__DisplayClass42.b__41() +28 System.Web.Mvc.Async.c__DisplayClass8 1.b__7(IAsyncResult )+10系统 .Web.Mvc.Async.WrappedAsyncResult 1.End() +57 System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +48 System.Web.Mvc.Async.c__DisplayClass39.b__33() +57 System.Web.Mvc.Async.c__DisplayClass4f.b__49() […]