VMware Cloud Community
stitze
Contributor
Contributor

Bug in PowerCLI 6.5 R1: Could not load file or assembly log4net

Description

I don't know where to report PowerCLI bugs ... btw Get-ErrorReport won't work for this bug.

There is a problem with PowerCLI 6.5 R1. When starting the x64 PowerCLI all PowerCLI modules cannot be loaded because this error: "Could not load file or assembly ‘log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=692fbea5521e1304’ or one of its dependencies. The system cannot find the file specified." The x86 PowerCLI starts without any problems.

Cause

We've analyzed the problem. The problem is caused by a log4net assembly in the GAC (Global Assembly Cache).

PowerCLI ships a log4net assembly in the "Modules\VMware.VimAutomation.Sdk" folder. The log4net assembly is explicitly loaded by the PowerShell because it is in the RequiredAssemblies list of the VMware.VimAutomation.Sdk.psd1 module manifest (see VMware.VimAutomation.Sdk.psd1).

The already installed log4net assembly in the GAC and the log4net assembly shiped by PowerCli:

  • both have the same Version: 1.2.10.0
  • both have the same Culture: neutral
  • both have the same PublicKeyToken: 692fbea5521e1304
  • but differ in the processorArchitecture
    • log4net in GAC: x86
    • log4net in PowerCLI: MSIL

The PowerShell seems to raise an error when:

  • it should load an assembly because it is in the RequiredAssemblies list
  • there is an assembly with the same (strong?) name in the GAC
  • the processorArchitecture of the assembly in the GAC does not match the architecture of the PowerShell (x64 for PowerShell x64/x86 for PowerShell x86) and is not MSIL

Regular "Any CPU" .NET applications behave differently. Assemblies in the GAC with a different processorArchitecture are ignored and not loaded.

BTW: Removing the assembly from the GAC isn't an option because this will break the software that installes log4net in the GAC: SAP Crystal Reports runtime engine for .NET Framework (32-bit), Version 13.0.8.1216

Steps to Reproduce

We can repoduce this problem:

  • Create an assembly MyLibrary.dll
  • Build the with AnyCPU and x86
  • Sign both assemblies
  • Install the x86 Assembly in the GAC
  • Create a PowerShell module MyModule
  • Add MyLibrary.dll to the RequiredAssemblies list of the module
  • Open x64 PowerShell
  • Import-Module MyModule fails with this error: "Could not load file or assembly ‘MyLibrary, Version=1.0.0.0, Culture=neutral, ...’ or one of its dependencies. The system cannot find the file specified."

see also comment of Waytraveler: https://blogs.vmware.com/PowerCLI/2016/11/new-release-powercli-6-5-r1.html

Temporary Workarounds

  1. Use PowerCLI x86
  2. Remote log4net from the RequiredAssemblies list of the VMware.VimAutomation.Sdk
    1. You may need to sign the module with you own code signing certificate
Tags (2)
15 Replies
stitze
Contributor
Contributor

The problem only occurs when PowerShell 5.0/5.1 is installed on the system. The problem does not occur when PowerShell 4.0 is used.

Reply
0 Kudos
LucD
Leadership
Leadership

You can create a SR for PowerCLI


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
erpadmin
Contributor
Contributor

Any resolution to this?  Have the same issue on Windows 10

Reply
0 Kudos
nnedev
VMware Employee
VMware Employee

stitze‌,

Can you please send the log4net.dll (SAP Crystal Reports) that is causing the problem? I'm unable to reproduce using locally built log4net.

Thanks,

Nedko

Regards, Nedko Nedev PowerCLI Development Team
Reply
0 Kudos
stitze
Contributor
Contributor

Sorry for the late anwser.

The assembly is attached to this post. It is installed in the c:\windows\assembly\gac_32 directory (the old GAC location).

DeclanGowran
Contributor
Contributor

Same issue when trying to load from script

Loading Modules

True

          Welcome to VMware PowerCLI!

Log in to a vCenter Server or ESX host: Connect-VIServer

