问题标签 [nullreferenceexception]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
113 浏览

model-view-controller - 在 IIS7 上使用 MVC 时的上下文、成员资格等 Null

我敢肯定这一定是我想念的简单东西。

我在我的表单应用程序中使用 MVC 路由进行 URL 路由。在大多数表单上,我访问上下文、成员资格等。

在我的开发机器和 IIS6 上一切正常。

我只是想开始在 IIS7 上工作,但没有运气。路由可以正常工作,但是每当我尝试访问上下文或成员资格时,我都会得到一个空值。在路由的某个地方,这些值没有通过。

任何想法将不胜感激!

0 投票
1 回答
9487 浏览

c# - 为什么 ResourceManager.GetResourceSet 在构建后的第一个请求上返回 null?(C#)

我正在开发一个用 C# (asp.net) 构建的大型 Web 应用程序。我有一个简单的 aspx 页面,它为客户端浏览器提供本地化字符串,以便在 javascript 控件中使用。要获取字符串,我执行以下操作:

这一切都很好,除了在清理/构建或重建之后立即对页面的第一个请求(如果我只是进行一些更改,然后构建,它工作正常)。因此,在第一个请求中,当我尝试迭代 ResourceSet 时,我得到了一个空引用异常。但是,如果我在出现错误后刷新页面,那么从那时起它就可以正常工作了。

有谁知道为什么会发生这种情况?

0 投票
3 回答
1112 浏览

c# - 设置对象成员时出现 NullReferenceException

运行以下程序时出现 NullReferenceException。我认为问题出在我正在创建一个Line包含Point该类的事实。

0 投票
2 回答
264 浏览

c# - XML 操作中的 NullReference

NullReferenceException在尝试读取 xml 文件的属性时遇到了问题——从用户输入定义的元素中读取的属性。

StackTrace 不断将我重定向到这一行(标记)

我在哪里错过了重点?这里缺少什么参考?我想不通...

编辑:元素存在,属性也存在(包括值)

进一步说明:_Arguments[]是用户输入的拆分数组。用户例如输入test1_read- 被拆分为_Arguments[0] = "test"_Arguments[1] = "read"

0 投票
0 回答
1433 浏览

c# - OnListChanged 中的 DataView NullReferenceException

我有一个相当复杂的 WinForms 应用程序,它使用数据绑定将强类型的 DataTables 绑定到控件(不确定这个事实在这里是否重要)。当对列的更改触发更新同一行上的另一列的逻辑时会引发异常(或者至少这是我的理论)。

一个示例:客户记录绑定到一个 ComboBox,其中包含 Customer::MarketingContactId 的联系人列表。当联系人更改时,有几个文本框和复选框将更新以允许编辑该联系人的详细信息。其中一个复选框在 CheckChanged 上有一个事件处理程序

m_row 是正在更新的客户。虽然此代码中不会发生错误,但实际上是由 MarketingContactId 字段的设置引发的。这是调用堆栈,它证实了这一点:

System.Data.dll!System.Data.DataView.OnListChanged(System.ComponentModel.ListChangedEventArgs e = {System.ComponentModel.ListChangedEventArgs}) 第 1433 行 + 0x2c 字节 C# System.Data.dll!System.Data.DataView.IndexListChanged(object sender, System.ComponentModel.ListChangedEventArgs e = {System.ComponentModel.ListChangedEventArgs}) 第 1299 行 C# System.Data.dll!System.Data.DataView.IndexListChangedInternal(System.ComponentModel.ListChangedEventArgs e) 第 1324 行 C#
System.Data.dll! System.Data.DataViewListener.IndexListChanged(System.ComponentModel.ListChangedEventArgs e) 第 76 行 + 0x7 字节 C#
System.Data.dll!System.Data.Index.OnListChanged.AnonymousMethod(System.Data.DataViewListener listener, System.ComponentModel.ListChangedEventArgs args , bool arg2, bool arg3) 第 803 行 + 0x7 字节 C#
System.Data.dll!System.Data.Listeners.Notify(System.ComponentModel.ListChangedEventArgs arg1 = {System.ComponentModel.ListChangedEventArgs}, bool arg2 = false, bool arg3 = false, System.Data.Listeners.Action action = {Method = {Void b__2(System.Data.DataViewListener, System.ComponentModel.ListChangedEventArgs, Boolean, Boolean)}}) 第 1029 行 + 0x1a 字节 C# System.Data.dll!System.Data.Index.OnListChanged(System.ComponentModel.ListChangedEventArgs e ) 第 805 行 C# System.Data.dll!System.Data.Index.OnListChanged(System.ComponentModel.ListChangedType changedType, int newIndex, int oldIndex) 第 788 行 C# System.Data.dll!System.Data.Index.RecordStateChanged(int oldRecord , System.Data.DataViewRowState oldOldState, System.Data.DataViewRowState oldNewState, int newRecord, System.Data.DataViewRowState newOldState, System.Data。DataViewRowState newNewState) 第 903 行 + 0x10 字节 C#
System.Data.dll!System.Data.DataTable.RecordStateChanged(int record1 = 0, System.Data.DataViewRowState oldState1 = 添加, System.Data.DataViewRowState newState1 = None, int record2 = 1, System.Data.DataViewRowState oldState2 = None , System.Data.DataViewRowState newState2 = 已添加) 第 3473 行 + 0x18 字节 C# System.Data.dll!System.Data.DataTable.SetNewRecordWorker(System.Data.DataRow row = "CustomerRow: Id:-1", int建议记录,系统.Data.DataRowAction action = Change, bool isInMerge, int position, bool fireEvent = true, out System.Exception deferredException = null) Line 3935 + 0x16 bytes C#
System.Data.dll!System.Data.DataTable.SetNewRecord(System.Data.DataRow 行,int建议记录,System.Data.DataRowAction 动作,bool isInMerge,bool fireEvent)第 3824 行 C# System.Data.dll!System.Data。 DataRow.SetNewRecord(int record) Line 1160 C# System.Data.dll!System.Data.DataRow.EndEdit() Line 631 + 0xa bytes C#
System.Data.dll!System.Data.DataRow.this[System.Data.DataColumn ].set(System.Data.DataColumn 列,对象值) 第 343 行 C#

