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;
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
|
show 3 more comments
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
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 thatFileHelpers
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
|
show 3 more comments
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
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
c# csv export-to-csv filehelpers csv-import
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 thatFileHelpers
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
|
show 3 more comments
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 thatFileHelpers
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
|
show 3 more comments
1 Answer
1
active
oldest
votes
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);
.
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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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);
.
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
add a comment |
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);
.
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
add a comment |
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);
.
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);
.
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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