Hi,

can anyone solve my problem in c# .net 2012 ?

when i run my project the compiler fails to compile in line 27 -->(GetDataTabletFromCSVFile Function) and shows me 4 errors as following :

1- Error 3 The type 'System.ComponentModel.IListSource' is defined in an assembly that is not referenced. You must add a reference to assembly 'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. D:\sample\sqlbulkcopy\ReadCSVFile\ReadCSVFile\Program.cs 27 34 ReadCSVFile

2 -Error 1 The type 'System.ComponentModel.ISupportInitialize' is defined in an assembly that is not referenced. You must add a reference to assembly 'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. D:\sample\sqlbulkcopy\ReadCSVFile\ReadCSVFile\Program.cs 27 34 ReadCSVFile

3- Error 2 The type 'System.ComponentModel.ISupportInitializeNotification' is defined in an assembly that is not referenced. You must add a reference to assembly 'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. D:\sample\sqlbulkcopy\ReadCSVFile\ReadCSVFile\Program.cs 27 34 ReadCSVFile

4- Error 4 The type 'System.ComponentModel.MarshalByValueComponent' is defined in an assembly that is not referenced. You must add a reference to assembly 'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. D:\sample\sqlbulkcopy\ReadCSVFile\ReadCSVFile\Program.cs 27 34 ReadCSVFile

this is my source code :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
using Microsoft.VisualBasic.FileIO;


namespace ReadCSVFile

    class Program
    {
        static void Main()
        {
            string csv_file_path = @"C:\csvtest.txt";

            DataTable csvData = GetDataTabletFromCSVFile(csv_file_path);

            Console.WriteLine("Rows count:" + csvData.Rows.Count);

            Console.ReadLine();
        }


        private static DataTable GetDataTabletFromCSVFile(string csv_file_path)
        {
            DataTable csvData = new DataTable();

            try
            {

                using (TextFieldParser csvReader = new TextFieldParser(csv_file_path))
                {
                    csvReader.SetDelimiters(new string[] { "," });
                    csvReader.HasFieldsEnclosedInQuotes = true;
                    string[] colFields = csvReader.ReadFields();
                    foreach (string column in colFields)
                    {
                        DataColumn datecolumn = new DataColumn(column);
                        datecolumn.AllowDBNull = true;
                        csvData.Columns.Add(datecolumn);
                    }

                    while (!csvReader.EndOfData)
                    {
                        string[] fieldData = csvReader.ReadFields();
                        //Making empty value as null
                        for (int i = 0; i < fieldData.Length; i++)
                        {
                            if (fieldData[i] == "")
                            {
                                fieldData[i] = null;
                            }
                        }
                        csvData.Rows.Add(fieldData);
                    }
                }
            }
            catch (Exception ex)
            {
            }
            return csvData;
        }
    }
}

How can i add "System.ComponentModel.MarshalByValueComponent" reference to assembly in my project ?

thanks

The reference is System.ComponentModel, MarshalByValueComponent is a class in the namespace.

You should add a reference in your project to the assemby from framework entitled as System.ComponentModel.DataAnnotations.

Usually this is done automatically by the nuget package manager if you select to add the EntityFramework from nuget.org to your project

Hope this helps

Hi ,

Thanks for your reply .

How can i add System.ComponentModel.DataAnnotations to my project ?

Could you help me to add it step by step .

Hi,
I solved it by adding "System.ComponentModel.DataAnnotations" reference to assemblies then i added
using System.ComponentModel.DataAnnotations;;
in my using .

Thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.