poshbotio / PoshBot

Powershell-based bot framework
MIT License
540 stars 108 forks source link

GetEnumeration error when starting bot instance on NanoServer #24

Closed megamorf closed 5 years ago

megamorf commented 7 years ago

Expected Behavior

Bot starts when you run $bot.start() on NanoServer.

Current Behavior

Bot start is interrupted by GetEnumerator error on NanoServer.

PS C:\> $bot.start()
Cannot find an overload for "GetEnumerator" and the argument count: "0".
At line:1 char:1
+ $bot.start()
+ ~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException

PS C:\> $bot | Start-PoshBot -Verbose -Debug
VERBOSE: [SlackBackend:LoadUsers] Adding user: U4ZLZE6E9:megamorf
VERBOSE: [SlackBackend:LoadUsers] Adding user: U4ZGBQQDR:poshbotdockertest
VERBOSE: [SlackBackend:LoadUsers] Adding user: USLACKBOT:slackbot
VERBOSE: [SlackBackend:LoadRooms] Adding channel: C5091LHFZ:general
VERBOSE: [SlackBackend:LoadRooms] Adding channel: C4ZGB5HJ7:random
VERBOSE: [Group: AddUser] User [U4ZLZE6E9] is already in [Admin]
DEBUG: [SlackBackend:ReceiveMessage] Received
{"type":"message","channel":"C4ZGB5HJ7","user":"U4ZLZE6E9","text":"!help","ts":"1492244031.722558","source_team":"T4ZGB5E9Z","team":"T4ZGB5E9Z"}

Confirm
Continue with this operation?
[Y] Yes  [A] Yes to All  [H] Halt Command  [S] Suspend  [?] Help (default is "Y"): a
Cannot find an overload for "GetEnumerator" and the argument count: "0".
At line:1 char:1
+ $bot | start-poshbot -Verbose -Debug
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException

PS C:\> Resolve-Error

writeErrorStream      : True
PSMessageDetails      :
Exception             : Microsoft.PowerShell.Commands.WriteErrorException: Cannot find an overload for "GetEnumerator" and the argument count: "0".
TargetObject          :
CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException
ErrorDetails          :
InvocationInfo        : System.Management.Automation.InvocationInfo
ScriptStackTrace      : at Start, C:\Program Files\WindowsPowerShell\Modules\poshbot\0.2.1\PoshBot.psm1: line 2522
                        at <ScriptBlock>, <No file>: line 1
PipelineIterationInfo : {}

MyCommand             :
BoundParameters       : {}
UnboundArguments      : {}
ScriptLineNumber      : 1
OffsetInLine          : 1
HistoryId             : 17
ScriptName            :
Line                  : $bot.start()
PositionMessage       : At line:1 char:1
                        + $bot.start()
                        + ~~~~~~~~~~~~
PSScriptRoot          :
PSCommandPath         :
InvocationName        :
PipelineLength        : 0
PipelinePosition      : 0
ExpectingInput        : False
CommandOrigin         : Internal
DisplayScriptPosition :

00000000000000000000000000000000000000000000000000000000000000000000000000000000

Message        : Cannot find an overload for "GetEnumerator" and the argument count: "0".
Data           : {}
InnerException :
StackTrace     :
HelpLink       :
Source         :
HResult        : -2146233088

Possible Solution

None.

Steps to Reproduce (for bugs)

  1. Install-Module -Name PoshBot -Repository PSGallery
  2. Generate new config with New-PoshBotConfiguration and save to file with Save-PoshBotConfiguration:

    @{
    AlternateCommandPrefixes = @('poshbot')
    PluginRepository = @('PSGallery')
    LogDirectory = 'C:\Users\ContainerAdministrator\.poshbot'
    Name = 'poshbotdockertest'
    BotAdmins = @('megamorf')
    ConfigurationDirectory = 'C:\Users\ContainerAdministrator\.poshbot'
    BackendConfiguration = @{
    Token = 'xoxb-169555840467-vh3I4ex91hIZVBiGqy7Xpxxx'
    Name = 'SlackBackend'
    }
    LogLevel = 'Verbose'
    PluginDirectory = 'C:\Users\ContainerAdministrator\.poshbot'
    MuteUnknownCommand = $False
    ModuleManifestsToLoad = @()
    AlternateCommandPrefixSeperators = @(':',',',';')
    SendCommandResponseToPrivate = @()
    PluginConfiguration = @{
    
    }
    CommandPrefix = '!'
    }
  3. Follow steps from docs:
    $pbc = Get-PoshBotConfiguration -Path .\poshbot.psd1
    $backend = New-PoshBotSlackBackend -Configuration $pbc.BackendConfiguration
    $bot = New-PoshBotInstance -Configuration $pbc -Backend $backend
    $bot.start()
  4. Get error

