C# - FileHelpers: Bad computing of DateTime variable



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








1















I have this sample CSV file:



Filip Malýn Male 1218-02-1994
Božena Němcová Female1804-02-1820
Jan Žižka Male 0719-09-1360
Che Guevara Male 2714-06-1928
AntoinedeSaint-ExupéryMale 1529-06-1900


I load it in a code by this function:



FileHelperEngine<T>().ReadFile(fileName);


But it ends up with this error:



FileHelpers.BadUsageException: 'The string '18-02-1994' (length 10) at line 1 has less chars than the defined for BirthDate (11). You can use the [FixedLengthRecord(FixedMode.AllowLessChars)] to avoid this problem.'


And if I add [FixedLengthRecord(FixedMode.AllowLessChars)] to the code it ends up with this error:



FileHelpers.ConvertException: 'Error Converting 'al' to type: 'Int32'. '


This is a class I use:



using System;
using FileHelpers;

namespace ImportExport.Mapping.FixedLength

[FixedLengthRecord(FixedMode.AllowLessChars)]
public class Person

[FieldFixedLength(9)]
public String Name;

[FieldFixedLength(13)]
public String Surname;

[FieldFixedLength(6)]
public String Gender;

[FieldFixedLength(2)]
public Int32 OrderNum;

[FieldFixedLength(11)]
[FieldConverter(ConverterKind.Date, "dd-MM-yyyy")]
public DateTime BirthDate;




I have been couting it so many times and tried a lot of version but with no success. What's wrong?










share|improve this question



















  • 3





    [FieldFixedLength(11)] should be [FieldFixedLength(10)]. 01-01-2000 is 10 characters, not 11.

    – mjwills
    Nov 16 '18 at 12:47







  • 2





    "dd-MM-yyyy".Length == 10 - Note that the error message states that.

    – PaulF
    Nov 16 '18 at 12:47







  • 1





    I'd be wondering about the encoding of this file, including the use of combining characters, any specified or assumed encoding that FileHelpers is working with and whether what it's actually working is characters or code points.

    – Damien_The_Unbeliever
    Nov 16 '18 at 12:53







  • 2





    You did something wrong, and it gave an error. You changed it to something else (hint - AllowLessChars), and you got a different error. You fixed the first bug - but did you remember to reverse the second thing you tried?

    – mjwills
    Nov 16 '18 at 12:53







  • 1





    The problem that the records contains diacritic so the real size is different.

    – Chyu
    Nov 16 '18 at 13:14

















1















I have this sample CSV file:



Filip Malýn Male 1218-02-1994
Božena Němcová Female1804-02-1820
Jan Žižka Male 0719-09-1360
Che Guevara Male 2714-06-1928
AntoinedeSaint-ExupéryMale 1529-06-1900


I load it in a code by this function:



FileHelperEngine<T>().ReadFile(fileName);


But it ends up with this error:



FileHelpers.BadUsageException: 'The string '18-02-1994' (length 10) at line 1 has less chars than the defined for BirthDate (11). You can use the [FixedLengthRecord(FixedMode.AllowLessChars)] to avoid this problem.'


And if I add [FixedLengthRecord(FixedMode.AllowLessChars)] to the code it ends up with this error:



FileHelpers.ConvertException: 'Error Converting 'al' to type: 'Int32'. '


This is a class I use:



using System;
using FileHelpers;

namespace ImportExport.Mapping.FixedLength

[FixedLengthRecord(FixedMode.AllowLessChars)]
public class Person

[FieldFixedLength(9)]
public String Name;

[FieldFixedLength(13)]
public String Surname;

[FieldFixedLength(6)]
public String Gender;

[FieldFixedLength(2)]
public Int32 OrderNum;

[FieldFixedLength(11)]
[FieldConverter(ConverterKind.Date, "dd-MM-yyyy")]
public DateTime BirthDate;




I have been couting it so many times and tried a lot of version but with no success. What's wrong?










