Bugzilla – Bug 321315
Wrong line numbers in stack traces
Last modified: 2011-06-02 18:01:05 UTC
---- Reported by rodrigobamboo@gmail.com 2006-06-05 16:06:59 MST ---- using System; using System.IO; using System.Reflection.Emit; using System.Reflection; using System.Diagnostics.SymbolStore; namespace BugReport { public interface IFoo { void Bar(); } class Program { const string DocumentPath = "/temp/test.cs"; static void Main(string[] args) { IFoo foo = EmitFoo(); try { foo.Bar(); } catch (Exception x) { //Console.WriteLine(x); Assert(x.StackTrace.IndexOf(DocumentPath + ":10") != -1); } } static void Assert(bool condition) { if (!condition) throw new ApplicationException(); } static IFoo EmitFoo() { AppDomain currentDomain = AppDomain.CurrentDomain; string fname = Path.Combine(currentDomain.BaseDirectory, "bugged.dll"); AssemblyName name = new AssemblyName(); name.Name = Path.GetFileNameWithoutExtension(fname); AssemblyBuilder builder = currentDomain.DefineDynamicAssembly(name, AssemblyBuilderAccess.Save, Path.GetDirectoryName(fname), null); ModuleBuilder module = builder.DefineDynamicModule(Path.GetFileName(fname), true); ISymbolDocumentWriter document = module.DefineDocument(DocumentPath, SymDocumentType.Text, SymLanguageType.CSharp, Guid.Empty); TypeBuilder foo = module.DefineType("Foo", TypeAttributes.Public | TypeAttributes.Class, typeof(object)); foo.AddInterfaceImplementation(typeof(IFoo)); MethodBuilder bar = foo.DefineMethod("Bar", MethodAttributes.Public | MethodAttributes.Virtual, typeof(void), new Type[0]); ILGenerator il = bar.GetILGenerator(); il.MarkSequencePoint(document, 10, 0, 11, 0); il.ThrowException(typeof(ApplicationException)); // MONO uses the next sequence point as the line number for the // exception above, it should use the previous one il.MarkSequencePoint(document, 11, 0, 12, 0); il.Emit(OpCodes.Ret); foo.CreateType(); builder.Save(Path.GetFileName(fname)); return (IFoo)Activator.CreateInstance(Assembly.LoadFrom(fname).GetType("Foo")); } } } ---- Additional Comments From martin@ximian.com 2006-06-12 09:28:55 MST ---- What's the problem here, this works for me ? Unknown bug field "cf_op_sys_details" encountered while moving bug <cf_op_sys_details>Windows XP</cf_op_sys_details> Unknown operating system unknown. Setting to default OS "Other".