icsharpcode / SharpDevelop

#develop (short for SharpDevelop) is a free IDE for .NET programming languages.
2.09k stars 773 forks source link

Debugger can't resolve types of dynamic assemblies #582

Open sven-n opened 10 years ago

sven-n commented 10 years ago

The debugger can't resolve types of dynamic assemblies. Here is a little example:

namespace DebugTest
{
    using System;
    using System.Reflection;
    using System.Reflection.Emit;

    class Program
    {
        public static void Main(string[] args)
        {
            var assemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(new AssemblyName("MyAssembly"), AssemblyBuilderAccess.Run);
            var moduleBuilder = assemblyBuilder.DefineDynamicModule("MyTypes");
            var typeBuilder = moduleBuilder.DefineType("MyException", TypeAttributes.Public, typeof(Exception));
            var myException = typeBuilder.CreateType();
            var instance = Activator.CreateInstance(myException);

            Console.ReadLine();
        }
    }
}

If you hold your mouse over "instance", it just shows the name of the type, but you can't expand and navigate through the properties and fields:

debugger

The watch window also doesn't work as expected, you can't even call GetType() on instance: debugger2

I debugged a bit and found Debugger.Value.CheckObject throws an Exception, because the objectInstance.Type is of TypeKind.Unknown and does not have a definition.

If you need more information, let me know.