- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我遇到一个问题,移动设备上的用户在 MVC 中遇到错误,而在普通桌面上查看网站时不会发生这种错误。通过使用 Chrome 的开发者工具并应用任何其他非默认 UA,我可以始终如一地重现错误。
抛出的底层异常是: ArgumentException: Illegal characters in path.
at System.IO.Path.CheckInvalidPathChars(String path, Boolean checkAdditional)
at System.IO.Path.GetExtension(String path)
at System.Web.WebPages.DefaultDisplayMode.TransformPath(String virtualPath, String suffix)
at System.Web.WebPages.DefaultDisplayMode.GetDisplayInfo(HttpContextBase httpContext, String virtualPath, Func'2 virtualPathExists)
at System.Web.WebPages.DisplayModeProvider.GetDisplayInfoForVirtualPath(String virtualPath, HttpContextBase httpContext, Func'2 virtualPathExists, IDisplayMode currentDisplayMode, Boolean requireConsistentDisplayMode)
at System.Web.Mvc.VirtualPathProviderViewEngine.GetPathFromGeneralName(ControllerContext controllerContext, List'1 locations, String name, String controllerName, String areaName, String cacheKey, String[]& searchedLocations)
at System.Web.Mvc.VirtualPathProviderViewEngine.GetPath(ControllerContext controllerContext, String[] locations, String[] areaLocations, String locationsPropertyName, String name, String controllerName, String cacheKeyPrefix, Boolean useCache, String[]& searchedLocations)
at System.Web.Mvc.VirtualPathProviderViewEngine.FindPartialView(ControllerContext controllerContext, String partialViewName, Boolean useCache)
at System.Web.Mvc.ViewEngineCollection.<>c__DisplayClass2.<FindPartialView>b__1(IViewEngine e)
at System.Web.Mvc.ViewEngineCollection.Find(Func'2 lookup, Boolean trackSearchedPaths)
at System.Web.Mvc.ViewEngineCollection.FindPartialView(ControllerContext controllerContext, String partialViewName)
at System.Web.Mvc.Html.TemplateHelpers.ExecuteTemplate(HtmlHelper html, ViewDataDictionary viewData, String templateName, DataBoundControlMode mode, GetViewNamesDelegate getViewNames, GetDefaultActionsDelegate getDefaultActions)
at System.Web.Mvc.Html.TemplateHelpers.TemplateHelper(HtmlHelper html, ModelMetadata metadata, String htmlFieldName, String templateName, DataBoundControlMode mode, Object additionalViewData, ExecuteTemplateDelegate executeTemplate)
at System.Web.Mvc.Html.TemplateHelpers.TemplateHelper(HtmlHelper html, ModelMetadata metadata, String htmlFieldName, String templateName, DataBoundControlMode mode, Object additionalViewData)
at System.Web.Mvc.Html.TemplateHelpers.TemplateFor[TContainer,TValue](HtmlHelper'1 html, Expression'1 expression, String templateName, String htmlFieldName, DataBoundControlMode mode, Object additionalViewData, TemplateHelperDelegate templateHelper)
at System.Web.Mvc.Html.TemplateHelpers.TemplateFor[TContainer,TValue](HtmlHelper'1 html, Expression'1 expression, String templateName, String htmlFieldName, DataBoundControlMode mode, Object additionalViewData)
at System.Web.Mvc.Html.DisplayExtensions.DisplayFor[TModel,TValue](HtmlHelper'1 html, Expression'1 expression)
使用 fiddler,将成功的请求与失败的请求进行比较时,请求的唯一区别是用户代理(以及 jQuery 作为查询字符串参数的一部分附加的缓存消除器)。
为什么只更改 UA 会导致此异常?如果不针对每个可能发生的地方在系统中编写特定的解决方法,我如何才能避免此问题?
最佳答案
我遇到了完全相同的问题,并已解决。
我的问题原来是在我的 View 模型中使用了 yield
block :
Controller :
var vm = new BigVM {
SmallVMs = BuildSmallOnes()
};
return View(vm);
private IEnumerable<SmallVM> BuildSmallOnes()
{
// complex logic
yield return new SmallVM(1);
yield return new SmallVM(2);
}
查看:
@model BigVM
@Html.DisplayFor(x => x.SmallVMs) <-- died
令人费解的是,这适用于台式机,但适用于 iPad 和 iPhone,引用了完全相同的堆栈跟踪。类似问题被举报here和 here .通过添加 .ToList()
调用解决了该问题,因此:
var vm = new BigVM {
SmallVMs = BuildSmallOnes().ToList()
};
大概编译器生成的表示 yield block 的类包含一些用户代理不喜欢的字符。包括 ToList() 调用使用 List<> 代替。
关于c# - 用户代理导致 MVC DisplayFor ArgumentException : Illegal characters in path,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27487032/
我有一个存储过程,我正在尝试使用 Dapper 执行该过程,该过程引发了一个错误,该错误似乎与我正在尝试做的事情无关,尽管我似乎无法弄清楚我在做什么错误的。 这是我试图调用的存储过程的签名: ALTE
我想匹配浏览器游戏中的坐标。我的正则表达式是: try { Regex r = new Regex("Mond ([1-9]) \x5B([1-
任何人都可以向我解释为什么我从这段代码中收到 ArgumentException 吗?它告诉我 Task.WhenAll 函数中的 tasks 参数包含空值。但是,它只是在我运行它时偶尔发生一次。 s
我正在尝试为 Eddystone 信标做广告,但我的代码在 advertisementData.Data 处失败并出现 ArgumentException: Value does not fall w
我已经编写了一些代码来从我的 Blogger 博客中导入内容。下载完所有 HTML 内容后,我将浏览图像标签并下载相应的图像。在大量情况下,System.Drawing.Bitmap.FromStre
我正在尝试更加熟悉表达式树。 我创建了一个简单的 switch 表达式,如下所示: var paramExp = Expression.Parameter(typeof(int)); Expressi
我正在尝试使用任务并行库逐个单元地构建矩阵。 我有以下代码可以执行此操作: List campaigns = GetHomeCampaigns(); Dictionary sellers = GetH
我试图通过添加三个参数来调用存储过程,但在添加第二个参数时出现以下 ArgumentException The SqlParameter is already contained by another
因为 CultureInfo 没有从一个线程复制到另一个线程,所以我使用了以下方法来为我做这件事。 public static StartCustomTask(Action action, TaskC
在我的代码中,我怎样才能显示弹出的警告框?我试图重播抛出新的参数异常并添加 Response.Write("alert('NOT Successful');");但它表明我在附近有语法错误”)”。如果
我有一个通过串行端口连接到设备的实用程序。为了测试这个应用程序,我正在为该设备编写一个模拟器。 这两个应用程序旨在在同一台 Windows 7 机器上运行。 我正在用 C# 编写模拟器。我使用 com
据我所知,ArgumentExceptions 通常是这样使用的: public void UpdateUser(User user) { if (user == null) throw ne
我有一个采用三个参数(3D 点)的方法。如果这些点是共线的,我想抛出一个异常。对我来说明显的异常(exception)是 ArgumentException,但最好的做法是在构造函数中包含参数名称。在
我正在使用 Path.Combine , 并且其中一个字符串包含 Unicode 字符。我收到 {System.ArgumentException} exception; illegal charac
当我尝试合并两个字典时,我不知道如何将键和值保留在字典中。由于 key 重复,我不断收到 ArgumentException。当键匹配时,我只想通过 =+ kvp.value; 添加值 我有一个字典列
当构造一个 ArgumentException 时,一些重载采用一个字符串作为无效参数的参数名称。我认为每当我更改方法的参数名称时不必记住更新此 ctor 参数会很好。有没有一种简单的方法可以使用反射
当我尝试合并两个字典时,我不知道如何将键和值保留在字典中。由于 key 重复,我不断收到 ArgumentException。当键匹配时,我只想通过 =+ kvp.value; 添加值 我有一个字典列
我想使用XamarinUITest在Xamarin上测试IOS应用程序。 不幸的是,我无法在本地设备上启动任何东西。 我已成功在Android上进行测试,但IOS似乎是一个全新的谜。 其实我有一个错误
我们的 SonarQube 经常在我们的代码中提出以下问题(代码异味):“用于 ArgumentException 的参数名称应与现有参数名称匹配”。 Here是触发此问题的规则。 触发此问题的示例如
在安装 WebActivatorEx nuget 包后尝试访问页面时,我不断收到以下 ArgumentException。 Server Error in '/PharmaDotnet/ux' App
我是一名优秀的程序员,十分优秀!