Click here to Skip to main content
16,011,988 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I have been following a post by nikhulion and answered by bijeesh. I am a novice at C# and would like to know how to actually compile and run the class resolution by bijeesh.

Code included here with error on assembly; Urgent assistance required please :-)

C#
private void WriteXmlMethod()
{
    string constring = ConfigurationManager.ConnectionStrings ["YourConnectionString"].ToString();
    SqlConnection con = new SqlConnection(constring);
    con.Open();
    string query = "select * from tbl_newsBee";
    SqlCommand cmd = new SqlCommand(query, con);
    SqlDataReader dr = cmd.ExecuteReader();
    XDocument doc = new XDocument();
    XDeclaration declaration = new XDeclaration("1.0", "utf-8", "yes");
    doc.Add(declaration);
    XElement element1 = new XElement("Newses");
    XElement element2 = null;
    while (dr.Read())
    {
        element2 = new XElement("News", new XAttribute("link", dr[2].ToString()), new XAttribute("des", dr[1].ToString()));
        element2.Add(dr[3].ToString());
        element1.Add(element2);
    }
    con.Close();
    string filename = Server.MapPath("E:/myXmlDoc.xml");
    doc.Save(filename);
}

Error that occurred:
The type 'System.ComponentModel.Component' 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' in:
C:\Users\Administrator\Documents\Visual Studio 2010\Projects\WtiteXml.cs
Line: 13
Column: 9
Other Info: TestXML

Edit by EdMan196: Added pre tags/formatting in general and made error message a bit more readable.
Posted
Updated 22-Feb-12 10:52am
v2

1 solution

Well the error says you have a reference missing so whatever you are using to compile the code (Visual Studio Solution/Project?). Whatever you are using you will need to add a reference to the library - what this means is you are telling the compiler where the system code library that your class needs to be compiled with, is. In Visual Studio it's very easy:

1. Right click on your project
2. Click "add Reference"
3. Go to the .Net tab
4. Find the item named (specifically) "System.ComponentModel.Component" or if that doesn't exist just add the "System.ComponentModel" one (which should exist). You may have to add the latter reference because System.ComponentModel.Component may be contained within the System.ComponentModel compiled code library (dll for file name).

Hope this helps,
Ed
 
Share this answer
 
Comments
becket_c 22-Feb-12 17:13pm    
Thanks for the prompt reponse, appreciate!! I actually overcame that by adding the System Reference. The lack of know how on my side is the problem. When I try compiling it says that it is missing an entry point for the Main method. I just have no idea on how get this compiled and eventually run. I have attached the error;

Error 1 Program 'C:\Users\Administrator\Documents\Visual Studio 2010\Projects\ItcmToCmdb\obj\x86\Release\ItcmToCmdb.exe' does not contain a static 'Main' method suitable for an entry point ItcmToCmdb
Ed Nutting 22-Feb-12 17:28pm    
All programs require a Main entry point and all programs may only have one Main entry point - it is the first bit of code that should be called. Might I suggest you create a new, bog standard windows forms project and look at the Programs.cs file. Also research the Main method on MSDN. Unfortunately I do not have time to write more now otherwise I would. I hope this small amount of info helps,
Ed

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