c# - CsvReader Mapping and Conversion : No coercion operator -


first, thank time. i'm trying use csvhelper first time along custom class , custom map. i'm getting "no cercion operator defined between types 'system.int32' , 'system.string'"

here classes:

class vendor {     public string vendorid { get; set; }     public string vendorname { get; set; }     public string vendorshortname { get; set; }     public string vendorcheckname { get; set; }     public string hold { get; set; }     public string vendorstatus { get; set; }     public string vendorclassid { get; set; }     public string primaryvendoraddressid { get; set; }     public string vendorcontact { get; set; }     public string address1 { get; set; }     public string address2 { get; set; }     public string address3 { get; set; }     public string city { get; set; }     public string state { get; set; }     public string zipcode { get; set; }     public string countrycode { get; set; }     public string country { get; set; }     public string phone1 { get; set; }     public string phone2 { get; set; }     public string phone3 { get; set; }     public string faxnumber { get; set; }     public string vendoraccountnumber { get; set; }     public string paymenttermsid { get; set; }     public string taxidnumber { get; set; }     public string taxregistrationnumber { get; set; }     public string user_defined1 { get; set; }     public string user_defined2 { get; set; }     public string tax1099type { get; set; }     public string tax1099boxnumber { get; set; }     public string purchasesaccount { get; set; }     public string transitroutingnumber { get; set; }     public string eftbankaccountnumber { get; set; } }  class vendormap : csvclassmap<vendor> {     public override void createmap()     {         map(m => m.vendorid).name("vendor id");         map(m => m.vendorname).name("vendor name");         map(m => m.vendorshortname).name("vendor short name");         map(m => m.vendorcheckname).name("vendor check name");         map(m => m.hold).name("hold").default(1);         map(m => m.vendorstatus).name("vendor status").default("active");         map(m => m.vendorclassid).name("vendor class id");         map(m => m.primaryvendoraddressid).name("primary vendor address id");         map(m => m.vendorcontact).name("vendor contact");         map(m => m.address1).name("address 1");         map(m => m.address2).name("address 2");         map(m => m.address3).name("address 3");         map(m => m.city).name("city");         map(m => m.state).name("state");         map(m => m.zipcode).name("zip code");         map(m => m.countrycode).name("country code");         map(m => m.country).name("country");         map(m => m.phone1).name("phone 1");         map(m => m.phone2).name("phone 2");         map(m => m.phone3).name("phone 3");         map(m => m.faxnumber).name("fax number");         map(m => m.vendoraccountnumber).name("vendor account number");         map(m => m.paymenttermsid).name("payment terms id");         map(m => m.taxidnumber).name("tax id number");         map(m => m.taxregistrationnumber).name("tax registration number");         map(m => m.user_defined1).name("user-defined 1");         map(m => m.user_defined2).name("user-defined 2");         map(m => m.tax1099type).name("tax 1099 type:");         map(m => m.tax1099boxnumber).name("tax 1099 box number");         map(m => m.purchasesaccount).name("purchases account");         map(m => m.transitroutingnumber).name("transit routing number");         map(m => m.eftbankaccountnumber).name("eft bank account number");     } } 

here reading file:

csvreader csv = new csvreader(reader);  csv.configuration.hasheaderrecord = true; csv.configuration.registerclassmap<vendormap>();  list<vendor> vendors = null;  try {     vendors = csv.getrecords<vendor>().tolist(); 

ideally, hold, tax99type, , tax99boxnumber properties types "short". however, received error "the conversion cannot performed".

here part of test csv:

"vendor id","vendor name","vendor short name","vendor check name","hold","vendor status","vendor clas "aa0011","uat demo","","","","active","","residence","demo uat","testing","testing","","testing","ks" "aa0011","uat demo","","","","active","","supply","demo uat","new address","new address","","new addr 

the issue caused mismatch of types between column definition (string):

public string hold { get; set; } 

and it's default value (int32),

map(m => m.hold).name("hold").default(1); 

as far i'm aware, current version of csvhelper, default value type should match type definition of corresponding column.

you have 2 options . either define column hold short, or change default value string (ie "1").

assuming you've tried former option, error "the conversion cannot performed" means 1 or more column values in csv file contains value cannot converted short (ie alphanumeric value).


Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -