Powershell - Assembly binding redirect NOT found in application configuration file

前端 未结 3 1382
情话喂你
情话喂你 2021-01-11 12:49

Got a problem here...

I have got a Powershell CmdLet that works when running in 32-bit mode and fails in 64-bit mode. Question is what the cause is and how it can

3条回答
  •  遥遥无期
    2021-01-11 13:48

    Not 100% related to 32/64-bit issue, however if someone is interested in working assembly redirect solution please have a look here Powershell config assembly redirect.

    You can do custom assembly redirect using PowerShell code like

    $FSharpCore = [reflection.assembly]::LoadFrom($PSScriptRoot + "\bin\LIBRARY\FSharp.Core.dll") 
    
    $OnAssemblyResolve = [System.ResolveEventHandler] {
      param($sender, $e)
    
      # from:FSharp.Core, Version=4.3.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
      # to:  FSharp.Core, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
      if ($e.Name -eq "FSharp.Core, Version=4.3.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a") { return $FSharpCore }
    
      foreach($a in [System.AppDomain]::CurrentDomain.GetAssemblies())
      {
        if ($a.FullName -eq $e.Name)
        {
          return $a
        }
      }
      return $null
    }
    
    [System.AppDomain]::CurrentDomain.add_AssemblyResolve($OnAssemblyResolve)
    

    I am first loading the correct version of FSharp.Core from somewhere as the version in the GAC is old (I guess this might be your case too)

提交回复
热议问题