.NET Framework Bookmark and Share   
 index > Common Language Runtime > Assembly.GetTypes() does not work
 

Assembly.GetTypes() does not work

Hi,

I am using reflection to load a dll and I am getting the following exception when I try to get the Assembly types using .GetTypes().  Please advice!

 

System.Reflection.ReflectionTypeLoadException was unhandled
  Message="Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information."
  Source="mscorlib"
  StackTrace:
       at System.Reflection.Module.GetTypesInternal(StackCrawlMark& stackMark)
       at System.Reflection.Assembly.GetTypes()
       at ReflectAssembly.Class1.Main(String[] args) in C:\Documents and Settings\aalamo\Desktop\ReflectAssembly\Class1.cs:line 48
       at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()

C_Geek

I guess assembly (assembly 1) you're trying to reflect to get types references types defined in the another assembly (assembly 2).

When you're trying to get a list of  types defined in assembly 1 it (for some nasty reason) fails to load assembly 2 and stops with the exception you'd posted.

Follow the advice given by MS developer and examine LoaderExceptions property of exception to find out that went wrong.

 

 

Igor Sukhov

I guess assembly (assembly 1) you're trying to reflect to get types references types defined in the another assembly (assembly 2).

When you're trying to get a list of  types defined in assembly 1 it (for some nasty reason) fails to load assembly 2 and stops with the exception you'd posted.

Follow the advice given by MS developer and examine LoaderExceptions property of exception to find out that went wrong.

 

 

Igor Sukhov
"examine LoaderExceptions property of exception to find out that went wrong." that is what the exception says. Thank you very much for pointing that out. I could not have known that on my own.
Any real solution to this problem.? Some of us really want to know!!

darom

Try the following code:-

Public Shared Function GetTypes(ByVal objAssembly As System.Reflection.Assembly) As Type()

Dim objTypes() As Type = Nothing

Try

'In a medium trust environment this call will fail.

'We then just need to get the types that were loaded.

'Thankfully these can be got from the exception.

objTypes = objAssembly.GetTypes()

Catch ex As Reflection.ReflectionTypeLoadException

objTypes = ex.Types

#If DEBUG Then

For Each ex1 As Exception In ex.LoaderExceptions

System.Diagnostics.Debug.WriteLine("--LoaderExceptions: " + ex1.Message)

Next

#End If

End Try

Return objTypes

End Function

Richard Shears

Hi,

I have excatly the same problem.

My LoaderException is Null.

Did'you find any solution ?

Thanks.

Leclerc
Make sure you have the correct startup project set for you solution.
Big KooKoo
where should i use this code
how to call and check any loader exceptions are there

Sandeep...
Sandeep Reddy Pinniti
where should i use this code
how to call and check any loader exceptions are there
Sandeep...
Sandeep Reddy Pinniti

You can use google to search for other answers

Custom Search

More Threads

• Executing a dll-dependent application produces a "The type 'xxx' could not be loaded."
• Check if global hotkey is registered
• Huge bug in .NET 2.0 TripleDESCryptoServiceProvider
• Install service via Installer
• breakpoint is NOT working, breakpoint will not currently be hit
• Could I pass data between threads?
• Native vs Managed Threads
• Non OLE clipboard copy and importing clip32.dll
• Handling COM events in C++ .NET
• Create Control from HWND