csharp System.BadImageFormatException类(方法)实例源码

下面列出了csharp System.BadImageFormatException 类(方法)源码代码实例,从而了解它的用法。

作者:.NET开发    项目:Syste   
// 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.

作者:.NET开发    项目:Syste   
//引入命名空间
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); 			
   }
}

作者:.NET开发    项目:Syste   
//引入命名空间
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);
   }
}

作者:.NET开发    项目:Syste   
//引入命名空间
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");
            }
         }
      }
   }
}


问题


面经


文章

微信
公众号

扫码关注公众号