我已经检查过 Stackoverflow 上的所有类似问题。他们都没有回答或真正提出同样的问题。
有没有办法找到尝试引用所述空对象的方法?

我知道它不能说出什么对象,因为它不知道,但是它必须知道什么方法正在尝试空引用,但不会显示它。在调试模式下,代码屏幕显示:
“您的应用程序已进入中断状态,但没有代码可显示,因为所有线程都在执行外部代码(通常是系统或框架代码)。”
我点击“继续执行”来读取输出并从那里找到它,但是输出中没有任何相关内容:
**System.NullReferenceException:** 'Loading...'
Thread finished: <Thread Pool> #4
The thread 0x4 has exited with code 0 (0x0).
Thread finished: <Thread Pool> #5
The thread 0x5 has exited with code 0 (0x0).
Thread finished: <Thread Pool> #2
The thread 0x2 has exited with code 0 (0x0).
Thread finished: <Thread Pool> #3
The thread 0x3 has exited with code 0 (0x0).
Thread finished: <Thread Pool> #6
The thread 0x6 has exited with code 0 (0x0).
Thread …Run Code Online (Sandbox Code Playgroud) object-reference nullreferenceexception xamarin.android xamarin.forms
我正在寻找一种很好的方法来处理对象层次结构中的空引用.
即:
if(null == Object1.Object2.Object3.Property)
Run Code Online (Sandbox Code Playgroud)
如果说Object2为null,则此示例将抛出Null Reference异常.
在我的情况下,我不在乎什么是null,只是有些东西.我真的不想在我希望做这样的事情的每个地方放置尝试/捕获,所以我一直在寻找替代方案.
我试过了?? 运算符,但这会在两个级别之后产生一些难看的代码.
任何想法都赞赏.
sUsername.Trim();
sPassword.Trim();
string ConnectionString = WebConfigurationManager.ConnectionStrings["dbnameConnectionString"].ConnectionString;
SqlConnection myConnection = new SqlConnection(ConnectionString);
Run Code Online (Sandbox Code Playgroud)
你调用的对象是空的.描述:执行当前Web请求期间发生未处理的异常.请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息.
异常详细信息:System.NullReferenceException:未将对象引用设置为对象的实例.
有任何想法吗?我不明白这个错误.
当列中的任何一列可能为空时,如何使用LINQ to SQL搜索多个列?
IEnumerable<User> users = from user in databaseUsers
where
user.ScreenName.Contains(search)
|| user.FirstName.Contains(search)
|| user.LastName.Contains(search)
select user;
Run Code Online (Sandbox Code Playgroud)
我一直得到这个例外:
你调用的对象是空的.
描述:执行当前Web请求期间发生未处理的异常.请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息.
异常详细信息:System.NullReferenceException:未将对象引用设置为对象的实例.
鉴于代码:
from i in this.GridViewFoo.SelectedItems
select new EmployeeEntity
{
EmployeeID = (i as EmployeeDto).EmployeeID,
Email = this.GetAllEmail((i as EmployeeDto).Email, (i as EmployeeDto).SecondaryEmails),
EmployeeNumber = (i as EmployeeDto).EmployeeNumber,
FirstName = (i as EmployeeDto).FirstName,
LastName = (i as EmployeeDto).LastName
}
Run Code Online (Sandbox Code Playgroud)
在安全演员之后,(i as EmployeeDto)我可能会收到NullReferenceException.如何确保代码的安全性并且不会因为大量的空检而使其过载?
解决方案概述:
我做了一些测试来断言解决方案是否正常工作.两者都运作良好并带来相同的结果,你可以在这里查看.之后,我使用OfTypeSolution和letSolution进行了一些性能测试.
由于OfType解决方案平均有更好的时间,这将是答案!
我在NHibernate中使用JoinAlias QueryOver获得了一些意想不到的行为.
我的实体基本上是这样的:
public class Field
{
public virtual long Id { get; protected set; }
public virtual Field Parent { get; protected set; }
public virtual FieldType Type { get; protected set; }
public virtual string Value { get; protected set; }
...(Ctors etc
}
Run Code Online (Sandbox Code Playgroud)
我的映射是这样的:
public class FieldMap : ClassMap<Field>
{
public FieldMap()
{
Id(x => x.Id)
.GeneratedBy.Native();
References(x => x.Type)
.Column("FieldTypeId")
.LazyLoad()
.Cascade.All()
;
Map(x => x.Value);
References(x => x.Parent)
.Column("ParentFieldId")
.Nullable()
.LazyLoad()
.Cascade.All()
;
}
Run Code Online (Sandbox Code Playgroud)
我的查询: …
我有一个WPF项目,我正在使用多个WPF窗口.我的WPF Windows是:
我必须在案例场景中,在第一个一切正常,但在第二个我得到一个空引用异常.
MainWindow.当用户点击MainWindow上的Button时,他在Window1中被转发,我有以下代码:
MainWindow obj=(MainWindow)Application.Current.MainWindow;
private void button1_Click(object sender, RoutedEventArgs e)
{
obj.checkBox1.IsChecked = false;
}
Run Code Online (Sandbox Code Playgroud)
2.第二种场景:App.xaml配置为启动窗口为Login Window.登录代码:
private void button1_Click(object sender, RoutedEventArgs e)
{
var window=new MainWindow();
window.Show();
this.Close();
}
Run Code Online (Sandbox Code Playgroud)
在这种情况下,当我单击Window1中的按钮时,将抛出obj的空引用异常.
这MainWindow两种情况的初始化有什么不同,导致第二种情况下的异常,我该如何克服它?
我有以下代码定义一个数组
public class PalphabetsDic
{
public static string[] PAlphCodes = new string[3] {
PAlphCodes[0] = "1593",
PAlphCodes[1] = "1604",
PAlphCodes[2] = "1740",
};
}
Run Code Online (Sandbox Code Playgroud)
当我使用这个数组
var text = PalphabetsDic.PAlphCodes[1]
Run Code Online (Sandbox Code Playgroud)
给出错误:
'Dota2RTL.PalphabetsDic'的类型初始值设定项引发了异常.---> System.NullReferenceException:对象引用未设置为对象的实例.
请有人帮我这个吗?
请注意什么是NullReferenceException,我该如何解决?涵盖数组,但PAlphCodes = new string[3]应该将其设置为不null.
这引用了我的最后一个问题,该问题似乎已被放弃。如果您使用 C# 和 MS VS 2015,我遇到了一个奇怪的“错误”。要重现该错误,请按照以下步骤操作:
命中Continue并抛出 NRE 异常。为什么会出现这种情况?只有我吗?对此有何技术解释?
代码:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace testapp
{
class Program
{
static void Main(string[] args)
{
FILECollection randomCollection = new FILECollection();
// Fill with junk test data:
for(int i = 0; i<10; i++)
{
FILE junkfile = new FILE() { fileName = i.ToString(), folderName = i.ToString(), fileHashDigest = new byte[1] };
randomCollection.Add(junkfile); …Run Code Online (Sandbox Code Playgroud) 在调试 NULL Ref Exception 期间,我不小心取消选中了该框Break when this exception type is user-unhandled异常弹出窗口中的复选框。我怎样才能重新打开它?
我查看了 debug-> 异常,但没有看到提到的 null ref
c# ×8
.net ×1
arrays ×1
if-statement ×1
initializer ×1
linq ×1
linq-to-sql ×1
nhibernate ×1
null ×1
queryover ×1
wpf ×1