Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / CLR / July 2004

Tip: Looking for answers? Try searching our database.

Dynamic assembly not persisting correctly.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Frank - 28 Jul 2004 07:21 GMT
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
Frank - 29 Jul 2004 01:08 GMT
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

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.