Powershell中的反射装配错误

问题描述 投票:1回答:1

我有一些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
}

但是,当我在服务器上运行它时,会出现两种类型的错误;

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个回答
0
投票

将具有相同标识的多个DLL加载到同一AppDomain中将为您带来第一个例外。

请参阅我的解决方法https://stackoverflow.com/a/62379741/920618

© www.soinside.com 2019 - 2024. All rights reserved.