当前位置: 首页>>代码示例>>C#>>正文


C# BadImageFormatException类代码示例

本文整理汇总了C#中System.BadImageFormatException的典型用法代码示例。如果您正苦于以下问题:C# BadImageFormatException类的具体用法?C# BadImageFormatException怎么用?C# BadImageFormatException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


BadImageFormatException类属于System命名空间,在下文中一共展示了BadImageFormatException类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: if

// Windows DLL (non-.NET assembly)
string filePath = Environment.ExpandEnvironmentVariables("%windir%");
if (! filePath.Trim().EndsWith(@"\"))
   filePath += @"\";
filePath += @"System32\Kernel32.dll";

try {
   Assembly assem = Assembly.LoadFile(filePath);
}
catch (BadImageFormatException e) {
   Console.WriteLine("Unable to load {0}.", filePath);
   Console.WriteLine(e.Message.Substring(0, 
                     e.Message.IndexOf(".") + 1));   
}
// 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:.NET开发者,项目名称:System,代码行数:17,代码来源:BadImageFormatException

示例2: ToProperCase

//引入命名空间
using System;

public class StringLib
{
   private string[] exceptionList = { "a", "an", "the", "in", "on", "of" };
   private char[] separators = { ' ' };
   
   public string ToProperCase(string title)
   {
      bool isException = false;	
      
      string[] words = title.Split( separators, StringSplitOptions.RemoveEmptyEntries);
      string[] newWords = new string[words.Length];
        
      for (int ctr = 0; ctr <= words.Length - 1; ctr++)
      {
         isException = false;

         foreach (string exception in exceptionList)
         {
            if (words[ctr].Equals(exception) && ctr > 0)
            {
               isException = true;
               break;
            }
         }
         
         if (! isException)
            newWords[ctr] = words[ctr].Substring(0, 1).ToUpper() + words[ctr].Substring(1);
         else
            newWords[ctr] = words[ctr];	 
      }	
      return String.Join(" ", newWords); 			
   }
}
开发者ID:.NET开发者,项目名称:System,代码行数:36,代码来源:BadImageFormatException

输出:

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

示例3: Main

//引入命名空间
using System;
using System.Reflection;

public class Example
{
   public static void Main()
   {
      string title = "a tale of two cities";
//      object[] args = { title}
      // Load assembly containing StateInfo type.
      Assembly assem = Assembly.LoadFrom(@".\StringLib.dll");
      // Get type representing StateInfo class.
      Type stateInfoType = assem.GetType("StringLib");
      // Get Display method.
      MethodInfo mi = stateInfoType.GetMethod("ToProperCase");
      // Call the Display method. 
      string properTitle = (string) mi.Invoke(null, new object[] { title } );
      Console.WriteLine(properTitle);
   }
}
开发者ID:.NET开发者,项目名称:System,代码行数:21,代码来源:BadImageFormatException

示例4: Main

//引入命名空间
using System;
using System.IO;
using System.Reflection;

public class Example
{
   public static void Main()
   {
      String[] args = Environment.GetCommandLineArgs();
      if (args.Length == 1) {
         Console.WriteLine("\nSyntax:   PlatformInfo <filename>\n");
         return;
      }
      Console.WriteLine();

      // Loop through files and display information about their platform.
      for (int ctr = 1; ctr < args.Length; ctr++) {
         string fn = args[ctr];
         if (! File.Exists(fn)) {
            Console.WriteLine("File: {0}", fn);
            Console.WriteLine("The file does not exist.\n");
         }
         else {
            try {
               AssemblyName an = AssemblyName.GetAssemblyName(fn);
               Console.WriteLine("Assembly: {0}", an.Name);
               if (an.ProcessorArchitecture == ProcessorArchitecture.MSIL)
                  Console.WriteLine("Architecture: AnyCPU");
               else
                  Console.WriteLine("Architecture: {0}", an.ProcessorArchitecture);

               Console.WriteLine();
            }
            catch (BadImageFormatException) {
               Console.WriteLine("File: {0}", fn);
               Console.WriteLine("Not a valid assembly.\n");
            }
         }
      }
   }
}
开发者ID:.NET开发者,项目名称:System,代码行数:42,代码来源:BadImageFormatException


注:本文中的System.BadImageFormatException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。