2010-07-02 95 views
0

当加载dll文件使用.net反射(加载的文件描述是:Microsoft C运行时库),我得到运行时错误(R6034) 当加载dll,不使用C运行时库它将被成功加载, 可以我加载dll,使用C运行时使用.net反射,如果没有,那么如何捕获这个异常? 下面找到我的代码:.NET反射加载DLL文件给运行时错误(R6034)!

class ReverseDLL 
{ 
    private Assembly assembly; 
    private AssemblyDescriptionAttribute desc; 
    private AssemblyTitleAttribute title; 
    private AssemblyCopyrightAttribute copyRight; 

    public string getCopyright(string path) 
    { 
     try 
     { 
      assembly = System.Reflection.Assembly.LoadFrom(path); 
     } 
     catch { Console.WriteLine("(private message)Class ReverseDll : Couldn't load dll"); } 
     try 
     { 
      string verInfo = assembly.GetName().Version.ToString(); 
      desc = (AssemblyDescriptionAttribute) 
      AssemblyDescriptionAttribute.GetCustomAttribute(
      assembly, typeof(AssemblyDescriptionAttribute)); 
      title = (AssemblyTitleAttribute) 
      AssemblyTitleAttribute.GetCustomAttribute(
      assembly, typeof(AssemblyTitleAttribute)); 
      copyRight = (AssemblyCopyrightAttribute)AssemblyCopyrightAttribute.GetCustomAttribute(assembly, typeof(AssemblyCopyrightAttribute)); 
      Console.WriteLine("Class ReverseDll , signature: " + copyRight.Copyright.ToString()); 
     } 
     catch 
     { 
      this.copyRight = new AssemblyCopyrightAttribute(""); 
      Console.WriteLine("(private message)Class ReverseDll : reflection not able to pull the needed data "); 
     } 
     return copyRight.Copyright; 
    } 
} 

回答

0

是否安装了VC_Redist x86或64位来与你用来建立你的DLL编译器?我想你忘了在你的机器上或者你的配置文件forgot the include the manifest to your DLL。这对于使用VS2005或更新版本编译的C/C++应用程序非常重要。