I tried to create a complier on which Complile my code wriiten in c#.net. I am working on debugger i have create complier but is there is a way through which i can put a break point on my code file and when click on the Run button it will be stop where i put break point Please tell me if any body knows the code how we put the break point on the program c# files
Break points aren't part of the compiled binary - although you could inject calls to Debugger.Break
into your code.
You may want to look at the debugger API.
Thanks for your response. i using the following complile code.
String code="using System;\r\nnamespace PATNI.Script\r\n{\r\n\tpublic partial class Program\r\n\t{\r\n\t\tstatic int Main()\r\n\t\t{\r\n\t\t\t\r\n\t\t\treturn 0;\r\n\t\t}\r\n\t}\r\n}\r\n";
string exePath = Application.StartupPath+"\"+DateTime.Now.ToString("ddMMyyyyHHmmssff")+".exe"; if (dummyDoc != null) { CSharpCodeProvider loCompiler = new CSharpCodeProvider();
//CodeDomProvider loCompiler = CodeDomProvider.CreateProvider("CSharp");
//ICodeCompiler loCompiler = new CSharpCodeProvider().CreateCompiler();
//CompilerParameters loParameters = new CompilerParameters(null,exePath,true);
CompilerParameters loParameters = new CompilerParameters();
// *** Start by adding any referenced assemblies
loParameters.ReferencedAssemblies.Add("System.dll");
loParameters.ReferencedAssemblies.Add("System.Windows.Forms.dll");
loParameters.OutputAssembly = exePath;
//loParameters.ReferencedAssemblies.Add(typeof(IScript).Assembly.Location);
loParameters.GenerateExecutable = true;
// *** Load the resulting assembly into memory
loParameters.GenerateInMemory = false;
loParameters.TempFiles= new TempFileCollection(Environment.GetEnvironmentVariable("TEMP"), true);
loParameters.IncludeDebugInformation=true;
loParameters.TempFiles.KeepFiles = true ;
loParameters.CompilerOptions+= " /debug";
// *** Now compile the whole thing
CompilerResults loCompiled = loCompiler.CompileAssemblyFromSource(loParameters, code);
//DLL.CreateInstance(t.FullName, false, System.Reflection.BindingFlags.Default, null, new object[] { engine }, null, null);
if (loCompiled.Errors.HasErrors)
{
string lcErrorMsg = "";
// *** Create Error String
lcErrorMsg = loCompiled.Errors.Count.ToString() + " Errors:";
for (int x = 0; x < loCompiled.Errors.Count; x++)
lcErrorMsg = lcErrorMsg + "\r\nLine: " + loCompiled.Errors[x].Line.ToString() + " - " +
loCompiled.Errors[x].ErrorText;
MessageBox.Show(lcErrorMsg + "\r\n\r\n" + dummyDoc.docSAS.Contents, "Compiler Demo", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
Assembly loAssembly = loCompiled.CompiledAssembly;
Type t = loAssembly.GetType("PATNI.Script.Program");
//// *** Retrieve an object reference - since this object is 'dynamic' we can't explicitly
//// *** type it so it's of type Object
//object loObject = loAssembly.CreateInstance("PATNI.Script.Program");
if (t == null)
{
MessageBox.Show("Couldn't load class.");
return;
}
try
{
// BindingFlags enumeration specifies flags that control binding and
// the way in which the search for members and types is conducted by reflection.
// The following specifies the Access Control of the bound type
BindingFlags bflags = BindingFlags.DeclaredOnly | BindingFlags.Public
| BindingFlags.NonPublic | BindingFlags.Instance;
object loResult = t.InvokeMember("Main", BindingFlags.CreateInstance, null, null, null);
if (System.Diagnostics.Debugger.IsAttached)
{
ReflectionCheck(exePath); System.Diagnostics.Debugger.Launch(); } else t.InvokeMember("Main", bflags | BindingFlags.InvokeMethod, null, loResult, null); } catch (Exception loError) { MessageBox.Show(loError.Message, "Compiler Demo", MessageBoxButtons.OK, MessageBoxIcon.Information); }
it will genraate and create PDB files but please i ma not able to genarate code by using or not able to put break points the above code is still line in Rich text box Please help me?