【问题标题】:Reflection Assembly Errors in PowershellPowershell 中的反射装配错误
【发布时间】:2018-01-18 14:45:28
【问题描述】:

我有一些 Powershell 代码,可以获取在 IIS 服务器上运行的应用程序并找到它们正在运行的 .NET 版本。

$Apps = Get-WebApplication
foreach($App in $Apps) {
    $binLocation = "$($App.physicalPath)\bin"

    # get all dlls in bin folder
    $dllFolder = Get-Item -Path $binLocation
    $dlls = $dllFolder.GetFiles("*.dll")

    # analyze dll .net version
    $set = New-Object System.Collections.Generic.HashSet[String]
    $dlls | ForEach-Object {
        $set.Add([Reflection.Assembly]::ReflectionOnlyLoadFrom("$binLocation\$($_.Name)").ImageRuntimeVersion) | Out-Null
    }

    # print all dll .NET version
    $App
        $set
}

但是,当我在我的服务器上运行它时,我得到了 2 种类型的错误;

Exception calling "ReflectionOnlyLoadFrom" with "1" argument(s): "API restriction: The
assembly 'file:///D:\inetpub\wwwroot\OABS_ECRM\bin\WebGrease.dll' has already loaded from a 
different location. It cannot be loaded from a new location within the same appdomain."
At line:13 char:74
+         $set.Add([Reflection.Assembly]::ReflectionOnlyLoadFrom ("$binLocation\$($_.Name ...
+                                                                                ~~~~~~~
+ CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : FileLoadException

和,

Exception calling "ReflectionOnlyLoadFrom" with "1" argument(s): "Could not load file or 
assembly 'file:///D:\inetpub\wwwroot\Tablet\bin\epengine.dll' or one of its dependencies. 
The module was expected to contain an assembly manifest."
At line:13 char:74
+         $set.Add([Reflection.Assembly]::ReflectionOnlyLoadFrom("$binLocation\$($_.Name ...
+                                                                                ~~~~~~~
+ CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : BadImageFormatException

我似乎从脚本中获得了在每个应用程序上运行的 .NET 版本,但我想知道是什么导致了这些错误以及是否可以清除它们。我需要在 powershell 中解决这个问题。

【问题讨论】:

标签: powershell iis .net-assembly windows-server-2012-r2


【解决方案1】:

将具有相同标识的多个 DLL 加载到同一个 AppDomain 中会出现第一个异常。

在https://stackoverflow.com/a/62379741/920618 上查看我的解决方法。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-15
    相关资源
    最近更新 更多