dataplat / dbatools

🚀 SQL Server automation and instance migrations have never been safer, faster or freer
https://dbatools.io
MIT License
2.44k stars 794 forks source link

[Bug]Import-Module in VS17 produces "Parameter Not Found" error in 1.0.26 #5939

Closed jay-butler closed 5 years ago

jay-butler commented 5 years ago

Environmental information

Name                           Value                                                                                   
----                           -----                                                                                   
PSVersion                      5.1.18362.145                                                                           
PSEdition                      Desktop                                                                                 
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                 
BuildVersion                   10.0.18362.145                                                                          
CLRVersion                     4.0.30319.42000                                                                         
WSManStackVersion              3.0                                                                                     
PSRemotingProtocolVersion      2.3                                                                                     
SerializationVersion           1.1.0.1                                                                                 

dbatools Module version:

Name    : dbatools
Path    : C:\Program Files\WindowsPowerShell\Modules\dbatools\1.0.26\dbatools.psd1
Version : 1.0.26
Name    : dbatools
Path    : C:\Program Files\WindowsPowerShell\Modules\dbatools\1.0.20\dbatools.psd1
Version : 1.0.20
# Replace with output of Get-Culture

SQL Server:

Microsoft SQL Server 2014 (SP3-CU2) (KB4482960) - 12.0.6214.1 (X64)   Feb  2 2019 01:10:18   Copyright (c) Microsoft Corporation  Enterprise Edition: Core-based Licensing (64-bit) on Windows NT 6.3 <X64> (Build 9600: ) 
us_english

Report

Host used

Errors Received


writeErrorStream      : True
PSMessageDetails      : 
Exception             : System.Management.Automation.PSInvalidOperationException: The 
                        module to process 'dbatools.psm1', listed in field 
                        'ModuleToProcess/RootModule' of module manifest 'C:\Program 
                        Files\WindowsPowerShell\Modules\dbatools\1.0.26\dbatools.psd1' 
                        was not processed because no valid module was found in any 
                        module directory. ---> System.IO.FileNotFoundException: The 
                        module to process 'dbatools.psm1', listed in field 
                        'ModuleToProcess/RootModule' of module manifest 'C:\Program 
                        Files\WindowsPowerShell\Modules\dbatools\1.0.26\dbatools.psd1' 
                        was not processed because no valid module was found in any 
                        module directory.
                           --- End of inner exception stack trace ---
                           at Microsoft.PowerShell.Commands.ModuleCmdletBase.LoadModuleMa
                        nifest(String moduleManifestPath, ExternalScriptInfo 
                        manifestScriptInfo, Hashtable data, Hashtable localizedData, 
                        ManifestProcessingFlags manifestProcessingFlags, Version 
                        minimumVersion, Version maximumVersion, Version requiredVersion, 
                        Nullable`1 requiredModuleGuid, ImportModuleOptions& options, 
                        Boolean& containedErrors)
                           at Microsoft.PowerShell.Commands.ModuleCmdletBase.LoadModule(P
                        SModuleInfo parentModule, String fileName, String moduleBase, 
                        String prefix, SessionState ss, Object privateData, 
                        ImportModuleOptions& options, ManifestProcessingFlags 
                        manifestProcessingFlags, Boolean& found, Boolean& 
                        moduleFileFound)
                           at Microsoft.PowerShell.Commands.ModuleCmdletBase.LoadUsingExt
                        ensions(PSModuleInfo parentModule, String moduleName, String 
                        fileBaseName, String extension, String moduleBase, String 
                        prefix, SessionState ss, ImportModuleOptions options, 
                        ManifestProcessingFlags manifestProcessingFlags, Boolean& found, 
                        Boolean& moduleFileFound)
                           at Microsoft.PowerShell.Commands.ModuleCmdletBase.LoadUsingMul
                        tiVersionModuleBase(String moduleBase, ImportModuleOptions 
                        importModuleOptions, Boolean& found)
                           at Microsoft.PowerShell.Commands.ModuleCmdletBase.LoadUsingMod
                        ulePath(PSModuleInfo parentModule, Boolean found, IEnumerable`1 
                        modulePath, String name, SessionState ss, ImportModuleOptions 
                        options, ManifestProcessingFlags manifestProcessingFlags, 
                        PSModuleInfo& module)
                           at Microsoft.PowerShell.Commands.ImportModuleCommand.ImportMod
                        ule_LocallyViaName(ImportModuleOptions importModuleOptions, 
                        String name)
