Comments (14)
Can you paste in a small (couple of rows) example where the issue occurs?
from csvhelper.
Hi, here is some additioinal information:
CsvHelper.1.8.0\lib\net40-client\CsvHelper.dll
Runtime version v4.0.30319
Version 1.8.0.22497
public class UserCsvModel
{
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Email { get; set; }
}
CsvFile contents inside []
[Id,FirstName,LastName,Email
1,v,k,[email protected],
2,v,k,[email protected],]
from csvhelper.
Did you use CsvWriter to create the contents of the file? How did the extra comma get on the end of the rows? What error are you seeing? What do you mean by manually modified and removed empty row at end?
from csvhelper.
Sorry, my mistake, I incorrectly removed unnecessary columns in last example.
CsvFile contents inside []
[Id,FirstName,LastName,Email,Address
1,v,k,[email protected],Some address
2,v,k,[email protected],]
An error occurred trying to read a record of type 'UserCsvModel'.
Row: '4' (1-based)
Field Index: '0' (0-based)
Field Name: 'Id'
Field Value: ''
System.Exception: is not a valid value for Int32. ---> System.IndexOutOfRangeException: Index was outside the bounds of the array.
at System.ComponentModel.BaseNumberConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value)
--- End of inner exception stack trace ---
at System.ComponentModel.BaseNumberConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value)
at System.ComponentModel.TypeConverter.ConvertFromString(String text)
at lambda_method(Closure , ICsvReader )
at CsvHelper.CsvReader.d__0`1.MoveNext() in C:\Projects\CsvHelper\src\CsvHelper\CsvReader.cs:line 585
Just try to write a csv file, remove last \r\n characters and then try to read it. there should be no line end on last row.
from csvhelper.
I'm not able to reproduce it based on this information. I tried what you suggested and it's working for me, so I must be missing something.
Can you create a small example console app, zip it up, and email it to me?
from csvhelper.
Paste this in CsvReaderTests.cs
class UserCsvModel {
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Email { get; set; }
public string Address { get; set; }
}
[Fact]
public void GetRecordsTest2()
{
var badCsv = @"Id,FirstName,LastName,Email,Address
1,v,k,[email protected],Some address
2,v,k,[email protected],1245";
var stringReader = new StringReader(badCsv);
var csvReader = new CsvReader(stringReader);
var records = csvReader.GetRecords<UserCsvModel>().ToList();
Assert.Equal( 2, records.Count );
for( var i = 1; i <= records.Count; i++ )
{
var record = records[i - 1] as UserCsvModel;
Assert.Equal( i, record.Id );
}
}
from csvhelper.
Have you succeeded with exception reproduction?
from csvhelper.
Sorry, been busy. I'm looking into it now.
from csvhelper.
I think it is a bad practice to use the same class variable between method calls and support it state. It is better to use method argument in this case and take advantage of method scope. You have char c variable inside CsvParser and you probably forgot to clean it in the beginning of ReadLine method. This produce problem.
from csvhelper.
That's pretty much the case. I'll have a fix committed in a minute here and I'll link the change set.
from csvhelper.
Are you saying that the char c
variable should be passed into Read()
?
from csvhelper.
It's committed. Essentially a one line fix. ffbbada
from csvhelper.
When we start to read next row do we really need to know what last character was? I may be wrong, but it seems to me that c can be local variable of ReadLine().
Thank you.
11.10.2012, 06:09, "Josh Close" [email protected]:
Are you saying that the char c variable should be passed into Read()?
—
Reply to this email directly or view it on GitHub.
Kind Regards, Костенко Владислав.
from csvhelper.
I will take a look.
from csvhelper.
Related Issues (20)
- Build error - HOT 3
- New compatibility issue regression due to `System.Linq.Async` inclusion HOT 5
- Microsoft.Bcl.AsyncInterfaces dependency error on System.Threading.Tasks.Extensions HOT 4
- ConfigurationException: 'Types that inherit IEnumerable cannot be auto mapped' when using custom class based on DynamicObject (NOT ExpandoObject) which also implements IDictionary HOT 3
- Missing "Product Version" in CsvHelper.dll HOT 1
- Column Name not displaying Using Mapping HOT 1
- Just thrown new exception by choice.
- Unexpected `InvalidCastException` in `TypeConverter<>` with nullable structs and value types HOT 2
- List<T>.ToAsyncEnumerable not accessible anymore after upgrade to CSVHelper 31.0.2 (.NET 8) HOT 5
- Set Custom Headers that derives from the property value. HOT 7
- Eliminate the columns if empty HOT 1
- Unregister ClassMap does not clear the previous maps if the same class is used HOT 2
- Getting problems with release build of my app using COM HOT 1
- add my report list columns' name as a header to the csv file when the HasHeaderRecord is set to false
- When Query from db and return IEnumable, will execute 2 times for sql query HOT 3
- Validate Header generate a very large message. HOT 2
- Header does not contain Quote, but some fields in row contain Quote, how should I read this kind of CSV HOT 4
- FastDynamicObject broke serialization HOT 7
- Using a ClassMap with custom type converter results in a "newed" object. HOT 1
- Using Custom TypeConverter causes dangerous/spurious CsvWriter behavior
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from csvhelper.