IsAssembly( )

  • Thread starter Thread starter Thom Little
  • Start date Start date
T

Thom Little

Is there a capability in the Assembly class to verify that the file being
process actually contains Assemblies prior to processing them?

Currently I do an Assembly.LoadFrom( ) followed by a GetTypes( ) and trap
the exception that is thrown. This works but the performance is of course
suboptimal.

What I am holing for is something like IsAssembly( ) can be called to
validate the file prior to processing.
 
Thom,

An assembly can not contain another assembly. =)

What you could try and do is get the modules in the assembly (through a
call to GetModules), iterate through those, and call the IsResource method
on the module. If the module is not a resource, then I would think it
contains types of some kind. Hopefully, this will not throw an exception.

Hope this helps.
 
I think I was mumbling ... what I am doing is ...

private void btnLoadAssembly_Click( object sender, System.EventArgs e )
{
if ( dlgOpen.ShowDialog( ) == DialogResult.OK )
{
txtAssemblyName.Text = dlgOpen.FileName ;
Assembly oAssembly = Assembly.LoadFrom( txtAssemblyName.Text );
Type[] types = oAssembly.GetTypes( );
lbTypes.Items.Clear( );
foreach( Type oType in types )
lbTypes.Items.Add( oType.FullName );
}
}

If the module does not contain assemblies an exception is thrown on the
LoadFrom( ) that I handle. I would like to trap this condition before the
LoadFrom( ) is issued instead of waiting until the exception is thrown.
 
Back
Top