Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ConvertTo-SplatExpression: Cannot find type for custom attribute 'EditorCommand' #42

Closed
ArtisanByteCrafter opened this issue Nov 11, 2019 · 12 comments
Assignees
Labels
Milestone

Comments

@ArtisanByteCrafter
Copy link

Working with the newest Powershell Preview extension (tested on v2019.11.0), ConvertTo-SplatExpression fails with the following error. Non-preview powershell extension works as intended.

Exception             : 
    ErrorRecord : 
        Exception             : 
            Message : Cannot find the type for custom attribute 'EditorCommand'. Make sure that the assembly that contains this type is loaded.
            HResult : -2146233087
        TargetObject          : [EditorCommand(DisplayName='Convert Command to Splat Expression')]
        CategoryInfo          : InvalidOperation: ([EditorCommand(Disp…Splat Expression')]:AttributeAst) [], ParentContainsErrorRecordException
        FullyQualifiedErrorId : CustomAttributeTypeNotFound
        InvocationInfo        : 
            ScriptLineNumber : 10
            OffsetInLine     : 5
            HistoryId        : -1
            ScriptName       : C:\Users\ntwebb\Documents\PowerShell\Modules\EditorServicesCommandSuite\0.4.0\Public\ConvertTo-SplatExpression.ps1
            Line             : [EditorCommand(DisplayName='Convert Command to Splat Expression')]
            PositionMessage  : At C:\Users\ntwebb\Documents\PowerShell\Modules\EditorServicesCommandSuite\0.4.0\Public\ConvertTo-SplatExpression.ps1:10 char:5
                               +     [EditorCommand(DisplayName='Convert Command to Splat Expression') …
                               +     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            PSScriptRoot     : C:\Users\ntwebb\Documents\PowerShell\Modules\EditorServicesCommandSuite\0.4.0\Public
            PSCommandPath    : C:\Users\ntwebb\Documents\PowerShell\Modules\EditorServicesCommandSuite\0.4.0\Public\ConvertTo-SplatExpression.ps1
            CommandOrigin    : Internal
        ScriptStackTrace      : at <ScriptBlock>, <No file>: line 1
    TargetSite  : 
        Name          : GetAttribute
        DeclaringType : System.Management.Automation.Language.Compiler
        MemberType    : Method
        Module        : System.Management.Automation.dll
    StackTrace  : 
   at System.Management.Automation.Language.Compiler.GetAttribute(AttributeAst attributeAst)
   at System.Management.Automation.Language.ScriptBlockAst.System.Management.Automation.Language.IParameterMetadataProvider.GetScriptBlockAttributes()+MoveNext()
   at System.Collections.Generic.LargeArrayBuilder`1.AddRange(IEnumerable`1 items)
   at System.Collections.Generic.EnumerableHelpers.ToArray[T](IEnumerable`1 source)
   at System.Management.Automation.CompiledScriptBlockData.InitializeMetadata()
   at System.Management.Automation.CompiledScriptBlockData.Compile(Boolean optimized)
   at System.Management.Automation.PSScriptCmdlet..ctor(ScriptBlock scriptBlock, Boolean useNewScope, Boolean fromScriptFile, ExecutionContext context)
   at System.Management.Automation.CommandProcessor.Init(IScriptCommandInfo scriptCommandInfo)
   at System.Management.Automation.CommandDiscovery.GetScriptAsCmdletProcessor(IScriptCommandInfo scriptCommandInfo, ExecutionContext context, Boolean useNewScope, Boolean fromScriptFile, 
SessionStateInternal sessionState)
   at System.Management.Automation.CommandDiscovery.CreateCommandProcessorForScript(FunctionInfo functionInfo, ExecutionContext context, Boolean useNewScope, SessionStateInternal sessionState) 
   at System.Management.Automation.CommandDiscovery.LookupCommandProcessor(CommandInfo commandInfo, CommandOrigin commandOrigin, Nullable`1 useLocalScope, SessionStateInternal sessionState)    
   at System.Management.Automation.CommandDiscovery.LookupCommandProcessor(String commandName, CommandOrigin commandOrigin, Nullable`1 useLocalScope)
   at System.Management.Automation.ExecutionContext.CreateCommand(String command, Boolean dotSource)
   at System.Management.Automation.PipelineOps.AddCommand(PipelineProcessor pipe, CommandParameterInternal[] commandElements, CommandBaseAst commandBaseAst, CommandRedirection[] redirections,  
ExecutionContext context)
   at System.Management.Automation.PipelineOps.InvokePipeline(Object input, Boolean ignoreInput, CommandParameterInternal[][] pipeElements, CommandBaseAst[] pipeElementAsts,
CommandRedirection[][] commandRedirections, FunctionContext funcContext)
   at System.Management.Automation.Interpreter.ActionCallInstruction`6.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
    Message     : Cannot find the type for custom attribute 'EditorCommand'. Make sure that the assembly that contains this type is loaded.
    Data        : System.Collections.ListDictionaryInternal
    Source      : System.Management.Automation
    HResult     : -2146233087
TargetObject          : [EditorCommand(DisplayName='Convert Command to Splat Expression')]
CategoryInfo          : InvalidOperation: ([EditorCommand(Disp…Splat Expression')]:AttributeAst) [], RuntimeException
FullyQualifiedErrorId : CustomAttributeTypeNotFound
InvocationInfo        : 
    ScriptLineNumber : 10
    OffsetInLine     : 5
    HistoryId        : -1
    ScriptName       : C:\Users\ntwebb\Documents\PowerShell\Modules\EditorServicesCommandSuite\0.4.0\Public\ConvertTo-SplatExpression.ps1
    Line             : [EditorCommand(DisplayName='Convert Command to Splat Expression')]
    PositionMessage  : At C:\Users\ntwebb\Documents\PowerShell\Modules\EditorServicesCommandSuite\0.4.0\Public\ConvertTo-SplatExpression.ps1:10 char:5
                       +     [EditorCommand(DisplayName='Convert Command to Splat Expression') …
                       +     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    PSScriptRoot     : C:\Users\ntwebb\Documents\PowerShell\Modules\EditorServicesCommandSuite\0.4.0\Public
    PSCommandPath    : C:\Users\ntwebb\Documents\PowerShell\Modules\EditorServicesCommandSuite\0.4.0\Public\ConvertTo-SplatExpression.ps1
    CommandOrigin    : Internal
ScriptStackTrace      : at <ScriptBlock>, <No file>: line 1
@SeeminglyScience SeeminglyScience self-assigned this Nov 11, 2019
@SeeminglyScience SeeminglyScience pinned this issue Nov 11, 2019
@SeeminglyScience
Copy link
Owner

SeeminglyScience commented Nov 18, 2019

I've made some changes to the v0.5.0 branch to accommodate the new PowerShellEditorServices architecture. That version is a complete overhaul of the module and isn't where I want it to be for release yet, but it's currently functional and should serve as a drop in replacement.

You can grab a daily here
Edit 2020/02/08: Updated for PowerShellEditorServices 2.0.0-preview.8
Edit 2020/02/22: Updated for PowerShellEditorServices 2.0.0-preview.9

There's a few new editor commands in there, some fixes to old ones, and a lot more configuration options. There's also a context based refactor system similar to "quick fixes" or "code actions". To use that, put something like this in your keybindings.json:

    {
        "key": "ctrl+.",
        "command": "PowerShell.InvokeRegisteredEditorCommand",
        "args": { "commandName": "Invoke-DocumentRefactor" },
        "when": "editorLangId == 'powershell'",
    },

And then press Ctrl + . on whatever you want to refactor.

There's also configuration options scoped to machine, user, or project levels. To create a new settings file, use New-CommandSuiteSettingsFile with either -Scope Machine (or User) or -Path for project. (@markekraus this includes the splat variable name config)

@scrthq
Copy link

scrthq commented Nov 20, 2019

Daily works great @SeeminglyScience - thank you so much for publishing the link as a temporary workaround!

image

@kilasuit
Copy link

Any chance the v 0.5.0 can be pushed to the Gallery as a prelease?

@SeeminglyScience
Copy link
Owner

@kilasuit Not yet, PowerShellEditorServices is currently changing too rapidly to steadily release previews atm.

Once PowerShell/PowerShellEditorServices#1183 makes it into a vscode-powershell preview release then I'll get something up.

@PrzemyslawKlys
Copy link

After today's update to Preview 0.5 stopped working again.

Import-Module -Name EditorServicesCommandSuite                                               149,03ms

Add-Type : Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
At C:\Program Files\WindowsPowerShell\Modules\EditorServicesCommandSuite\0.5.0\EditorServicesCommandSuite.psm1:15 char:9
+         Add-Type -Path "$PSScriptRoot/EditorServicesCommandSuite.Edit ...
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Add-Type], ReflectionTypeLoadException
    + FullyQualifiedErrorId : System.Reflection.ReflectionTypeLoadException,Microsoft.PowerShell.Commands.AddTypeCommand

The following exception occurred while retrieving member "GetCommandSuite": "Could not load type 'Microsoft.PowerShell.EditorServices.Servic
es.PowerShellContext.EditorObject' from assembly 'Microsoft.PowerShell.EditorServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null
'."
At C:\Program Files\WindowsPowerShell\Modules\EditorServicesCommandSuite\0.5.0\EditorServicesCommandSuite.psm1:19 char:5
+     $CommandSuite = $type::GetCommandSuite(
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], ExtendedTypeSystemException
    + FullyQualifiedErrorId : CatchFromBaseGetMember
 
Get-RefactorOption : No existing CommandSuite instance was found. Initialization with the host editor may have failed.
At C:\Program Files\WindowsPowerShell\Modules\EditorServicesCommandSuite\0.5.0\EditorServicesCommandSuite.psm1:53 char:9
+         Get-RefactorOption | ForEach-Object {
+         ~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (:) [Get-RefactorOption], NoCommandSuiteInstanceException
    + FullyQualifiedErrorId : NoCommandSuiteInstance,EditorServicesCommandSuite.Commands.GetRefactorOptionCommand
 Import-EditorCommand -Module EditorServicesCommandSuite

Unable to find type [Microsoft.PowerShell.EditorServices.Services.PowerShellContext.EditorCommand].
At C:\Users\przemyslaw.klys\.vscode\extensions\ms-vscode.powershell-preview-2020.2.0\modules\PowerShellEditorServices\Commands\Public\Import
-EditorCommand.ps1:10 char:17
+ ... [OutputType([Microsoft.PowerShell.EditorServices.Services.PowerShellC ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (Microsoft.Power...t.EditorCommand:TypeName) [], RuntimeException
    + FullyQualifiedErrorId : TypeNotFound

@SeeminglyScience
Copy link
Owner

Thanks @PrzemyslawKlys! Yeah, some more big changes. I'll get another build ready this weekend.

@SeeminglyScience
Copy link
Owner

Fix for preview 9 here. Also updated the link above.

@PrzemyslawKlys
Copy link

Unable to find type [Microsoft.PowerShell.EditorServices.Services.PowerShellContext.EditorCommand].
At C:\Users\przemyslaw.klys\.vscode\extensions\ms-vscode.powershell-preview-2020.2.0\modules\PowerShellEditorServices\Commands\Public\Import
-EditorCommand.ps1:10 char:17
+ ... [OutputType([Microsoft.PowerShell.EditorServices.Services.PowerShellC ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (Microsoft.Power...t.EditorCommand:TypeName) [], RuntimeException
    + FullyQualifiedErrorId : TypeNotFound

One error still remains.

@SeeminglyScience
Copy link
Owner

@PrzemyslawKlys That error isn't coming from ESCS, can you file that on PowerShellEditorServices? Also you can remove Import-EditorCommand from your profile, it's no longer required for this module (and that'll bypass that error).

@PrzemyslawKlys
Copy link

I can, but does it still matter if I'm not supposed to use it?

@SeeminglyScience
Copy link
Owner

This module just doesn't require it anymore, other modules still can. I'll take submitting the issue, thanks for the report 🙂

@SeeminglyScience
Copy link
Owner

Fixed with v1.0.0-beta1

Install-Module EditorServicesCommandSuite -Scope CurrentUser -AllowPrerelease -Force

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants