我有一个Powershell CmdLet,它在32位模式下运行时运行,在64位模式下运行失败.问题是原因是什么以及如何解决.
Powershell CmdLet引用'OutlookHelper.Common.dll'.最新版本是2.0.0.0 CmdLet还使用日志记录和引用'Logging.dll'.
Logging.dll也引用'OutlookHelper.Common.dll',仅针对版本1.0.0.0进行编译.
在Powershell的应用程序配置文件中使用程序集绑定重定向:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0.30319"/>
<supportedRuntime version="v2.0.50727"/>
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="OutlookHelper.Common" publicKeyToken="5e4553dc0df45306"/>
<bindingRedirect oldVersion="1.0.0.0" newVersion="2.0.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
Run Code Online (Sandbox Code Playgroud)
在64位计算机上运行时,使用"Windows Powershell(x86)"可以正常运行.程序集管理器找到程序集绑定重定向:
The operation was successful.
Bind result: hr = 0x0. The operation completed successfully.
Assembly manager loaded from: C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable C:\Windows\syswow64\Windowspowershell\v1.0\powershell.exe
--- A detailed error log follows.
=== Pre-bind state information ===
LOG: User = MYDOMAIN\testuser
LOG: DisplayName = …Run Code Online (Sandbox Code Playgroud)