Groups | Blog | Home
all groups > dotnet clr > july 2004 >

dotnet clr : Dynamic assembly not persisting correctly.


google NO[at]SPAM xemaps.com
7/27/2004 11:21:44 PM
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
7/28/2004 5:08:34 PM
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");
}
}
}
[quoted text, click to view]

Fabian Schmied
7/29/2004 10:03:45 AM
[quoted text, click to view]
[...]

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).

Frank
7/29/2004 2:23:00 PM
Thanks a million. That worked.


[quoted text, click to view]

AddThis Social Bookmark Button