行号在那里,因为我从 Visual Studio 的 MS 符号服务器功能为 System.Data.dll 加载了符号。有了这些数据,我可以进一步跟踪 OnListChanged 方法的这一部分的错误:

如果只是在检查 onListChanged != null 之后,显然出现了问题。我怀疑在 EndEdit 方法期间更新 DataRow 会触发此操作。当然,一个简单的沙箱来隔离这个问题并没有为我重现错误。SO上的其他人是否遇到过此错误,如果是,您是如何解决的?

我现在的任务是将 MarketingContactIsFulltimeChangedHandler 中的 BeginInvoke 调用到另一个在那里执行 CreditLevel 逻辑的方法。

0 投票
3 回答
2527 浏览

c# - XmlDocument C# 遇到问题

我无法让我的程序正确读取这个 XML 文件,它也需要写入它,但还没有。请注意,这只是代码的一小部分

我还取出了 try 语句,这样我就不必添加 catch

下面是它试图读取(以及稍后写入)的 XML 文件

代码运行,但它有一个 NullReference 异常

0 投票
0 回答
162 浏览

port - 如何在交错中使用 PortMode.OptimizedSingleReissueReceiver?(微软 CCR)

我在 Microsoft CCR 论坛上阅读了一篇关于减少调用 Port.Post() 开销的帖子 [参考:CCR 中的 PortElement 实例化],我想知道是否有类似的方法可以将端口绑定到其接收器为了在交错仲裁器中使用 OptimizedSingleReissueReceiver 模式下的端口?

我已经实现了以下代码,在 Interleave 上使用此 PortMode:

起初,它似乎没问题,但是我仍然不时收到 NullReferenceException (此异常表明端口尚未绑定到接收器)。

有谁知道在交错中使用 PortMode.OptimizedSingleReissueReceiver 的另一种方法?

0 投票
1 回答
639 浏览

winforms - System.NullReferenceException

我有一个在 VS.NET 2003 中开发的 Windows 应用程序。有时我会从 CallWindowProc() 获得 System.NullReferenceException 异常。

这是异常的堆栈跟踪

Error_Stack_Trace:在 System.Windows.Forms.NativeWindow.DefWndProc(Message& m) 在 System.Windows.Forms.NativeWindow.DefWndProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam) .DefWndProc(Message& m) 在 System.Windows.Forms.Control.WmUpdateUIState(Message& m) 在 System.Windows.Forms.Control.WndProc(Message& m) 在 System.Windows.Forms.ScrollableControl.WndProc(Message& m) 在 System .Windows.Forms.ContainerControl.WndProc(Message& m) 在 System.Windows.Forms.ParkingWindow.WndProc(Message& m) 在 System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m) 在 System.Windows.Forms.ControlNativeWindow.WndProc (消息和 m)在 System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd,Int32 msg,IntPtr wparam,IntPtr lparam)

请帮我解决这个错误。

谢谢和问候,贾加迪斯。

0 投票
1 回答
244 浏览

asp.net - IIS 6.0 上的 ASP.NET 处理突然停止

我们注意到我们的一个 Web 应用程序有一个相当奇怪的行为。在本地开发人员工作站上调试它时,一切都处理得很好(使用 Cassini 开发网络服务器)。当使用 IIS 6.0 在远程 Web 服务器上发布时,处理运行正常大约 4 或 5 分钟,然后突然停止。

稍后我将解释“突然死亡”的含义,首先我想摘录失败的代码。

此代码在调试时运行良好,执行大约需要 13 分钟(没关系,因为它仅在与 SAP 同步所有数据时发生)。在 IIS 6.0 上针对 SAME SAP 数据源运行 SAME 代码时,执行将在 4 或 5 分钟后停止。

首先,程序在调用“TimesumptionParserMethod1()”时抛出 System.NullReferenceException,在下一个循环中,我们在“GetStatusCodeForContract()”中得到 System.NullReferenceException。由于我们在两个调用中使用相同的参数,我认为 NullReferenceException 被抛出是因为成员“xItem”为空。

服务器配置:

有人知道 IIS 6 或类似生产服务器环境中的这种行为吗?

0 投票
1 回答
1358 浏览

scala - Regex.MatchData 返回 null:为什么不是 Option[String]?

Regex.MatchData.group(i: Int): java.lang.String 返回 null 而不是 Option[String] 有什么特别的原因吗?

Scala 中是否有“Scala 方式”来处理空值?