I am emitting a dynamic assembly (marked with the RunAndSave flag).
I can successfully instantiate the "dynamic" class in my dynamic
assembly. I can successfully call a method on that dynamic class.
When I call the assembly builder's Save() method, an assembly dll
(e.g., MyDynamicAssembly.dll) is created and it's 2K, but contains no
IL or classes.
ILDASM shows the following:
-----------------------------
.assembly MyDynamicAssembly
{
.hash algorithm 0x00008004
.ver 0:0:0:0
}
.module RefEmit_OnDiskManifestModule
// MVID: {299B3249-3C2C-4751-B239-B450A88FFCED}
.imagebase 0x00400000
.subsystem 0x00000003
.file alignment 512
.corflags 0x00000001
// Image base: 0x06d10000
-----------------------------
That's it. No classes or IL. Is it possible to persist an assembly
with all the IL and type information, so that I don't have to recreate
it every time the app runs?
Thanks a million,
Frank
BTW, here is some sample code that exhibits the problem:
using System;
using System.Reflection;
using System.Reflection.Emit;
namespace TestApp
{
public class Test
{
public static void DoTest()
{
AppDomain appDomain = AppDomain.CurrentDomain;
AssemblyName assemblyName = new AssemblyName();
assemblyName.Name = "MyDynamicAssembly";
AssemblyBuilder assemblyBuilder =
appDomain.DefineDynamicAssembly(assemblyName,
AssemblyBuilderAccess.RunAndSave);
ModuleBuilder moduleBuilder =
assemblyBuilder.DefineDynamicModule("MyDynamicAssembly");
TypeBuilder typeBuilder =
moduleBuilder.DefineType("MyDynamicClass", TypeAttributes.Public);
ConstructorBuilder constructorBuilder =
typeBuilder.DefineDefaultConstructor(MethodAttributes.Public);
typeBuilder.CreateType();
assemblyBuilder.Save("MyDynamicAssembly.dll");
}
}
}
> I am emitting a dynamic assembly (marked with the RunAndSave flag).
>
[quoted text clipped - 27 lines]
> Thanks a million,
> Frank
Fabian Schmied - 29 Jul 2004 09:03 GMT
> BTW, here is some sample code that exhibits the problem:
[...]
> ModuleBuilder moduleBuilder =
> assemblyBuilder.DefineDynamicModule("MyDynamicAssembly");
[...]
The module you are defining is transient, so it won't be saved to disk. To
define a persistent module, use one of the DefineDynamicModule overloads
that let you specify a filename (in addition to the module name).
Fabian
Frank - 29 Jul 2004 22:23 GMT
Thanks a million. That worked.
> > BTW, here is some sample code that exhibits the problem:
> >
[quoted text clipped - 8 lines]
>
> Fabian