本文整理匯總了VB.NET中System.AppDomain.AssemblyResolve事件的典型用法代碼示例。如果您正苦於以下問題:VB.NET AppDomain.AssemblyResolve事件的具體用法?VB.NET AppDomain.AssemblyResolve怎麽用?VB.NET AppDomain.AssemblyResolve使用的例子?那麽, 這裏精選的事件代碼示例或許可以為您提供幫助。您也可以進一步了解該事件所在類System.AppDomain
的用法示例。
在下文中一共展示了AppDomain.AssemblyResolve事件的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。
示例1: MyType
Public Class MyType
Public Sub New()
Console.WriteLine()
Console.WriteLine("MyType instantiated!")
End Sub
End Class
Class Test
Public Shared Sub Main()
Dim currentDomain As AppDomain = AppDomain.CurrentDomain
' This call will fail to create an instance of MyType since the
' assembly resolver is not set
InstantiateMyTypeFail(currentDomain)
AddHandler currentDomain.AssemblyResolve, AddressOf MyResolveEventHandler
' This call will succeed in creating an instance of MyType since the
' assembly resolver is now set.
InstantiateMyTypeFail(currentDomain)
' This call will succeed in creating an instance of MyType since the
' assembly name is valid.
InstantiateMyTypeSucceed(currentDomain)
End Sub
Private Shared Sub InstantiateMyTypeFail(domain As AppDomain)
' Calling InstantiateMyType will always fail since the assembly info
' given to CreateInstance is invalid.
Try
' You must supply a valid fully qualified assembly name here.
domain.CreateInstance("Assembly text name, Version, Culture, PublicKeyToken", "MyType")
Catch e As Exception
Console.WriteLine()
Console.WriteLine(e.Message)
End Try
End Sub
Private Shared Sub InstantiateMyTypeSucceed(domain As AppDomain)
Try
Dim asmname As String = Assembly.GetCallingAssembly().FullName
domain.CreateInstance(asmname, "MyType")
Catch e As Exception
Console.WriteLine()
Console.WriteLine(e.Message)
End Try
End Sub
Private Shared Function MyResolveEventHandler(sender As Object, args As ResolveEventArgs) As Assembly
Console.WriteLine("Resolving...")
Return GetType(MyType).Assembly
End Function 'MyResolveEventHandler
End Class