share|improve this question



















  • 3





    [FieldFixedLength(11)] should be [FieldFixedLength(10)]. 01-01-2000 is 10 characters, not 11.

    – mjwills
    Nov 16 '18 at 12:47







  • 2





    "dd-MM-yyyy".Length == 10 - Note that the error message states that.

    – PaulF
    Nov 16 '18 at 12:47







  • 1





    I'd be wondering about the encoding of this file, including the use of combining characters, any specified or assumed encoding that FileHelpers is working with and whether what it's actually working is characters or code points.

    – Damien_The_Unbeliever
    Nov 16 '18 at 12:53







  • 2





    You did something wrong, and it gave an error. You changed it to something else (hint - AllowLessChars), and you got a different error. You fixed the first bug - but did you remember to reverse the second thing you tried?

    – mjwills
    Nov 16 '18 at 12:53







  • 1





    The problem that the records contains diacritic so the real size is different.

    – Chyu
    Nov 16 '18 at 13:14













1












1








1








I have this sample CSV file:



Filip Malýn Male 1218-02-1994
Božena Němcová Female1804-02-1820
Jan Žižka Male 0719-09-1360
Che Guevara Male 2714-06-1928
AntoinedeSaint-ExupéryMale 1529-06-1900


I load it in a code by this function:



FileHelperEngine<T>().ReadFile(fileName);


But it ends up with this error:



FileHelpers.BadUsageException: 'The string '18-02-1994' (length 10) at line 1 has less chars than the defined for BirthDate (11). You can use the [FixedLengthRecord(FixedMode.AllowLessChars)] to avoid this problem.'


And if I add [FixedLengthRecord(FixedMode.AllowLessChars)] to the code it ends up with this error:



FileHelpers.ConvertException: 'Error Converting 'al' to type: 'Int32'. '


This is a class I use:



using System;
using FileHelpers;

namespace ImportExport.Mapping.FixedLength

[FixedLengthRecord(FixedMode.AllowLessChars)]
public class Person

[FieldFixedLength(9)]
public String Name;

[FieldFixedLength(13)]
public String Surname;

[FieldFixedLength(6)]
public String Gender;

[FieldFixedLength(2)]
public Int32 OrderNum;

[FieldFixedLength(11)]
[FieldConverter(ConverterKind.Date, "dd-MM-yyyy")]
public DateTime BirthDate;




I have been couting it so many times and tried a lot of version but with no success. What's wrong?










share|improve this question
















I have this sample CSV file:



Filip Malýn Male 1218-02-1994
Božena Němcová Female1804-02-1820
Jan Žižka Male 0719-09-1360
Che Guevara Male 2714-06-1928
AntoinedeSaint-ExupéryMale 1529-06-1900


I load it in a code by this function:



FileHelperEngine<T>().ReadFile(fileName);


But it ends up with this error:



FileHelpers.BadUsageException: 'The string '18-02-1994' (length 10) at line 1 has less chars than the defined for BirthDate (11). You can use the [FixedLengthRecord(FixedMode.AllowLessChars)] to avoid this problem.'


And if I add [FixedLengthRecord(FixedMode.AllowLessChars)] to the code it ends up with this error:



FileHelpers.ConvertException: 'Error Converting 'al' to type: 'Int32'. '


This is a class I use:



using System;
using FileHelpers;

namespace ImportExport.Mapping.FixedLength

[FixedLengthRecord(FixedMode.AllowLessChars)]
public class Person

[FieldFixedLength(9)]
public String Name;

[FieldFixedLength(13)]
public String Surname;

[FieldFixedLength(6)]
public String Gender;

[FieldFixedLength(2)]
public Int32 OrderNum;

[FieldFixedLength(11)]
[FieldConverter(ConverterKind.Date, "dd-MM-yyyy")]
public DateTime BirthDate;




I have been couting it so many times and tried a lot of version but with no success. What's wrong?







c# csv export-to-csv filehelpers csv-import






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 3 '18 at 11:12







Chyu

















asked Nov 16 '18 at 12:44









ChyuChyu

157317