To find out what commands are available, type: Get-VICommand

To show searchable help for all PowerCLI commands: Get-PowerCLIHelp

Once you've connected, display all virtual machines: Get-VM

If you need more help, visit the PowerCLI community: Get-PowerCLICommunity

       Copyright (C) VMware, Inc. All rights reserved.

ERROR MSG:Unable to find type [VMware.VimAutomation.Sdk.Util10.ProductInfo].

At C:\Program Files (x86)\VMware\Infrastructure\PowerCLI\Scripts\Initialize-Pow

erCLIEnvironment.ps1:71 char:1

+ $powerCliFriendlyVersion = [VMware.VimAutomation.Sdk.Util10.ProductIn ...

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo : InvalidOperation: (VMware.VimAutom...l10.Product

   Info:TypeName) [], RuntimeException

    + FullyQualifiedErrorId : TypeNotFound

Set-PowerCLIConfiguration

Reply
0 Kudos
TacomaDan
Contributor
Contributor

Same issue on one of my machines when loading PowerCLI from the PowerShell Gallery...I can install the modules, but when I go to import them [Import-Module VMware.PowerCLI] it throws the log4net error. 

I had no problem with this on another machine, but it has a lot less other software installed on it...if I had to guess, I'd say that Crystal Reports on the first machine may have the conflicting version (x86 vs 64) that is causing my problems, but that is purely a guess.

BTW, very pumped that PowerCLI is now available in the Gallery...

Reply
0 Kudos
richardtracy79
Contributor
Contributor

I found I had the same issue importing PowerCLI 6.5.2 on a disconnected network. However after going through some rabbit holes, copying the file (from a connected computer)Microsoft.PackageManagement.NuGetProvider.dll to C:\Program Files\PackageManagement\ProviderAssemblies\nuget\2.8.5.208\ fixed the issue. I wrote about it here: Powershell on Crack: Installing PowerCLI on a disconnected network

I even wrote an installer for PowerCLI 6.5.2

Reply
0 Kudos
JeremyLCrabtree
Contributor
Contributor

This is still broken in 6.5.3

Reply
0 Kudos
richardtracy79
Contributor
Contributor

Is it an issue with log4net assembly still?

Reply
0 Kudos
karl-heinz_hild
Contributor
Contributor

I dont know if this is the recommended solution, but for me it helped:

Create a folder

c:\Windows\assembly\GAC_64\log4net\1.2.10.0__692fbea5521e1304\

copy log4net.dll from

c:\Program Files\WindowsPowerShell\Modules\VMware.VimAutomation.Sdk\1.0.0.5334677\

(or where ever you installed PowerCLI) into it.

After doing this,

get-module -list "VMware*" | import-module

executed successfully.

imompero
Enthusiast
Enthusiast

Karl, Thank you! that worked perfectly

Reply
0 Kudos
LucD
Leadership
Leadership

Did anyone try this with PowerCLI 10?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
SleeW
Contributor
Contributor

I have tried on Windows 10, and succeeded.

I downloaded log4net that stitzeposted last February, created directory C:\Windows\assembly\GAC_64\log4net\1.2.10.0__692fbea5521e1304\ and copied file to that directory.

After that Windows PowerShell (x64) Import-Module VMware.PowerCLI worked.

Prior to this I could only load VMware.PowerCLI using Windows PowerShell (x86).

PowerCLI version is 11.0.0

Thanks everyone!

Reply
0 Kudos
FMCUSystemAdmin
Contributor
Contributor

I am on Windows 7 with PowerShell 5.1 installed. My resolution was changing "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noe -c " within the PowerCLI shortcut's "Target" to "C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe -executionpolicy bypass -noe -c ".

It appears to be an issue with 64 bit PowerShell which lives in "C:\Windows\System32\WindowsPowerShell\v1.0". 32 bit PowerShell lives in "C:\Windows\SysWOW64\WindowsPowerShell\v1.0" and seems to work without issue.

Reply
0 Kudos