0

Note: I am not discussing the error here. I am wondering why I am having this error at this specific line.

I am getting this error on 3 different customers. I am not allowed to access their computers and data and I am not having this problem on my computer.

System.NullReferenceException: Object reference not set to an instance of an object...... vid Windows.Page.UCAtgardSkuldsanering. FillPdfSkuldFieldValues(Dictionary`2 fieldValues, Skuld skuld, Int32 SkuldNumber) i C:\Users\u706185\Source\Workspaces\Boss\Utveckling\1. 4.2\Windows\Page\UCAtgardSkuldsanering.cs:rad 1960 vid Windows.Page.UCAtgardSkuldsanering.FillWithSkulder(Dictionary`2 fieldValues) i C:\Users\u706185\Source\Workspaces\Boss\Utveckling\1. 4.2\Windows\Page\UCAtgardSkuldsanering.cs:rad 1913 vid Windows.Page.UCAtgardSkuldsanering.FillSkuldsaneringPdf() i C:\Users\u706185\Source\Workspaces\Boss\Utveckling\1. 4.2\Windows\Page\UCAtgardSkuldsanering.cs:rad 1361 vid Windows.MdiParent.letterToolStripButton_Click(Object sender, EventArgs e) i C:\Users\u706185\Source\Workspaces\Boss\Utveckling\1. 4.2\Windows\MdiParent.cs:rad 2792 vid System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)

The code at this location is:

enter image description here

    private void FillPdfSkuldFieldValues(Dictionary<string, string> fieldValues, Skuld skuld, int SkuldNumber)
    {
        if (skuld?.FordringsAgareNamn != null)
        {
            string s2 = (ApplicationHelper.FormatPostnummer(skuld.FordringsAgarePostnr) + " " + skuld.FordringsAgarePostOrt).Trim();
            string s1 = skuld.FordringsAgareAdress.Trim();
            fieldValues.Add($"BlankettFormular[0].SkuldsaneringPrivatperson[0].DinaSkulder[{ SkuldNumber }].Borgenar[0].NamnAdress[0]",
            string.Join(Environment.NewLine, new List<String> {
                skuld.FordringsAgareNamn,
                !string.IsNullOrEmpty(s1) && !string.IsNullOrEmpty(s2) ?
                        s1 + ", " + s2 : (!string.IsNullOrEmpty(s1) ? s1 : !string.IsNullOrEmpty(s2) ? s2 : "")
            }.Where(sx => !string.IsNullOrEmpty(sx))));

            fieldValues.Add($"BlankettFormular[0].SkuldsaneringPrivatperson[0].DinaSkulder[{ SkuldNumber }].Borgenar[0].Tfn[0]", skuld.FordringsAgareTelefon);
        }

FordringsAgareNamn property look like:

    public global::System.String FordringsAgareNamn
    {
        get
        {
            return _FordringsAgareNamn;
        }
        set
        {
            OnFordringsAgareNamnChanging(value);
            ReportPropertyChanging("FordringsAgareNamn");
            _FordringsAgareNamn = StructuralObject.SetValidValue(value, true, "FordringsAgareNamn");
            ReportPropertyChanged("FordringsAgareNamn");
            OnFordringsAgareNamnChanged();
        }
    }
    private global::System.String _FordringsAgareNamn;

Skuld object is read from database and it should never been null. and FordringsAgareNamn is string. Why am I getting this error at this line 1960?

The project is Windows form application with .Net framework 4.6

Note: I am not discussing the error here. I am wondering why I am having this error at this specific line.

Any help!!!!!

Yasser
  • 864
  • 1
  • 9
  • 19
  • 2
    please post code as code – Stefan Apr 07 '17 at 11:56
  • Did your customers run a debug version of your app? I guess it's a release version, so the stack trace may not be detailed enough...is it possible that the `FordringsAgareNamn` property getter (I guess it is a property) throws the exception and it just does not appear in the stack trace due to some kind of optimization? – René Vogt Apr 07 '17 at 11:59
  • Yes, FordringsAgareNamn is a property. The getter is just returning the value. public global::System.String FordringsAgareNamn { get { return _FordringsAgareNamn; } set – Yasser Apr 07 '17 at 12:00
  • 3
    If your question is why the exception is thrown at that particular line, then the answer is that your PDBs don't match your source code. – CodeCaster Apr 07 '17 at 12:15
  • I have followed the stack trace and it does match the code at every line. – Yasser Apr 07 '17 at 12:19
  • 2
    There's simply no way that `if (skuld?.FordringsAgareNamn != null)` can throw a `NullReferenceException` that I'm aware of, given the code you show. Unless in turn `_FordringsAgareNamn` is something other than a string field. – CodeCaster Apr 07 '17 at 12:27
  • @CodeCaster. That is why I wrote Weird. I am not understanding what is happening here. Unfortunately _FordringsAgareNamn is a string. – Yasser Apr 07 '17 at 12:35
  • I only ever heard of null conditional operator causing this kind of problem in cases like this: http://stackoverflow.com/q/33592547/891715 or https://stackoverflow.com/questions/37218581/null-conditional-operator-not-behaving-as-expected-on-some-machines (related to await on tasks). Are you sure you don't have something in your project that uses this sort of thing under the hood? Could Skuld be some proxy type? – Arie Apr 07 '17 at 12:48
  • What do you mean by proxy type? Skuld is an item of an array which have been read from the database. – Yasser Apr 07 '17 at 12:53
  • Do you have any `Equal`ity / `GetHash` overrides or custom operators defined? – Stefan Apr 07 '17 at 13:09

0 Answers0