157317







  • 3





    [FieldFixedLength(11)] should be [FieldFixedLength(10)]. 01-01-2000 is 10 characters, not 11.

    – mjwills
    Nov 16 '18 at 12:47







  • 2





    "dd-MM-yyyy".Length == 10 - Note that the error message states that.

    – PaulF
    Nov 16 '18 at 12:47







  • 1





    I'd be wondering about the encoding of this file, including the use of combining characters, any specified or assumed encoding that FileHelpers is working with and whether what it's actually working is characters or code points.

    – Damien_The_Unbeliever
    Nov 16 '18 at 12:53







  • 2





    You did something wrong, and it gave an error. You changed it to something else (hint - AllowLessChars), and you got a different error. You fixed the first bug - but did you remember to reverse the second thing you tried?

    – mjwills
    Nov 16 '18 at 12:53







  • 1





    The problem that the records contains diacritic so the real size is different.

    – Chyu
    Nov 16 '18 at 13:14












  • 3





    [FieldFixedLength(11)] should be [FieldFixedLength(10)]. 01-01-2000 is 10 characters, not 11.

    – mjwills
    Nov 16 '18 at 12:47







  • 2





    "dd-MM-yyyy".Length == 10 - Note that the error message states that.

    – PaulF
    Nov 16 '18 at 12:47







  • 1





    I'd be wondering about the encoding of this file, including the use of combining characters, any specified or assumed encoding that FileHelpers is working with and whether what it's actually working is characters or code points.

    – Damien_The_Unbeliever
    Nov 16 '18 at 12:53







  • 2





    You did something wrong, and it gave an error. You changed it to something else (hint - AllowLessChars), and you got a different error. You fixed the first bug - but did you remember to reverse the second thing you tried?

    – mjwills
    Nov 16 '18 at 12:53







  • 1





    The problem that the records contains diacritic so the real size is different.

    – Chyu
    Nov 16 '18 at 13:14







3




3





[FieldFixedLength(11)] should be [FieldFixedLength(10)]. 01-01-2000 is 10 characters, not 11.

– mjwills
Nov 16 '18 at 12:47






[FieldFixedLength(11)] should be [FieldFixedLength(10)]. 01-01-2000 is 10 characters, not 11.

– mjwills
Nov 16 '18 at 12:47





2




2





"dd-MM-yyyy".Length == 10 - Note that the error message states that.

– PaulF
Nov 16 '18 at 12:47






"dd-MM-yyyy".Length == 10 - Note that the error message states that.

– PaulF
Nov 16 '18 at 12:47





1




1





I'd be wondering about the encoding of this file, including the use of combining characters, any specified or assumed encoding that FileHelpers is working with and whether what it's actually working is characters or code points.

– Damien_The_Unbeliever
Nov 16 '18 at 12:53






I'd be wondering about the encoding of this file, including the use of combining characters, any specified or assumed encoding that FileHelpers is working with and whether what it's actually working is characters or code points.

– Damien_The_Unbeliever
Nov 16 '18 at 12:53





2




2





You did something wrong, and it gave an error. You changed it to something else (hint - AllowLessChars), and you got a different error. You fixed the first bug - but did you remember to reverse the second thing you tried?

– mjwills
Nov 16 '18 at 12:53






You did something wrong, and it gave an error. You changed it to something else (hint - AllowLessChars), and you got a different error. You fixed the first bug - but did you remember to reverse the second thing you tried?

– mjwills
Nov 16 '18 at 12:53





1




1





The problem that the records contains diacritic so the real size is different.

– Chyu
Nov 16 '18 at 13:14





The problem that the records contains diacritic so the real size is different.

– Chyu
Nov 16 '18 at 13:14












1 Answer
1






active

oldest

votes


















0














Thanks all. The solution is adding an info about encoding of the file. In my case changing FileHelperEngine<T>().ReadFile(fileName); to FileHelperEngine<T>(Encoding.UTF8).ReadFile(fileName);.






