Skip to content

PowerShell Custom Attribute Types Unresolved on Initial File Open #5381

@mdaneri

Description

@mdaneri

Prerequisites

  • I have written a descriptive issue title.
  • I have searched all open and closed issues to ensure it has not already been reported.
  • I have read the troubleshooting guide.
  • I am sure this issue is with the extension itself and does not reproduce in a standalone PowerShell instance.
  • I have verified that I am using the latest version of Visual Studio Code and the PowerShell extension.
  • If this is a security issue, I have read the security issue reporting guidance.

Summary

Summary

When opening a PowerShell script that uses custom attributes defined in a .NET assembly, the VS Code PowerShell extension reports diagnostics such as:

Cannot find the type for custom attribute 'OpenApiSchemaComponent'. Make sure that the assembly that contains this type is loaded.

This happens on initial file open only. The error disappears immediately after any edit (even a single key press), indicating that a re-analysis fixes the issue.

This occurs even when using assembly with an absolute path is present, and even though the type is fully resolvable in the PowerShell terminal session.


Environment

  • OS: Windows
  • VS Code: (fill in)
  • PowerShell VS Code Extension: (fill in)
  • PowerShell Version: (fill in, e.g. 7.x)
  • Module: Kestrun
  • Attribute Assembly: Kestrun.Annotations.dll

Evidence

Terminal Session (Correct)

In the integrated PowerShell terminal:

Get-Module Kestrun
'OpenApiSchemaComponent' -as [type]

Result:

  • Module is loaded.
  • Attribute type resolves correctly from Kestrun.Annotations.dll.

Editor Diagnostics (Incorrect)

On initial open, VS Code reports missing attribute types despite:

  • Module being available
  • Assembly existing
  • Attribute being public and valid
  • Runtime resolution succeeding

Attempted Mitigations (All Failed)

  • RequiredAssemblies in module manifest
  • using module Kestrun
  • using assembly "<absolute path to Kestrun.Annotations.dll>"
  • Explicit Import-Module Kestrun
  • Absolute assembly paths (no variables)

None prevent the initial false diagnostic.


Expected Behavior

The PowerShell language server should:

  • Honor using assembly directives during the initial analysis pass
  • Resolve attribute types correctly without requiring a document edit
  • Invalidate or refresh diagnostics once assemblies are loaded

Actual Behavior

  • Initial analysis does not honor using assembly
  • Diagnostics are emitted too early
  • Diagnostics are not invalidated when assemblies become available
  • Only a manual edit triggers correct re-analysis

Impact

This significantly affects frameworks and DSL-style PowerShell codebases that rely on attributes (e.g. OpenAPI schemas, metadata-driven systems).

Files appear broken on open, reducing trust in editor diagnostics and developer productivity.


Attachments

  • Screenshot 1: Initial file open showing attribute diagnostics
  • Screenshot 2: Same file after a single key press (diagnostics resolved)

Notes

This appears to be a language server / diagnostic lifecycle issue, not a PowerShell runtime or module authoring problem.

PowerShell Version

# Version is not relevant
$PsversionTable;$Host 

Name                           Value
----                           -----
PSVersion                      7.5.4
PSEdition                      Core
GitCommitId                    7.5.4
OS                             Microsoft Windows 10.0.26200
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Name             : Visual Studio Code Host
Version          : 2025.5.0
InstanceId       : 521d25ca-73c6-4e76-8d50-caa5e80f5bfa
UI               : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture   : en-US
CurrentUICulture : en-US
PrivateData      : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
DebuggerEnabled  : True
IsRunspacePushed : False
Runspace         : System.Management.Automation.Runspaces.LocalRunspace

Visual Studio Code Version

code --version
1.108.1
585eba7c0c34fd6b30faac7c62a42050bfbc0086
x64

Extension Version

code --list-extensions --show-versions | Select-String powershell

ms-vscode.powershell@2025.5.0

Steps to Reproduce

  1. Start VS Code.
  2. Open a PowerShell file containing custom attributes defined in a .NET assembly.
  3. The file contains attribute usage such as:
[OpenApiSchemaComponent(RequiredProperties = ('statusCode','message'))]
class ErrorResponse {}
  1. Observe that VS Code immediately reports diagnostics saying the attribute type cannot be found.
  2. Press any key inside the editor (even whitespace).
  3. Diagnostics disappear and the attribute resolves correctly.

Visuals

Issue

Image

Solved after pressing a space anyware inside the editor

Image

Logs

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions