Cannot Load Late Boung Protected Assembly

L

localhost

Help!

I have a WinForm that at startup creates a custom principal (inherits
from GenericPrincipal) and assign it and its roles to the current
thread.

The WinForm then loads a class library via Reflection. The class
library works fine until I assign a security attribute to the class
like this:

[System.Security.Permissions.PrincipalPermission(System.Security.Permissions.SecurityAction.Demand
,
Role="FormUser")]
public class TestForm : BaseForm
{

This "class library" is actually a WinForm that I compiled as a class
library in the VS.NET 2003 Project settings.

Anyway, when the main form loads the class library form, I get this
error:

An unhandled exception of type
'System.Reflection.ReflectionTypeLoadException' occurred in
mscorlib.dll
Additional Information: One or more fo the types in the assembly
unable to load.


The loader code looks like this:

Assembly childAssembly = Assembly.LoadFrom( loadInfo );
foreach ( System.Reflection.Module childModule in
childAssembly.GetModules() )
{
try
{
foreach( Type childType in childModule.GetTypes() )
{
if ( childType.Name.ToLower().StartsWith("subsystem") == true
)
{
if ( TestChildForm(childType) == true )
{
Form testForm =
(Form)Activator.CreateInstance(childType) ;
}
}
}
}
catch( Exception xxx )
{
string fjjf = xxx.ToString();
int ghjg=4;
}
}
 
Y

Ying-Shen Yu[MSFT]

Hi,

This exception that is thrown by the Module.GetTypes method if any of the
classes in a module cannot be loaded.
You may catch this exception then check the follow properites:
InnerException,
LoaderExceptions
Types
and the StackTrack properties ,

hopefully we could get more information about this issue, which will be
helpful to find the cause of this type load failure.

Also if it is possible to reproduce this issue in a small sample, please
feel free to send it to me by mail to let me take a look at it.

Thanks!

Best regards,

Ying-Shen Yu [MSFT]
Microsoft Community Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
This mail should not be replied directly, please remove the word "online"
before sending mail.
 
L

localhost

I will try to wrap up a simple sample. However, I think a good
solution would be for me to create a new "throwaway" App Domain and
load the Type into that and inspect it, it might be easier to trap the
exception.

I have not had success with a try...catch System.Exception, I think
because mscorlib.dll is throwing the exception which is happening at a
lower level than my Exception handler. Does that make sense?
 
Y

Ying-Shen Yu[MSFT]

Hi,

Thanks for your reply!

I'm not very clear about the actual scenario in your app now, however since
the ReflectionTypeLoadException is an exception class derived from
System.Exception, try catch block should take effect.

Maybe you need check if you had disabled option "break in when exception"
(first-chance exception) in VS.NET IDE "Debug"->"Exceptions" settings, if
this option is enabled, the debugger will break in before your exception
handler.

If the exception still could not be caught, you may try adding an event
handler to AppDomain.UnhandledException event, the thrown exception object
is in UnhandledExceptionEventArgs.ExceptionObject, you may need cast it to
a proper type before getting it's properties.

If you still have trouble to get these information or have any updates to
this issue , please feel free to let me know.

Best wishes,

Ying-Shen Yu [MSFT]
Microsoft Community Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
This mail should not be replied directly, please remove the word "online"
before sending mail.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top