Click here to Skip to main content
15,897,273 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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 :

C#
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

[edit]Code block added - OriginalGriff[/edit]
Posted
Updated 21-Dec-13 3:48am
v3
Comments
Davood Riazi 22-Dec-13 1:06am    
Hi ,


When i add <pre lang="cs">using System.ComponentModel.MarshalByValueComponent;</pre>

the compiler says that :

the type or namespace name 'componentmodel' does not exist in the namespace 'system'

but i have added System.ComponentModel to my references in my project .

What should i do for solving it ?


Thanks for helping .

You don't - the reference is already there:
System.ComponentModel.MarshalByValueComponent[^] says it is in System.DLL, which is added by default to all new projects.

You may have to add
C#
using System.ComponentModel;
to your using list though.
 
Share this answer
 
Comments
Karthik_Mahalingam 21-Dec-13 21:22pm    
5
Davood Riazi 22-Dec-13 1:07am    
Hi ,


When i add <pre lang="cs">using System.ComponentModel.MarshalByValueComponent;</pre>

the compiler says that :

the type or namespace name 'componentmodel' does not exist in the namespace 'system'

but i have added System.ComponentModel to my references in my project .

What should i do for solving it ?


Thanks for helping .
OriginalGriff 22-Dec-13 1:48am    
Don't add
using System.ComponentModel.MarshalByValueComponent;
Is the simple solution! :laugh:
All you need is
using System.ComponentModel;
Which is the namespace MarshalByValueComponent is in.
Davood Riazi 22-Dec-13 2:06am    
Hi,

I solved it by adding "System.ComponentModel.DataAnnotations" reference to assemblies then i

added using System.ComponentModel.DataAnnotations; in my using .

Thanks
OriginalGriff 22-Dec-13 3:58am    
You're welcome!
as Griff said it is available in Using System; namespace.

you can use this object directly like this "System.ComponentModel.MarshalByValueComponent"

check this link: system.componentmodel.marshalbyvaluecomponent[^]
 
Share this answer
 
Hi,

I solved it by adding "System.ComponentModel.DataAnnotations" reference to assemblies then i

added using System.ComponentModel.DataAnnotations; in my using .

Thanks
 
Share this answer
 
Hi,

I solved it by adding "System.ComponentModel.DataAnnotations" reference to assemblies then i

added using System.ComponentModel.DataAnnotations; in my using .

Thanks
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900