Context

The issue prevents me from testing PoshBot on NanoServer.

Your Environment

PS C:\> $PSVersionTable

Name                           Value
----                           -----
WSManStackVersion              3.0
PSVersion                      5.1.14393.1000
CLRVersion
PSEdition                      Core
BuildVersion                   10.0.14393.1000
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
SerializationVersion           1.1.0.1
PSRemotingProtocolVersion      2.3

PS C:\> Get-Module

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Script     1.0.2      Configuration                       {Add-MetadataConverter, ConsoleColor, ConvertFrom-Metadata, ConvertTo-Me...
Manifest   7.0.1      Json.Net
Manifest   3.1.0.0    Microsoft.PowerShell.Management     {Add-Content, Clear-Content, Clear-Item, Clear-ItemProperty...}
Manifest   3.0.0.0    Microsoft.PowerShell.Security       {ConvertFrom-SecureString, ConvertTo-SecureString, Get-Acl, Get-Authenti...
Manifest   3.1.0.0    Microsoft.PowerShell.Utility        {Add-Member, Add-Type, Clear-Variable, Compare-Object...}
Binary     1.0.0.1    PackageManagement                   {Find-Package, Find-PackageProvider, Get-Package, Get-PackageProvider...}
Script     0.2.1      poshbot                             {Get-PoshBot, Get-PoshBotConfiguration, New-PoshBotCardResponse, New-Pos...
Script     0.0        PoshBotAttribute
Script     1.0.0.1    PowerShellGet                       {Find-Command, Find-DscResource, Find-Module, Find-RoleCapability...}
Script     0.0.17     PSSlack                             {Find-SlackMessage, Get-PSSlackConfig, Get-SlackChannel, Get-SlackGroup...}
adammillerio commented 7 years ago

In trying to fix my issue (#26) I had a similar error arise when trying to run PoshBot using the latest PowerShell available from their GitHub:

WARNING: You are using PSSlack in with .NET Core.  Several features will not work:
 Set-PSSlackConfig cannot serialize tokens or URIs
 [System.Drawing.Color]::SOmeColor shortcut is not available
Cannot find an overload for "GetEnumerator" and the argument count: "0".
At line:1 char:1
+ & 'C:\Users\aemiller\Scripts\Bot\Bot.ps1'
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException

Looks like at least in my case, it is because that version of PowerShell is using .NET Core, which is more stripped down than what ships with full Windows. This is likely a similar issue with yours, as Nano Server probably ships with .NET Core.

megamorf commented 7 years ago

Yeah, the missing color class error of PSSlack broke my docker build on NanoServer so I had to fix it by changing the ErrorActionPreference prior to importing PoshBot:

# configure shell default parameters
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]

# Install PoshBot and create new PoshBot configuration and store it for later use
RUN Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force; \
    Install-Module -Name PoshBot -RequiredVersion $env:PoshBotVersion -Repository PSGallery -Force; \
    $ErrorActionPreference = 'Ignore'; \
    Import-Module -Name PoshBot -ErrorAction SilentlyContinue; \
    $ErrorActionPreference = 'Stop'; \
    New-PoshBotConfiguration | Save-PoshBotConfiguration
devblackops commented 7 years ago

@megamorf I'm hacking away at some of these bugs in Nano. I squash one, another appears ☹️

It may be a bit before this is fully working on Nano. Have you tried it on Windows 2012R2\2016 or Windows 10? Does it work for you?

devblackops commented 7 years ago

Aside from the PSSlack issue, I think the Nano Server issues are fixed. I'll try to do some more testing tonight and commit my changes.

devblackops commented 7 years ago

@megamorf I have published a Docker image of v0.2.2 here. It's also been published to PSGallery.

Can you try running the following?

docker run -it -e SLACK_TOKEN="<YOUR-SLACK-TOKEN>" -e BOT_ADMINS="<YOUR-HANDLE>" -v C:/temp/poshbot_docker_volume/:c:/poshbot_data poshbotio/poshbot-nano-slack:0.2.2

Note the use of the Docker volume. PoshBot will store all configuration in this directory so subsequent invocations should read in the configuration.

megamorf commented 7 years ago

@devblackops hey, thanks for that :+1: . I'll check it out some time this week.

RamblingCookieMonster commented 7 years ago

You could suppress the PSSlack warning when importing if desired. I think I'll kill that warning shortly, just need to make sure to document that bit in the readme/about.

Cheers!

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.