On Fri, 18 Jun 2004 10:12:01 -0700, Ricardo
[quoted text, click to view] <Ricardo@discussions.microsoft.com> wrote:
> I need to open an assembly, change some custom attribute's values and
> then re-write the assembly without re-compiling it.
> I tried using Reflection.Emit, but I couldn't cast
> (System.Reflection.)Assembly to
> (System.Reflection.Emit.)AssemblyBuilder, which is the class where
> custom attributes are writeable (in System.Reflection.Assembly they're
> just readable) and has a "save" method.>
Yes, this is not possible.
[quoted text, click to view] > What's the difference between a dynamic assembly and a common one??
A dynamic assembly has been created using Reflection.Emit. A non-dynamic
assembly cannot be converted to a dynamic assembly (unless you manually
copy each module, type, and member).
[quoted text, click to view] > I also read some info about this IMetaDataImport.IMetaDataAssemblyImport
> interface which is exposed via IMetaDataDispenser interface, and
> provides a way to change assembly's metadata and persist this changes,
> but I do not have enough documentation. I would appreciate some help,
> source code samples, whatever...
IMetaDataImport, -Emit, -AssemblyImport, -AssemblyEmit, and -DispenserEx
are documented in the .NET SDK (Tool Developers Guide\Docs). I tried to
use the IMetaDataDispenserEx interface for loading modules some time ago,
that works fine. You can use IMetaDataEmit to add or change some custom
attributes, no problem (removing them would be more difficult). Then, you
can use IMetaDataEmit to save the modules to files. However this will only
save the metadata, not the PE file layout, managed code, and unmanaged
code, so it's probably not what you want. Unless you do the rest yourself,
that is.
Fabian
--