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:未将对象引用设置为对象的实例.
我在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) 我正在用F#编写一个库,其中一些接口和基类是公开可见的.一般情况下,我避免指定[<AllowNullLiteral>]我的自定义类型,因为这在我的F#代码验证逻辑(见复杂的F#这个不错的职位对商品和空移交的劣品得到的图片),而且,F#最初不容许null的F#类型.因此,我仅对接受该null值为有效的类型验证null .
但是,当我的库使用其他.NET语言(例如C#)时会出现问题.更具体地说,我担心在C#代码调用时,我应该如何实现接受F#-declared接口的方法.接口类型在C#中可以为空,我怀疑C#代码传递null给我的F#方法不会有问题.
我担心调用者会因NPE而崩溃和烧毁,问题是我甚至不允许在F#代码中正确处理它 - 比如抛出ArgumentNullException- 因为相应的接口缺少AllowNullLiteral属性.我担心我必须使用该属性并在我的F#代码中添加相关的空检查逻辑,以最终防止这种灾难.
我的恐惧是否合理?我有点困惑,因为我最初试图坚持良好的F#做法并null尽可能避免.如果我的目标之一是允许C#代码继承并实现我在F#中创建的接口,这会如何改变?如果它们是公共的并且可以从任何CLR语言访问,我是否必须允许来自我的F#代码的所有非值类型的空值?是否有最佳实践或良好建议?
在调试 NULL Ref Exception 期间,我不小心取消选中了该框Break when this exception type is user-unhandled异常弹出窗口中的复选框。我怎样才能重新打开它?
我查看了 debug-> 异常,但没有看到提到的 null ref
我有2个表单(Form1和Form2)和一个类(Class1).Form1包含一个按钮(Button1),Form2包含一个RichTextBox(textBox1)当我在Form1上按下Button1时,我想要调用方法(DoSomethingWithText).我一直得到"NullReferenceException - 对象引用未设置为对象的实例".这是一个代码示例:
Form1中:
namespace Test1
{
public partial class Form1 : Form
{
Form2 frm2;
Class1 cl;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
frm2 = new Form2();
cl.DoSomethingWithText();
frm2.Show()
}
}
}
Run Code Online (Sandbox Code Playgroud)
1类:
namespace Test1
{
class Class1
{
Test1.Form2 f2;
public void DoSomethingWithText()
{
f2.richTextBox1.Text = "Blah blah blah";
}
}
}
Run Code Online (Sandbox Code Playgroud)
如何在课堂中调用此方法?任何帮助是极大的赞赏.
ReSharper通知我有关System.NullReferenceException以下代码的可能性:
IEnumerator<IEdgeData> edgeEnumerator = edgeData.GetEnumerator();
while (edgeEnumerator.MoveNext())
{
ConvId fromConvId = edgeEnumerator.Current.From;
...
}
Run Code Online (Sandbox Code Playgroud)
具体来说,它强调:
edgeEnumerator.Current
Run Code Online (Sandbox Code Playgroud)
我无法弄清楚异常可能发生在哪种情况下.我的理解是,while只有MoveNext()在下一个元素上设置枚举器时才会执行-loops内部语句.
c# ×10
.net ×1
arrays ×1
class ×1
f# ×1
ienumerator ×1
if-statement ×1
initializer ×1
linq-to-sql ×1
methods ×1
nhibernate ×1
null ×1
queryover ×1
resharper ×1
wpf ×1