mono-api-assembly.html

Assemblies

Synopsis

#include <metadata/assembly.h> typedef struct _MonoImage MonoImage; typedef struct _MonoAssembly MonoAssembly; typedef struct { const char *name; const char *culture; const char *hash_value; const guint8* public_key; guchar public_key_token [MONO_PUBLIC_KEY_TOKEN_LENGTH]; guint32 hash_alg; guint32 hash_len; guint32 flags; guint16 major, minor, build, revision; } MonoAssemblyName; MonoAssembly* mono_assembly_open (const char *filename, MonoImageOpenStatus *status); void mono_assembly_close (MonoAssembly *assembly); MonoAssembly* mono_assembly_load (MonoAssemblyName *aname, const char *basedir, MonoImageOpenStatus *status); MonoAssembly* mono_assembly_load_full (MonoAssemblyName *aname, const char *basedir, MonoImageOpenStatus *status, gboolean refonly); MonoAssembly* mono_assembly_loaded (MonoAssemblyName *aname); MonoImage* mono_assembly_get_image (MonoAssembly *assembly); MonoAssembly* mono_assembly_get_main (void); G_CONST_RETURN gchar * mono_assembly_getrootdir (void); void mono_assembly_addref (MonoAssembly *assembly); gboolean mono_assembly_name_parse (const char *name, MonoAssemblyName *aname); void mono_assembly_name_free (MonoAssemblyName *aname); char* mono_stringify_assembly_name (MonoAssemblyName *aname); gboolean mono_assembly_names_equal (MonoAssemblyName *l, MonoAssemblyName *r);

Assembly Loading

mono_assembly_open
MonoAssembly* mono_assembly_open (const char *filename, MonoImageOpenStatus *status)

Parameters

filename:
Opens the assembly pointed out by this name
status:
where a status code can be returned
Returns
a pointer to the MonoAssembly if filename contains a valid assembly or NULL on error. Details about the error are stored in the status variable.
Remarks

mono_assembly_open opens the PE-image pointed by filename, and loads any external assemblies referenced by it.

mono_assembly_close
void mono_assembly_close (MonoAssembly *assembly)

Parameters

assembly:
the assembly to release.
Remarks

This method releases a reference to the assembly. The assembly is only released when all the outstanding references to it are released.

mono_assembly_load
MonoAssembly* mono_assembly_load (MonoAssemblyName *aname, const char *basedir, MonoImageOpenStatus *status)

Parameters

aname:
A MonoAssemblyName with the assembly name to load.
basedir:
A directory to look up the assembly at.
status:
a pointer to a MonoImageOpenStatus to return the status of the load operation
Returns
the assembly referenced by aname loaded or NULL on error. On error the value pointed by status is updated with an error code.
Remarks

Loads the assembly referenced by aname, if the value of basedir is not NULL, it attempts to load the assembly from that directory before probing the standard locations.

mono_assembly_load_full
MonoAssembly* mono_assembly_load_full (MonoAssemblyName *aname, const char *basedir, MonoImageOpenStatus *status, gboolean refonly)

Parameters

aname:
A MonoAssemblyName with the assembly name to load.
basedir:
A directory to look up the assembly at.
status:
a pointer to a MonoImageOpenStatus to return the status of the load operation
refonly:
Whether this assembly is being opened in "reflection-only" mode.
Returns
the assembly referenced by aname loaded or NULL on error. On error the value pointed by status is updated with an error code.
Remarks

Loads the assembly referenced by aname, if the value of basedir is not NULL, it attempts to load the assembly from that directory before probing the standard locations. If the assembly is being opened in reflection-only mode (refonly set to TRUE) then no assembly binding takes place.

mono_assembly_loaded
MonoAssembly* mono_assembly_loaded (MonoAssemblyName *aname)

Parameters

aname:
an assembly to look for.
Returns
NULL If the given aname assembly has not been loaded, or a pointer to a MonoAssembly that matches the MonoAssemblyName specified.

Working with Assemblies

mono_assembly_get_image
MonoImage* mono_assembly_get_image (MonoAssembly *assembly)

Parameters

assembly:
The assembly to retrieve the image from
Returns
the MonoImage associated with this assembly.
mono_assembly_get_main
MonoAssembly* mono_assembly_get_main (void)

Returns

the assembly for the application, the first assembly that is loaded by the VM
mono_assembly_getrootdir
G_CONST_RETURN gchar * mono_assembly_getrootdir (void)

Returns

a string with the directory, this string should not be freed.
Remarks

Obtains the root directory used for looking up assemblies.

mono_assembly_addref
void mono_assembly_addref (MonoAssembly *assembly)

Parameters

assemnly:
the assembly to reference
Remarks

This routine increments the reference count on a MonoAssembly. The reference count is reduced every time the method mono_assembly_close() is invoked.

Assembly Names

The MonoAssemblyName contains the full identity of an assembly (name, culture, public key, public key token, version and any other flags).

These unmanaged objects represent the System.Reflection.AssemblyName managed type.

mono_assembly_name_parse
gboolean mono_assembly_name_parse (const char *name, MonoAssemblyName *aname)

Parameters

name:
name to parse
aname:
the destination assembly name
Returns
true if the name could be parsed.
Remarks

Parses an assembly qualified type name and assigns the name, version, culture and token to the provided assembly name object.

mono_assembly_name_free
void mono_assembly_name_free (MonoAssemblyName *aname)

Parameters

aname:
assembly name to free
Remarks

Frees the provided assembly name object. (it does not frees the object itself, only the name members).

mono_stringify_assembly_name
char* mono_stringify_assembly_name (MonoAssemblyName *aname)

Parameters

aname:
the assembly name.
Returns
a newly allocated string with a string representation of the assembly name.
Remarks

Convert aname into its string format. The returned string is dynamically allocated and should be freed by the caller.