當前位置: 首頁>>代碼示例>>VB.NET>>正文


VB.NET BadImageFormatException類代碼示例

本文整理匯總了VB.NET中System.BadImageFormatException的典型用法代碼示例。如果您正苦於以下問題:VB.NET BadImageFormatException類的具體用法?VB.NET BadImageFormatException怎麽用?VB.NET BadImageFormatException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了BadImageFormatException類的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。

示例1: DLL

' Windows DLL (non-.NET assembly)
Dim filePath As String = Environment.ExpandEnvironmentVariables("%windir%")
If Not filePath.Trim().EndsWith("\") Then filepath += "\"
filePath += "System32\Kernel32.dll"
Try
   Dim assem As Assembly = Assembly.LoadFile(filePath)
Catch e As BadImageFormatException
   Console.WriteLine("Unable to load {0}.", filePath)
   Console.WriteLine(e.Message.Substring(0, _
                     e.Message.IndexOf(".") + 1))   
End Try
' The example displays an error message like the following:
'       Unable to load C:\WINDOWS\System32\Kernel32.dll.
'       The module was expected to contain an assembly manifest.
開發者ID:VB.NET開發者,項目名稱:System,代碼行數:14,代碼來源:BadImageFormatException

示例2: exceptionList

Public Module StringLib
   Private exceptionList() As String = { "a", "an", "the", "in", "on", "of" }
   Private separators() As Char = { " "c }
   
   Public Function ToProperCase(title As String) As String
      Dim isException As Boolean = False	
      
      Dim words() As String = title.Split( separators, StringSplitOptions.RemoveEmptyEntries)
      Dim newWords(words.Length) As String
        
      For ctr As Integer = 0 To words.Length - 1
         isException = False

         For Each exception As String In exceptionList
            If words(ctr).Equals(exception) And ctr > 0 Then
               isException = True
               Exit For
            End If
         Next
         If Not isException Then
            newWords(ctr) = words(ctr).Substring(0, 1).ToUpper() + words(ctr).Substring(1)
         Else
            newWords(ctr) = words(ctr)	 
         End If	 
      Next	
      Return String.Join(" ", newWords) 			
   End Function
End Module
開發者ID:VB.NET開發者,項目名稱:System,代碼行數:28,代碼來源:BadImageFormatException

示例3: Main

' 導入命名空間
Imports System.Reflection

Module Example
   Public Sub Main()
      Dim title As String = "a tale of two cities"
      ' Load assembly containing StateInfo type.
      Dim assem As Assembly = Assembly.LoadFrom(".\StringLib.dll")
      ' Get type representing StateInfo class.
      Dim stateInfoType As Type = assem.GetType("StringLib")
      ' Get Display method.
      Dim mi As MethodInfo = stateInfoType.GetMethod("ToProperCase")
      ' Call the Display method. 
      Dim properTitle As String = CStr(mi.Invoke(Nothing, New Object() { title } ))
      Console.WriteLine(properTitle)
   End Sub
End Module
開發者ID:VB.NET開發者,項目名稱:System,代碼行數:17,代碼來源:BadImageFormatException

輸出:

Unhandled Exception: System.BadImageFormatException: 
The format of the file 'StringLib.dll' is invalid.

示例4: Example

' 導入命名空間
Imports System.IO
Imports System.Reflection

Module Example
   Public Sub Main()
      Dim args() As String = Environment.GetCommandLineArgs()
      If args.Length = 1 Then
         Console.WriteLine()
         Console.WriteLine("Syntax:   PlatformInfo <filename> ")
         Console.WriteLine()
         Exit Sub
      End If
      Console.WriteLine()
      
      ' Loop through files and display information about their platform.
      For ctr As Integer = 1 To args.Length - 1
         Dim fn As String = args(ctr)
         If Not File.Exists(fn) Then
            Console.WriteLine("File: {0}", fn)
            Console.WriteLine("The file does not exist.")
            Console.WriteLine()
         Else
            Try
               Dim an As AssemblyName = AssemblyName.GetAssemblyName(fn)
               Console.WriteLine("Assembly: {0}", an.Name)
               If an.ProcessorArchitecture = ProcessorArchitecture.MSIL Then
                  Console.WriteLine("Architecture: AnyCPU")
               Else
                  Console.WriteLine("Architecture: {0}", an.ProcessorArchitecture)
               End If
            Catch e As BadImageFormatException
               Console.WriteLine("File: {0}", fn)
               Console.WriteLine("Not a valid assembly.\n")
            End Try
            Console.WriteLine()
         End If
      Next
   End Sub
End Module
開發者ID:VB.NET開發者,項目名稱:System,代碼行數:40,代碼來源:BadImageFormatException


注:本文中的System.BadImageFormatException類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。