本文整理汇总了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