2011-11-04 26 views
0

我有一些程序集存储在数据库的Oracle BLOB字段中。我正在加载组件,创建类的实例等全部成功。但是,我想访问加载的程序集的AssemblyFileVersion,但似乎无法找到如何去做。如何从已从字节加载的程序集中获取FileVersion?

我已经尝试了一些东西,包括像下面的代码:

var assembly = Assembly.Load(plugInBytes); 
var version = FileVersionInfo.GetVersionInfo(assembly.Location).FileVersion; 

然而,当组件被装字节,assembly.Location是空的,并没有什么好之后发生的。

只是在正确的方向寻找一个微调。

+0

为什么当你知道位置时不从位置加载它? –

+0

@SaeedAmiri,位置在Oracle BLOB字段 –

回答

2

如果AssemblyFileVersion attribute得到了应用,你就不能使用:

var version = assembly.GetCustomAttributes(typeof(AssemblyFileVersionAttribute), 
              false); 
         .Cast<AssemblyFileVersionAttribute>() 
         .Select(attr => attr.Version) 
         .FirstOrDefault(); 
if (version != null) 
{ 
    // Got the version number... 
} 
1

你可以尝试SOMET

public bool GetVersion(string fileName) 
{ 
     Assembly asm = null; 
     try 
     { 
       asm = Assembly.LoadFrom(fileName); 
     } 
     catch (Exception err) 
     { 
       this._errMsg = err.Message; 
       return false; 
     } 
     if (asm != null) 
     { 
       this._info = new AssemblyInformation(); 
       this._info.Name = asm.GetName().Name; 
       this._info.Version = asm.GetName().Version.ToString(); 
       this._info.FullName = asm.GetName().ToString(); 
     } 
     else 
     { 
       this._errMsg = "Invalid assembly"; 
       return false; 
      } 
      return GetReferenceAssembly(asm); 
    } 
    public bool GetVersion(Assembly asm) 
    { 
     if (asm != null) 
     { 
       this._info = new AssemblyInformation(); 
       this._info.Name = asm.GetName().Name; 
      this._info.Version = asm.GetName().Version.ToString(); 
      this._info.FullName = asm.GetName().ToString(); 
     } 
     else 
      { 
      this._errMsg = "Invalid assembly"; 
      return false; 
      } 

      return GetReferenceAssembly(asm); 
    } 
0

就获得相同的字节,保存到临时文件并获得文件版本如果你需要文件版本。大会版本可能是相同的,并且更容易获得(参见Jon的回复)。

+0

@AlexeiLevnekov,出于安全原因,我无法将程序集保存到磁盘 –

相关问题