Weird NullReferenceException in third party dll: C#

吃可爱长大的小学妹 提交于 2019-12-12 02:28:36

问题


I have a strange error, which has started suddenly and which is driving me crazy. In my C# application, I am doing some heavy mathematical calculations and for that purpose, I am using CenterSpace's NMath library. Recently, when I started my application from inside Visual Studio 2015 in order to debug it, the application started to crash because of NullReferenceExceptions in NMath.dll, whenever I call an NMath library method (and another library which we have written, as well). In order to isolate the problem, I just run the following very basic matrix multiplication code:

    static void Main(string[] args)
    {
        var mA = new DoubleMatrix(100, 200, 1.5);
        var mB = new DoubleMatrix(200, 50, 1.2);
        var mC = NMathFunctions.Product(mA, mB);
        Console.WriteLine(mC[5, 6]);

        Console.WriteLine("Computation finished");
        Console.ReadLine();
    }

The code crashes in the third line, when I call the "NMathFunctions.Product" method because of a NullReferenceException, with the following exception detail:

It seems that it crashes just in the constructor of the "NMathKernel" object, since an object reference is not properly set.

The most strange thing is, when I run the exactly same program directly from its project folder by using Windows Explorer, not within Visual Studio, the program runs perfectly: The fourth line prints "360.000000001" as expected and the "Console.ReadLine()" is reached!

I am completely clueless about the reason of this NullReferenceException error. It is not a third party dll related problem it seems, since the program only crashes when started from within the Visual Studio. This error completely blocks me from debugging my program with Visual Studio, which is a painful thing, leaves me the only option of debugging it with "Console.WriteLine" calls, from outside of Visual Studio. What can be the reason of this problem? Is something messed up with my Build settings maybe? (Which I have checked and found nothing out of order by the way) Any clues or hints are so much welcome.


回答1:


  1. In VisualStudio go to Tools -> Options -> Debugging and make sure you have Enable Just My Code option checked.
  2. Go to Debug -> Exceptions and unckeck all Thrown chechboxes. Only leave User-unhandled checkboxes checked. Or just use the Reset all button.


来源:https://stackoverflow.com/questions/32751435/weird-nullreferenceexception-in-third-party-dll-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!