gpt4 book ai didi

visual-studio-2013 - 为什么此 Typescript 接口(interface)会在运行时捆绑中导致空异常?

转载 作者:搜寻专家 更新时间:2023-10-30 21:07:31 24 4
gpt4 key购买 nike

我在 VS 2013 中启动了一个新的 MVC Razor 测试 Web 项目。我将所有 NuGet 包更新到今天的最新版本,并开始包括我来自另一个项目的 TypeScript 插件以进行测试。其中一个插件导致了这个运行时错误:

堆栈跟踪错误:

Object reference not set to an instance of an object. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:
Line 39: @Scripts.Render("~/bundles/jquery")
Line 40: @Scripts.Render("~/bundles/bootstrap")
Line 41: @Scripts.Render("~/bundles/ListView")
Line 42: @RenderSection("scripts", required: false)
Line 43: </body>
Stack Trace:

[NullReferenceException: Object reference not set to an instance of an object.]
Microsoft.Ajax.Utilities.JSParser.ParseUnaryExpression(Boolean& isLeftHandSideExpr, Boolean isMinus) +298
Microsoft.Ajax.Utilities.JSParser.ParseExpressionStatement(Boolean fSourceElement) +125
Microsoft.Ajax.Utilities.JSParser.ParseStatement(Boolean fSourceElement, Boolean skipImportantComment) +1552
Microsoft.Ajax.Utilities.JSParser.ParseBlock() +164
Microsoft.Ajax.Utilities.JSParser.ParseStatement(Boolean fSourceElement, Boolean skipImportantComment) +498
Microsoft.Ajax.Utilities.JSParser.ParseLabeledStatement(Lookup lookup, Boolean fSourceElement) +543
Microsoft.Ajax.Utilities.JSParser.ParseExpressionStatement(Boolean fSourceElement) +226
Microsoft.Ajax.Utilities.JSParser.ParseStatement(Boolean fSourceElement, Boolean skipImportantComment) +1552
Microsoft.Ajax.Utilities.JSParser.ParseBlock() +164
Microsoft.Ajax.Utilities.JSParser.ParseStatement(Boolean fSourceElement, Boolean skipImportantComment) +498
Microsoft.Ajax.Utilities.JSParser.ParseBlock() +164
Microsoft.Ajax.Utilities.JSParser.ParseStatement(Boolean fSourceElement, Boolean skipImportantComment) +498
Microsoft.Ajax.Utilities.JSParser.ParseStatements(Block block) +159
Microsoft.Ajax.Utilities.JSParser.InternalParse() +1011
Microsoft.Ajax.Utilities.JSParser.Parse(DocumentContext sourceContext) +123
Microsoft.Ajax.Utilities.JSParser.Parse(DocumentContext sourceContext, CodeSettings settings) +54
Microsoft.Ajax.Utilities.Minifier.MinifyJavaScript(String source, CodeSettings codeSettings) +987
System.Web.Optimization.JsMinify.Process(BundleContext context, BundleResponse response) +310
System.Web.Optimization.Bundle.ApplyTransforms(BundleContext context, String bundleContent, IEnumerable`1 bundleFiles) +263
System.Web.Optimization.Bundle.GenerateBundleResponse(BundleContext context) +355
System.Web.Optimization.Bundle.GetBundleResponse(BundleContext context) +104
System.Web.Optimization.BundleResolver.GetBundleContents(String virtualPath) +254
System.Web.Optimization.AssetManager.DeterminePathsToRender(IEnumerable`1 assets) +252
System.Web.Optimization.AssetManager.RenderExplicit(String tagFormat, String[] paths) +75
System.Web.Optimization.Scripts.RenderFormat(String tagFormat, String[] paths) +292
System.Web.Optimization.Scripts.Render(String[] paths) +51
ASP._Page_views_shared__LayoutHome_cshtml.Execute() in e:\HiTechMagic\iCollectIt\iCollectIt.CloudServices\iCollectit.Collector.WebApplication\Views\Shared\_LayoutHome.cshtml:41
System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +271
System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +120
System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +145
System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer) +41
System.Web.WebPages.<>c__DisplayClass7.<RenderPageCore>b__6(TextWriter writer) +335
System.Web.WebPages.HelperResult.WriteTo(TextWriter writer) +42
System.Web.WebPages.WebPageExecutingBase.WriteTo(TextWriter writer, HelperResult content) +45
System.Web.WebPages.WebPageBase.Write(HelperResult result) +53
System.Web.WebPages.WebPageBase.RenderSurrounding(String partialViewName, Action`1 body) +178
System.Web.WebPages.WebPageBase.PopContext() +347
System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +154
System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance) +695
System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer) +382
System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +431
System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) +39
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +116
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +529
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +106
System.Web.Mvc.Async.<>c__DisplayClass2b.<BeginInvokeAction>b__1c() +321
System.Web.Mvc.Async.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult) +185
System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +42
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +133
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +56
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +40
System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +34
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +70
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +139
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +59
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +40
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +44
System.Web.Mvc.Controller.<BeginExecute>b__15(IAsyncResult asyncResult, Controller controller) +39
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +62
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +139
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +59
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +40
System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +39
System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +39
System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +39
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +70
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +139
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +59
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +40
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +40
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +38
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9688704
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155

我删除了所有代码和文件,直到我将范围缩小到一个失败的示例:

BundleConfig.cs

bundles.Add(new ScriptBundle("~/bundles/ListView").Include(
"~/Scripts/Vero/reorder.ts"));

重新排序.ts

module Plugins
{
export interface IReorderOptions
{
onChange: { (): void; }; // Function to call after update
}
}

母版页_LayoutHome.cshtml:

<!DOCTYPE html>
<html>
[SNIP]
<body>
[SNIP]

@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/bootstrap")
@Scripts.Render("~/bundles/ListView")
@RenderSection("scripts", required: false)
</body>
</html>

我的主页/索引引用母版页:

@{
ViewBag.Title = "Home Page";
Layout = "~/views/shared/_layoutHome.cshtml";
}

基本上,构建 JS 输出/ bundle 的代码似乎打破了我的函数接口(interface)声明,但我找不到它的模式。

完整的插件在以前的 Web 应用程序中运行良好,因此我怀疑其中一个 NuGet/VS 工具已更改。 reorder.js 输出文件明显是空的,所以看起来可能是 TypeScript 解析。

我希望堆栈跟踪(上图)和日志(下图)能提供线索。我希望这实际上是我遗漏或在声明中做错的事情。

输出日志(最后一部分由于 SO 大小限制):

'C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\8d1fcf70\6d8beac0\App_Web_2rxc12vp.dll'. 
'iisexpress.exe' (CLR v4.0.30319: /LM/W3SVC/44/ROOT-1-130403001817617541): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Dynamic\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Dynamic.dll'. Cannot find or open the PDB file.
A first chance exception of type 'Microsoft.CSharp.RuntimeBinder.RuntimeBinderException' occurred in Microsoft.CSharp.dll
A first chance exception of type 'Microsoft.CSharp.RuntimeBinder.RuntimeBinderException' occurred in Microsoft.CSharp.dll
'iisexpress.exe' (CLR v4.0.30319: /LM/W3SVC/44/ROOT-1-130403001817617541): Loaded 'C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\8d1fcf70\6d8beac0\App_Web_fivluysz.dll'.
A first chance exception of type 'Microsoft.CSharp.RuntimeBinder.RuntimeBinderException' occurred in Microsoft.CSharp.dll
A first chance exception of type 'Microsoft.CSharp.RuntimeBinder.RuntimeBinderException' occurred in Microsoft.CSharp.dll
A first chance exception of type 'System.NullReferenceException' occurred in WebGrease.dll
A first chance exception of type 'System.NullReferenceException' occurred in WebGrease.dll
A first chance exception of type 'System.NullReferenceException' occurred in System.Web.Mvc.dll
A first chance exception of type 'System.NullReferenceException' occurred in System.Web.Mvc.dll
'iexplore.exe' (Script): Loaded 'Script Code (Windows Internet Explorer)'.
The program '[6296] iexplore.exe' has exited with code 0 (0x0).
The program '[11616] iisexpress.exe' has exited with code 0 (0x0).

最佳答案

答:确保你总是引用 .js 文件(而不是 .ts)!

希望这个问题和答案可能对其他犯了和我一样的愚蠢错误并得到同样无用的错误消息的人有用!

我不小心在 bundle 中引用了 .ts 文件而不是 .js 文件...仅在一个插件(损坏的那个)上。我的所有更改都没有解决现在非常明显的问题。

噢! :)

关于visual-studio-2013 - 为什么此 Typescript 接口(interface)会在运行时捆绑中导致空异常?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22657178/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com