Reflection.AssemblyName()。Version的意外结果 [英] Unexpected result of Reflection.AssemblyName().Version

查看:74
本文介绍了Reflection.AssemblyName()。Version的意外结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近,我不得不检查某些DLL的汇编版本,将其命名为 AAA.BBB.dll ,我决定使用一个简单的Powershell命令来获取它,即:

Recently, I had to check assembly version of certain DLL, let call it AAA.BBB.dll and I decided to use a simple Powershell command to get it, namely:

[Reflection.AssemblyName]::GetAssemblyName('AAA.BB.dll').Version

我意识到此命令不会显示我想要的版本。大多数情况下,它显示一个固定版本,该版本与当前目录中dll的版本不匹配。甚至向GetAssemblyName方法提供了一些无效的输入(例如AAA.BB.dll123)也显示了相同的版本(而不是引发异常)。我尝试使用绝对路径,但没有帮助。我还检查了AAA.BB.dll是否不在GAC中。

I realized that this command does not display the version that I want. Most of the time it displays one fixed version which does not match the version of the dll in the current directory. Even providing an some invalid inputs to GetAssemblyName method (e.g. 'AAA.BB.dll123') showed that same version (instead of throwing an exception). I tried using absolute paths and it did not help. I've also checked that AAA.BB.dll was not in GAC.

我可以通过在F#交互式中调用类比代码或通过打开AAA获得正确的汇编版本。 .NET反射器中的.BB.dll。

I could get a correct assembly version by calling analogical code in F# interactive or by opening that AAA.BB.dll in .NET reflector.

我已经检查了 AssemblyName.GetAssemblyName ,但我找不到该行为的任何解释。我想知道:

I've checked documentation for AssemblyName.GetAssemblyName and I couldn't find any explanation for that behavior. I'm wondering:


  • 为什么该命令不断显示DLL的一个版本?

  • Why is that command constantly displaying one version of a DLL?

如何解释Powershell和F#交互中的类比代码之间的差异?它与程序集解析机制,.NET Framework配置或.NET Framework版本有关吗?

How differences between analogical code in Powershell and F# interactive can be explained? Is it something with assembly resolution mechanism or .NET Framework configuration or .NET Framework version?

为什么用无效参数(即'AAA.BB.')调用GetAssemblyName。 dll123')不会引发异常吗?

Why calling GetAssemblyName with an invalid argument (namely 'AAA.BB.dll123') does not throw the exception?

我要粘贴几个已执行命令的输出在 M:目录中,其中不包含dll。

I'm pasting the output for a couple of commands which were executed in M: directory which contains no dlls.

PS M:\> [Reflection.AssemblyName]::GetAssemblyName('AAA.BB.dll').Version

Major  Minor  Build  Revision
-----  -----  -----  --------
1      0      600    8


PS M:\> [Reflection.AssemblyName]::GetAssemblyName('aAAA.BB.dll').Version
Exception calling "GetAssemblyName" with "1" argument(s): "Could not load file or assembly 'M:\aAAA.BB.dll' or one o
f its dependencies. The system cannot find the file specified."
At line:1 char:43
+ [Reflection.AssemblyName]::GetAssemblyName <<<< ('aAAA.BB.dll').Version
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

PS M:\> [Reflection.AssemblyName]::GetAssemblyName('AAA.BB.dll123').Version

Major  Minor  Build  Revision
-----  -----  -----  --------
1      0      600    8


PS M:\> [Reflection.AssemblyName]::GetAssemblyName("AAA.BB.dll123").Version

Major  Minor  Build  Revision
-----  -----  -----  --------
1      0      600    8


PS M:\> [Reflection.AssemblyName]::GetAssemblyName("AAA.BB123").Version
Exception calling "GetAssemblyName" with "1" argument(s): "Could not load file or assembly 'M:\AAA.BB123' or one of
its dependencies. The system cannot find the file specified."
At line:1 char:43
+ [Reflection.AssemblyName]::GetAssemblyName <<<< ("AAA.BB123").Version
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

PS M:\> [Reflection.AssemblyName]::GetAssemblyName("AAA.BB.123").Version

Major  Minor  Build  Revision
-----  -----  -----  --------
1      0      600    8

我应该注意AAA程序集版本为1.0.600.8的.BB.dll在该计算机上的其他目录中。

I should note that AAA.BB.dll with assembly version 1.0.600.8 is in some other directory on that computer.

推荐答案

我没有访问权限到问题机器,但我认为配置错误 DEVPATH 可能是罪魁祸首。某些工具(例如反编译器)会修改DEVPATH,以使用户能够调试反编译的程序集。

I don't have access to machine in question anymore, but I think that misconfigured DEVPATH might have been the culprit. Some tools, such as decompilers, modify DEVPATH to enable user to debug decompiled assemblies.

如果此博客条目为true,如果设置了DEVPATH,则会禁用所有常规程序集查找功能,并且DEVPATH中的程序集将优先于所有其他程序集。在这种情况下,Powershell会显示AAA.BB.dll的固定版本这一事实不足为奇。如果F#在另一个.NET运行时版本下运行,则该更改可能不会受到影响。

If this blog entry is true, if DEVPATH is set, all normal assembly lookup features are disabled and assemblies in DEVPATH take precedence over all other assemblies. In such case, the fact that Powershell displayed a fixed version of AAA.BB.dll should be no surprise. If F# run under another version .NET runtime, it could be not affected by that change.

这篇关于Reflection.AssemblyName()。Version的意外结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