share|improve this answer























  • Still doesn't match with the code though as you're saying that birth date is 11 characters but in reality it's just 10. Good that you solved your problem but this can't be the whole solution.

    – Lasse Vågsæther Karlsen
    Nov 28 '18 at 16:16











  • Yes, I have admitted this in a comment section below my question. In my opinion I wouldn't edit the code in question due to loss of continuity.

    – Chyu
    Nov 28 '18 at 16:21











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53338176%2fc-sharp-filehelpers-bad-computing-of-datetime-variable%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Thanks all. The solution is adding an info about encoding of the file. In my case changing FileHelperEngine<T>().ReadFile(fileName); to FileHelperEngine<T>(Encoding.UTF8).ReadFile(fileName);.






share|improve this answer























  • Still doesn't match with the code though as you're saying that birth date is 11 characters but in reality it's just 10. Good that you solved your problem but this can't be the whole solution.

    – Lasse Vågsæther Karlsen
    Nov 28 '18 at 16:16











  • Yes, I have admitted this in a comment section below my question. In my opinion I wouldn't edit the code in question due to loss of continuity.

    – Chyu
    Nov 28 '18 at 16:21















0














Thanks all. The solution is adding an info about encoding of the file. In my case changing FileHelperEngine<T>().ReadFile(fileName); to FileHelperEngine<T>(Encoding.UTF8).ReadFile(fileName);.






share|improve this answer























  • Still doesn't match with the code though as you're saying that birth date is 11 characters but in reality it's just 10. Good that you solved your problem but this can't be the whole solution.

    – Lasse Vågsæther Karlsen
    Nov 28 '18 at 16:16











  • Yes, I have admitted this in a comment section below my question. In my opinion I wouldn't edit the code in question due to loss of continuity.

    – Chyu
    Nov 28 '18 at 16:21













0












0








0







Thanks all. The solution is adding an info about encoding of the file. In my case changing FileHelperEngine<T>().ReadFile(fileName); to FileHelperEngine<T>(Encoding.UTF8).ReadFile(fileName);.






share|improve this answer













Thanks all. The solution is adding an info about encoding of the file. In my case changing FileHelperEngine<T>().ReadFile(fileName); to FileHelperEngine<T>(Encoding.UTF8).ReadFile(fileName);.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 28 '18 at 16:09









ChyuChyu

157317




157317












  • Still doesn't match with the code though as you're saying that birth date is 11 characters but in reality it's just 10. Good that you solved your problem but this can't be the whole solution.

    – Lasse Vågsæther Karlsen
    Nov 28 '18 at 16:16











  • Yes, I have admitted this in a comment section below my question. In my opinion I wouldn't edit the code in question due to loss of continuity.

    – Chyu
    Nov 28 '18 at 16:21

















  • Still doesn't match with the code though as you're saying that birth date is 11 characters but in reality it's just 10. Good that you solved your problem but this can't be the whole solution.

    – Lasse Vågsæther Karlsen
    Nov 28 '18 at 16:16











  • Yes, I have admitted this in a comment section below my question. In my opinion I wouldn't edit the code in question due to loss of continuity.

    – Chyu
    Nov 28 '18 at 16:21
















Still doesn't match with the code though as you're saying that birth date is 11 characters but in reality it's just 10. Good that you solved your problem but this can't be the whole solution.

– Lasse Vågsæther Karlsen
Nov 28 '18 at 16:16





Still doesn't match with the code though as you're saying that birth date is 11 characters but in reality it's just 10. Good that you solved your problem but this can't be the whole solution.

– Lasse Vågsæther Karlsen
Nov 28 '18 at 16:16













Yes, I have admitted this in a comment section below my question. In my opinion I wouldn't edit the code in question due to loss of continuity.

– Chyu
Nov 28 '18 at 16:21





Yes, I have admitted this in a comment section below my question. In my opinion I wouldn't edit the code in question due to loss of continuity.

– Chyu
Nov 28 '18 at 16:21



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53338176%2fc-sharp-filehelpers-bad-computing-of-datetime-variable%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Top Tejano songwriter Luis Silva dead of heart attack at 64

ReactJS Fetched API data displays live - need Data displayed static

政党