LinqToExcel - InvalidCastException leading to Object should implement the opposite error

I use the following code to request an excel file in LinqToExcel:

var excelFile = new LinqToExcel.ExcelQueryFactory(@"\"+txtFileName.Text.Replace(@"\\",@"\"));

var properties = from p in excelFile.Worksheet<Property>()
                 where AssessmentID != null
                 select p;
foreach (var autoP in properties)
        doSomething();

When I look at the runtime debugger, I see "InvalidCastException" when viewing the "View Results" of the properties variable . So, I assume that something funny is going on with my class definition. I also assume that I do not need to map all members of the class to an excel file, but rather only those that I consider necessary.
So here is the class definition:

public class Property
{

    [DataMember]
    public int? Year { get; set; }

    [DataMember]
    public string ChangeReason { get; set; }

    [DataMember]
    public string AssessmentID { get; set; }

    [DataMember]
    public string CallBackNotes { get; set; }

    [DataMember]
    public string InspectionNotes { get; set; } 

    [DataMember]
    public string Notes { get; set; }

    [DataMember]
    public bool Authorization { get; set; }

    [DataMember]
    public string ChargeStatus { get; set; }

    [DataMember]
    public string LegalLandDesc { get; set; }

    [DataMember]
    public string Address { get; set; }
    }

Here's a link to the source code for linqToExcel on GitHub: LinqToExcel Generics are harder than I saw, and this is what I (apparently) need to refresh.

- , , ? , , ?

+4
1

where, - . null, . :

where  !String.IsNullOrEmpty(p.AssessmentID) 

.

: !

+7

Source: https://habr.com/ru/post/1623831/


All Articles