标签: nullreferenceexception

两个用户控件之间的交互

我快要疯了......

在我正在构建的应用程序中,我正在处理需要相互交互的两个动态添加的控件,但我已经将问题简化为一个简单的,因为我可以制作它的示例控件是静态加载的,它仍然存在同样的问题:调用委托时出现NullReferenceException.这是要点:

控制1

Partial Class Control1
Inherits System.Web.UI.UserControl

Private _delClicked As System.Delegate
Public WriteOnly Property UpdateLabel() As System.Delegate
    Set(ByVal value As System.Delegate)
        _delClicked = value
    End Set
End Property

Protected Sub btnButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnButton.Click
    Dim aObj(0) As Object
    aObj(0) = 1
    _delClicked.DynamicInvoke(aObj)
End Sub
End Class
Run Code Online (Sandbox Code Playgroud)

控制2

Partial Class Control2
Inherits System.Web.UI.UserControl

Protected WithEvents Control1 As New Control1
Delegate Sub ChangeLabel(ByVal int As Integer)

Protected Sub Page_Init(ByVal sender As Object, ByVal e As …
Run Code Online (Sandbox Code Playgroud)

vb.net asp.net user-controls delegates nullreferenceexception

5
推荐指数
1
解决办法
1186
查看次数

单击“发布”时出错 | “你调用的对象是空的”

我正在尝试发布我刚刚在 Visual Studio 2012 中创建的项目的文件。

当我点击发布时,

在此输入图像描述

显示以下窗口

在此输入图像描述

已经创建了一个新的 Web 项目(相同类型,asp.net mvc 4)并尝试进行相同的更改,一切正常。显然这只发生在这个项目上!

已经关闭了“VS”并在我重新启动电脑时再次打开..有什么提示吗?

publishing nullreferenceexception asp.net-mvc-4 visual-studio-2012

5
推荐指数
1
解决办法
7099
查看次数

System.NullReferenceException 仅在发布版本中

我收到“System.NullReferenceException:未将对象引用设置为对象实例”。当我启动 Web 应用程序的发布版本时出错。它告诉我进行调试构建以获取更多信息,但是当我启动调试构建时,错误不再发生。如果没有调试构建中大多数错误给出的行号的帮助,就很难(据我所知)查明这个模糊错误的原因。

谁能指出正确的方向来缩小此异常的原因?

谢谢。

.net c# release build nullreferenceexception

5
推荐指数
1
解决办法
3343
查看次数

成员参考和评估的分配顺序

为什么下面NullReferenceException的声明崩溃a.b.c = LazyInitBAndReturnValue(a);

class A {
    public B b;
}

class B {
    public int c;
    public int other, various, fields;
}

class Program {

    private static int LazyInitBAndReturnValue(A a)
    {
        if (a.b == null)
            a.b = new B();

        return 42;
    }

    static void Main(string[] args)
    {
        A a = new A();
        a.b.c = LazyInitBAndReturnValue(a);
        a.b.other = LazyInitBAndReturnValue(a);
        a.b.various = LazyInitBAndReturnValue(a);
        a.b.fields = LazyInitBAndReturnValue(a);
    }
}
Run Code Online (Sandbox Code Playgroud)

赋值表达式从右到左进行计算,因此在我们分配时a.b.c,a.b不应为null.奇怪的是,当调试器中断异常时,它也显示a.b为初始化为非空值.

调试器休息

c# evaluation nullreferenceexception

5
推荐指数
1
解决办法
82
查看次数

绑定表达式中的空检查

WPF 绑定表达式语法是否具有空检查机制?因此,例如 MyTextBox显示对象Address数组的第一个元素的字段People,如下所示:

Text="{Binding AllPeople[0].Address}" 
Run Code Online (Sandbox Code Playgroud)

AllPeople有时可以为空本身。这不会导致任何异常,但 WPF 会在“立即”窗口中以静默方式记录绑定错误消息。有没有办法通过在 Path 表达式中指定空安全来避免这种情况?一些关于AllPeople?[0].Address.

注意:我知道这可以使用转换器轻松完成。我正在寻找速记符号。

wpf xaml binding nullreferenceexception

5
推荐指数
1
解决办法
2462
查看次数

使用任务获取“未将对象引用设置为对象的实例”

首先,我已经在许多 NullReferenceException 问题中搜索了 SO。这里这里

当我尝试调用时收到错误“对象引用未设置为对象的实例” Task.WaitAll(tasks);

我确信在尝试调用方法之前我正在初始化所有对象。下面是代码片段:

public IList<ResourceFreeBusyDto> GetResourceFreeBusy(int requesterId, int[] resourceIds, DateTime start, DateTime end)
    {
        IList<ResourceFreeBusyDto> result = new List<ResourceFreeBusyDto>();

        ValidateFreeBusyInputs(resourceIds, start, end);

        List<Task<IList<ResourceFreeBusyDto>>> tasks = new List<Task<IList<ResourceFreeBusyDto>>>();
        TimeSpan timeout = new TimeSpan(0,0,30); // 30 seconds          

        // Split resources to persons and meetingRooms
        List<int> personIds;
        List<int> meetingRoomIds;

        SplitResourceIds(resourceIds, out personIds, out meetingRoomIds);

        // Go online for persons
        if (personIds.Count > 0)
        {
            //result.AddRange(GetResourceFreeBusyOnline(requesterId, personIds.ToArray(), start, end)); // paralelizovat
            Task<IList<ResourceFreeBusyDto>> task = Task.Factory.StartNew(() => GetResourceFreeBusyOnline(requesterId, …
Run Code Online (Sandbox Code Playgroud)

c# task nullreferenceexception

5
推荐指数
1
解决办法
1万
查看次数

WPF:Automation.Peers.ItemAutomationPeer.GetNameCore 处的 NullReferenceException

我有一个棘手的问题,为此花了一整天的时间,但仍然无法解决。我在 WPF UI 上有一个按钮,用于向树视图添加项目,xaml 中的代码如下:

<Button Content="Create Item"  
                                        Command="{Binding NewItem}"
                                        Click="NewItemButton_Click"
                                        TabIndex="16"                                                                                           
                                        ToolTip="{Binding NewItemHelpText}"
                                        ToolTipService.ShowOnDisabled="True">
                                        <Button.IsEnabled>
                                            <MultiBinding Converter="{StaticResource LogicalAndConverter}">
                                                <Binding Path="CurrentItem" Converter="{StaticResource ItemCreationConverter}"/>
                                                <Binding Path="ControlMode" Converter="{StaticResource MyConverter}" ConverterParameter="{x:Static local:Option.ReadOnly}"/>
                                            </MultiBinding>
                                        </Button.IsEnabled>
                                    </Button>
Run Code Online (Sandbox Code Playgroud)

有时候,点击这个按钮后,会抛出异常,

> ERROR MyApplication.App [(null)] - Error in MyApplication
   System.NullReferenceException: Object reference not set to an instance of an object.
   at System.Windows.Automation.Peers.ItemAutomationPeer.GetNameCore()
   at System.Windows.Automation.Peers.AutomationPeer.UpdateSubtree()
   at System.Windows.Automation.Peers.AutomationPeer.UpdateSubtree()
   at System.Windows.Automation.Peers.AutomationPeer.UpdateSubtree()
   at System.Windows.Automation.Peers.AutomationPeer.UpdatePeer(Object arg)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate …
Run Code Online (Sandbox Code Playgroud)

wpf automation nullreferenceexception

5
推荐指数
1
解决办法
207
查看次数

Unity Vuforia NullReferenceException

我正在使用Untiy使用Vuforia为HoloLens构建AR-App。我正在使用一个标记,以相对于标记位置放置多个对象。没什么特别的。尚未编写脚本。有时会弹出以下错误消息。我不知道是什么原因引起的。我无法了解我统一所做的事情。同样,即使存在错误消息,构建也会成功。怎么可能把它弄走?我什至无法理解它的重要性,因为该应用程序没有明显的影响。

我怀疑是唯一的原因:在第一次发生错误之前不久,我更新了Vuforia。这可能是原因吗?

NullReferenceException: Object reference not set to an instance of an object
Vuforia.EditorClasses.ImageTargetEditor.DrawPredefinedTargetInspectorUI (Boolean typeChanged)
Vuforia.EditorClasses.ImageTargetEditor.OnInspectorGUI ()
UnityEditor.InspectorWindow.DrawEditor (UnityEditor.Editor[] editors, Int32 editorIndex, Boolean rebuildOptimizedGUIBlock, System.Boolean& showImportedObjectBarNext, UnityEngine.Rect& importedObjectBarRect) (at C:/buildslave/unity/build/Editor/Mono/Inspector/InspectorWindow.cs:1295)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)
Run Code Online (Sandbox Code Playgroud)

编辑:这不是什么是NullReferenceException的重复项,我该如何解决?因为Exception的含义是已知的。我不知道异常的原因是什么以及如何统一解决它,因为它源自我编写的代码之外。

nullreferenceexception unity-game-engine vuforia hololens

5
推荐指数
0
解决办法
1111
查看次数

你能捕获抛出 NullReferenceException 的对象的名称吗?

有没有办法找出是什么特定对象导致了NullReferenceException?我已经阅读了关于故障排除NullReferenceException页面,它谈到了在调试器中检查变量并查看异常消息。

如果异常是在生产代码中引发的,因此您无法运行调试器来检查变量怎么办?异常消息显示了堆栈跟踪,因此您可以查看抛出异常的方法,但它没有说明是哪个特定对象null

我希望能够将对象的名称添加null到错误消息中,这样当我查看用户的报告并遇到 . 时NullReferenceException,我可以轻松查看对象是什么null并修复它。有谁知道这样做的方法吗?

我也发现这个问题提出了同样的问题,但它是从 2011 年开始的,我不知道从那时起是否有任何变化。

编辑这个问题,这是标记为重复的确是重复的,但也是很老的(2008)。从那以后有什么改变吗?

编辑 2:我在谷歌搜索这个问题时发现了一点。Visual Studio 可以告诉你是什么抛出了NullReferenceException; 有什么方法可以利用它将其添加到日志文件中吗?

c# logging nullreferenceexception

5
推荐指数
1
解决办法
401
查看次数

如何找到抛出“NullReferenceException:'对象引用未设置到对象实例”的方法?

我已经检查过 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

5
推荐指数
1
解决办法
4333
查看次数