Hi all,
I am having problem in loading types from an assembly using reflection.
I am using:
1. Windows Server 2003 64-Bit
2. Microsoft .NET Framework 1.1
3. IIS 6.0
My application is an ASP.NET web application and this application can
be started with providing log-in credentials through a logon page.
These credentials are nothing but the users organizational network
userid/password. The application will impersonate the user by examining
the Active Directory, and then proceed. I am using the windows
authentication mode -- following are the entries of my web.config file:
<authentication mode="Windows"/>
<identity impersonate="true"/>
In IIS, I am using both "Integrated Windows Authentication" and
"Anonymous Access".
Also, my application pool uses "Local System" identity.
Now, after calling the Impersonate() method of the WindowsIdentity
class, I am loading an assembly (the assembly is NOT stored in GAC)
like:
Assembly a = Assembly.LoadFrom("myassembly.dll");
IMyType vType = (IMyType)Activator.CreateInstance(a.GetType("mytype",
false, true));
Now, when I run this application, depending on the user, two different
things happen:
Scenario 1: The userid that I pass in the logon screen is the userid of
a user who is a member of the administrators group of the web server.
Result: Works fine.
Scenario 2: The userid that I pass in the logon screen is the userid of
a user who is NOT a member of the administrators group of the web
server.
Result: Getting the following error:
One or more of the types in the assembly unable to load.
System.Reflection.Module.GetTypesInternal(StackCrawlMark& stackMark) at
System.Reflection.Assembly.GetTypes()
Can anyone suggest any remedy please?
Regards,
JJ
JJ - 24 Jul 2006 14:26 GMT
Little correction--the error actually comes from the line:
foreach(System.Type t in a.GetTypes()) {
Response.Write(string.Format("<br>Type {0}:{1}",++count,t.Name));
}
which I am using for debugging.
> Hi all,
>
[quoted text clipped - 44 lines]
> Regards,
> JJ
Peter Ritchie [MVP] - 24 Jul 2006 14:57 GMT
You generally want to use a complete path with LoadFrom. While the current
directory is usually C:\Windows\System (or %SystemRoot%\system32) there's no
real guarentee that will be the case when you code is executed.
Ideally you should either place the full path to your assembly in a config
file, or the directory to the assembly in the config file. That makes life
so much easier. Ignore this if you're just using the hard-coded path as an
example...

Signature
http://www.peterRitchie.com/blog/
Microsoft MVP, Visual Developer - Visual C#
> Hi all,
>
[quoted text clipped - 39 lines]
> System.Reflection.Module.GetTypesInternal(StackCrawlMark& stackMark) at
> System.Reflection.Assembly.GetTypes()
JJ - 24 Jul 2006 15:10 GMT
Thanks, Peter.
The "myassembly.dll" is a dummy name, and I am actually using the
complete path.
Regards,
JJ
Peter wrote:
> You generally want to use a complete path with LoadFrom. While the current
> directory is usually C:\Windows\System (or %SystemRoot%\system32) there's no
[quoted text clipped - 52 lines]
> > System.Reflection.Module.GetTypesInternal(StackCrawlMark& stackMark) at
> > System.Reflection.Assembly.GetTypes()
JJ - 25 Jul 2006 06:38 GMT
I tried configuring the .NET framework security configuration -- still
did not work.
Regards,
JJ
> Thanks, Peter.
>
[quoted text clipped - 61 lines]
> > > System.Reflection.Module.GetTypesInternal(StackCrawlMark& stackMark) at
> > > System.Reflection.Assembly.GetTypes()
JJ - 25 Jul 2006 06:56 GMT
Resolved.
Checked the security level of
"C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\Temporary ASP.NET Files"
and done.
JJ
> I tried configuring the .NET framework security configuration -- still
> did not work.
[quoted text clipped - 67 lines]
> > > > System.Reflection.Module.GetTypesInternal(StackCrawlMark& stackMark) at
> > > > System.Reflection.Assembly.GetTypes()