简体   繁体   English

不合逻辑的NullReferenceException

[英]Illogical NullReferenceException

So in my normal course of getting some work done, i came across a generic System.NullReferenceException: 'Object reference not set to an instance of an object.' 因此,在我完成一些工作的正常过程中,我遇到了一个通用的System.NullReferenceException: 'Object reference not set to an instance of an object.' .

So no problem i'm thinking as I start looking for the culprit. 所以, 没问题,我在想,我开始寻找罪魁祸首。 After much debugging, I threw my hands up in the air and wanted to give up for the moment... My strategy for bypassing this was to just instantiate an array instead of calling some service for the data. 经过多次调试后,我举起双手,想要暂时放弃......我绕过这个的策略是实例化一个数组,而不是为数据调用一些服务。

So i changed: 所以我改变了:

var data = service.GetData(someId);

to

var data = new DataType[]{};

to get my code compiling and debuggable so i can come back to this. 让我的代码编译和调试,所以我可以回到这里。

The kicker: upon doing so, i'm still getting the exception on that line. 踢球者:在这样做的时候,我仍然在那条线上获得例外。 So JUST an array instantiation is yielding this exception. 所以只是一个数组实例化正在产生这个异常。 The exception has zero data to it. 该例外的数据为零。 No inner exception or stack trace beyond pointing to this line. 除了指向此行之外,没有内部异常或堆栈跟踪。 The class itself is just a poco with no methods (no constructor either) so nothing is happening internally. 类本身只是一个没有方法的poco(也没有构造函数)所以内部没有任何事情发生。 (see below for the class) (见下面的课程)

My next thought is that clearly, the code i'm seeing isn't what my debug session is using. 我的下一个想法是,显然,我看到的代码不是我的调试会话使用的。

To test this thought I've 为了测试这个想法我

  • Cleaned in VS 在VS中清理
  • manually deleted the bin 手动删除bin
  • manually deleted obj 手动删除obj
  • removed all package directories 删除了所有包目录
  • restarted my computer 重启了我的电脑
  • tried it in the new beta of VS 在VS的新测试版中尝试过它
  • tried it in JetBrains' Rider 在JetBrains的Rider中尝试过

still i'm facing this. 还是面对这个。

Anyone have thoughts on how i can get more details on why this is happening, or is there something else I should be cleaning? 任何人都有关于我如何能够获得有关为什么会发生这种情况的更多细节的想法,或者是否还有其他我应该清理的东西?

I've also looked at the output of git clean -xdn to see what kind of ephemeral stuff is hanging around that could be removed and nothing of interest there... 我也看了一下git clean -xdn的输出,看看有什么样的短暂的东西可以被删除,没有什么值得关注的......

no matter what code is actually on the line, if i completely comment out this line and have completely different code there in it's place (as initially described), then that code throws the exception instead. 无论什么代码实际上都在线上,如果我完全注释掉这一行并且在那里有完全不同的代码 (如最初描述的那样),那么代码会抛出异常。 i just had one of my colleagues grab this branch and run it and it was fine for them 我只是让我的一个同事抓住这个分支并运行它,这对他们来说没问题

3 hours deep so far... no fun 到目前为止3个小时深......没什么好玩的

Edit: 编辑:

as requested, here's a definition: 根据要求,这是一个定义:

using System;
using Dapper.Contrib.Extensions;

namespace some_namespace
{
#pragma warning disable 1591
    [Table ("CompanyOptions")]
    public class CompanyOption
    {
        [ExplicitKey]
        public Guid PKID { get; set; }
        public Guid CompanyPKId { get; set; }
        public string OptionName { get; set; }
        public string OptionValue { get; set; }
        public DateTime CreatedOn { get; set; }
        public string CreatedBy { get; set; }
        public DateTime? UpdatedOn { get; set; }
        public string UpdatedBy { get; set; }
    }
}

在此输入图像描述

So it seems there were issues with my installation of some microsoft packages. 所以我的安装一些微软软件包似乎存在问题。 I found that running Update-Package Microsoft.CodeDom.Providers.DotNetCompilerPlatform -r in the package management console to reinstall solved my problem. 我发现在包管理控制台中运行Update-Package Microsoft.CodeDom.Providers.DotNetCompilerPlatform -r重新安装解决了我的问题。 In looking at the diff that that yielded, the only meaningful thing is the following target framework bumps in my packages.config : 在查看产生的差异时,唯一有意义的事情是我的packages.config的以下目标框架颠簸:

在此输入图像描述

These package references haven't changed recently and the project has been targeting 4.7.1 for quite some time now so not sure why the sudden problem. 这些软件包引用最近没有改变,项目已经针对4.7.1进行了相当长的一段时间,因此不确定为什么突然出现问题。 Seems something became corrupted in the roslyn layer perhaps? 似乎某些东西在roslyn层中被腐蚀了?

Going to slowly back away from my computer now. 现在慢慢退出我的电脑。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM