PC Review


Reply
Thread Tools Rate Thread

Assembly.Gettype freezes

 
 
Anthony C
Guest
Posts: n/a
 
      23rd Nov 2004
On certain assemblies, when I do a LoadFrom to get a reference, and
then call GetTypes to get a list of types, the application freezes.

If, however, I put a try/catch block around the code, it does NOT
freeze, but NO EXCEPTION is thrown.

This is for my plugin structure. I have 30 dlls to search. The
first 10 are ok. #1, which is not much different than the other 10,
fails. Ok.. so I skip that one manually.. 11-16 work, 17 fails.

I figured I would inspect the failing ones and see why. There is no
common bond.

Also, one more thing.. this seems to work successfully, for all DLLs
on most machines, but one a couple of clients reporting a problem.

Anyone have any advice?

Here is the code. FINDPLUGINS is the routine I call....

Public Shared Function FindPlugins(ByVal szPath As String, _
Optional ByVal
objHostInitialize As ITPPHost = Nothing) As AvailablePlugin()
Dim objArrayPlugins As ArrayList = New ArrayList
Dim szDLLs() As String, nIndex As Integer
Dim objDLL As [Assembly]
Dim szInterface As String = GetType(ITPPPlugIn).ToString()

'Go through all DLLs in the directory, attempting to load them
szDLLs = Directory.GetFileSystemEntries(szPath, "*.dll")
For nIndex = 0 To szDLLs.Length - 1
Try
Dim szFileName As String =
System.IO.Path.GetFileName(szDLLs(nIndex))
If Not szFileName.StartsWith("ActiveReports") Then
objDLL = [Assembly].LoadFrom(szDLLs(nIndex))
ExamineAssembly(objDLL, szInterface,
objArrayPlugins, objHostInitialize)
End If
Catch e As Exception
'Error loading DLL, we don't need to do anything
special
End Try
Next

'Return all objArrayPlugins found
Dim Results(objArrayPlugins.Count - 1) As AvailablePlugin

If objArrayPlugins.Count <> 0 Then
objArrayPlugins.CopyTo(Results)
Return Results
Else
Return Nothing
End If
End Function

Private Shared Sub ExamineAssembly(ByVal objDLL As [Assembly], _
ByVal szInterface As String, _
ByVal objArrayPlugins As
ArrayList, _
ByVal objHost As ITPPHost)
Dim objType As Type
Dim objInterface As Type
Dim objAP As AvailablePlugin

Try
'Loop through each type in the DLL
For Each objType In objDLL.GetTypes
'Only look at public types
If objType.IsPublic = True Then
'Ignore abstract classes

If Not ((objType.Attributes And
TypeAttributes.Abstract) = TypeAttributes.Abstract) Then

'See if this type implements our interface
objInterface =
objType.GetInterface(szInterface, True)

If Not (objInterface Is Nothing) Then
'It does
objAP = New AvailablePlugin
objAP.AssemblyPath = objDLL.Location
objAP.ClassName = objType.FullName

'if the host exists, then instantiate

If Not objHost Is Nothing Then
objAP.Plugin = CreateInstance(objAP, objHost)
objArrayPlugins.Add(objAP)
End If

End If
End If
Next
Catch ex As Exception
Throw ex
End Try
End Sub
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with Assembly.GetType nomad Microsoft C# .NET 7 15th Jan 2011 11:48 PM
Question on Assembly.GetType() =?Utf-8?B?RmxhY2s=?= Microsoft C# .NET 0 1st Nov 2006 10:14 PM
Load Assembly Type.GetType("Class,Assembly") Mohamed Zaki Microsoft Dot NET Framework 4 7th Jan 2006 07:32 PM
Assembly.GetCallingAssembly().GetType().Namespace Kelmen Wong Microsoft Dot NET 3 26th Oct 2004 10:51 AM
GetType information from more than one assembly =?Utf-8?B?RFJhY2hl?= Microsoft Dot NET Framework 0 16th Jul 2004 10:57 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:10 PM.