TargetObject          : dbatools
CategoryInfo          : ResourceUnavailable: (dbatools:String) [Import-Module], 
                        PSInvalidOperationException
FullyQualifiedErrorId : Modules_ModuleFileNotFound,Microsoft.PowerShell.Commands.ImportMo
                        duleCommand
ErrorDetails          : 
InvocationInfo        : System.Management.Automation.InvocationInfo
ScriptStackTrace      : at Patch-Cluster<Begin>, C:\Users\c952142\OneDrive - 
                        Exelon\TFS\xdnu001782\SQL Cluster Patch Automation\SQL Cluster 
                        Patch Automation\Patch-Cluster.ps1: line 58
                        at <ScriptBlock>, C:\Users\c952142\OneDrive - 
                        Exelon\TFS\xdnu001782\SQL Cluster Patch Automation\SQL Cluster 
                        Patch Automation\Patch-Cluster.ps1: line 450
                        at <ScriptBlock>, <No file>: line 1
PipelineIterationInfo : {0, 1}

Steps to Reproduce

Running a debug session in VS17 Community with the PowerShell Tools for Visual Studio installed, ran a script that had just completed initializing (created a log file, wrote a few messages). The Import-Module command produces a few errors resulting in the module not being loaded correctly.

Expected Behavior

Prior versions of the dbatools module had loaded without error. Worked around error by installing dbatools 1.0.20 side-byside with 1.0.26 and forced he older version load by setting the -MaximumVersion parameter. Older module loaded without error.

Actual Behavior

Version 1.0.26 produced the following error when imported in VS17. It did not produce any error when loaded from the powershell.exe command line. Version 1.0.20 did not produce any errors in VS or on the command line. Register-DbaRunspace : A parameter cannot be found that matches parameter name 'Target'.

jay-butler commented 5 years ago

I have been doing more troubleshooting with this one. I have tried uninstalling dbatools and forcing an install of various older versions. In some cases, VS works, but in most it throws the above errors on Import-Module. Next, I am going to uninstall PowerShell Tools for Visual Studio extension and re-install it.

wsmelton commented 5 years ago

I use PoshTools but not with VS 2017 so can't verify this right off. I'm on VS 2019 and it has no issues that I have seen.

Do you have the same issue if you repeat your test using PoshTools in VS Code?

potatoqualitee commented 5 years ago

@jay-butler - can you install 1.0.26 is any other way? Either via Save-Module or by downloading the nuget and extracting from dbatools.io/gallery? This generally happens when the installer failed.

jay-butler commented 5 years ago

Thanks for the quick responses. @wsmelton I actually did test this on a coworker's machine using VS17 Pro and on my box in PowerShell ISE. But, I did not have VS Code installed on my box yet. @potatoqualitee I went through uninstalling and reinstalling manually as you suggested, but the problem persisted. That got me thinking about what could have changed. I was just making some relatively minor changes in my code which included renaming some variable and functions to be a bit more descriptive. I had inadvertently caused a function naming collision between one of the functions in my code with one of the private functions in dbatools. We both had a Write-Message function. Once I renamed my function to something else, the error was gone.

Thanks again for the quick responses. I was stuck scratching my head. You guys got me thinking in a way that got me to the solution.

jay-butler commented 5 years ago

Issue is resolved. One of the private functions in the dbatools (Write-Message) had a name collision with one of the functions in my own module. I had assumed that all dbatools functions used the Verb-Dba prefix convention, but now realize that only applies to the public/exported functions. I changed the naming convention in my own module to prevent further collisions.

potatoqualitee commented 5 years ago

excellent news, thanks for the update ⭐️