i use of this code for serialize in code compiler :
public void GetItemSource() { CSharpCodeProvider c = new CSharpCodeProvider(); ICodeCompiler icc = c.CreateCompiler(); CompilerParameters cp = new CompilerParameters(); cp.GenerateExecutable = false; cp.ReferencedAssemblies.Add(typeof(System.Data.EntityClient.EntityCommand).Assembly.Location); cp.ReferencedAssemblies.Add("system.dll"); cp.ReferencedAssemblies.Add("system.xml.dll"); cp.ReferencedAssemblies.Add("system.data.dll"); cp.ReferencedAssemblies.Add("System.Runtime.Serialization.Formatters.Soap.dll"); cp.ReferencedAssemblies.Add("system.drawing.dll"); cp.ReferencedAssemblies.Add("System.Core.dll"); cp.ReferencedAssemblies.Add("System.Xml.Linq.dll"); cp.ReferencedAssemblies.Add("System.Web.Services.dll"); cp.ReferencedAssemblies.Add("System.Runtime.Serialization.dll"); cp.CompilerOptions = "/t:library"; cp.GenerateInMemory = true; StringBuilder sb = new StringBuilder(""); sb.Append("using System;\n"); sb.Append("using System.Xml;\n"); sb.Append("using System.Data;\n"); sb.Append("using System.Data.SqlClient;\n"); sb.Append("using System.Linq;\n"); sb.Append("using System.Collections.Generic;\n"); sb.Append("using System.Runtime.Serialization;\n"); sb.Append("using System.Xml.Serialization;\n"); sb.Append("using System.IO.IsolatedStorage;\n"); sb.Append("using System.Runtime.Serialization.Formatters.Binary;"); sb.Append("using System.IO;\n"); sb.Append("using System.Text;\n"); sb.Append("[Serializable()] \n"); sb.Append(" public class QueryList \n"); sb.Append("{ \n"); sb.Append("public string Name {get; set;} \n"); sb.Append("} \n"); sb.Append("public class GetData{ \n"); sb.Append("public string ItemSource(){\n"); sb.Append(" List
i end line i meet error
but when i that code run without code compiler every thing is ok
but in code compiler i don't serialize it
please help me
thanks
Jignesh TrivediPosted Jan 30, 2012, 3:10 AM
Please replace two in above code (ID Property does not exist).
sb.Append(@" list.Add(new QueryList() { Name =""Jenifer"" });");
sb.Append(@" list.Add(new QueryList() { Name =""Adam"" });"); sb.Append(" string str = ToXml(list);\n");
and following line not work in ur code.
sb.Append(" serializer.Serialize(xmlWriter, pparam);\n");
find alternate for same.
hope this help.