René's URL Explorer Experiment


Title: Strange behaviour when using in a Powershell class a class defined in a DLL imported with Add-Type · Issue #26477 · PowerShell/PowerShell · GitHub

Open Graph Title: Strange behaviour when using in a Powershell class a class defined in a DLL imported with Add-Type · Issue #26477 · PowerShell/PowerShell

X Title: Strange behaviour when using in a Powershell class a class defined in a DLL imported with Add-Type · Issue #26477 · PowerShell/PowerShell

Description: Prerequisites Write a descriptive title. Make sure you are able to repro it on the latest released version Search the existing issues. Refer to the FAQ. Refer to Differences between Windows PowerShell 5.1 and PowerShell. Steps to reprodu...

Open Graph Description: Prerequisites Write a descriptive title. Make sure you are able to repro it on the latest released version Search the existing issues. Refer to the FAQ. Refer to Differences between Windows PowerSh...

X Description: Prerequisites Write a descriptive title. Make sure you are able to repro it on the latest released version Search the existing issues. Refer to the FAQ. Refer to Differences between Windows PowerSh...

Opengraph URL: https://github.com/PowerShell/PowerShell/issues/26477

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Strange behaviour when using in a Powershell class a class defined in a DLL imported with Add-Type","articleBody":"### Prerequisites\n\n- [x] Write a descriptive title.\n- [x] Make sure you are able to repro it on the [latest released version](https://github.com/PowerShell/PowerShell/releases)\n- [x] Search the existing issues.\n- [x] Refer to the [FAQ](https://github.com/PowerShell/PowerShell/blob/master/docs/FAQ.md).\n- [x] Refer to [Differences between Windows PowerShell 5.1 and PowerShell](https://learn.microsoft.com/powershell/scripting/whats-new/differences-from-windows-powershell).\n\n### Steps to reproduce\n\nI don't know if this is a bug or simply the expected behavior, but it seems strange to me.\nIn a Powershell class, I want to use a class defined in a DLL imported with Add-Type.\n\nFor my first attempt, I simply tried the ClassS1.ps1 script.\n\n# ClassS1.ps1\nAdd-Type -path '.\\obs-websocket-dotnet.dll'\n#\n[OBSWebsocketDotNet.OBSWebsocket] $obsWS = $null\n#\nclass ClassS1 {\n\t[OBSWebsocketDotNet.OBSWebsocket] $obsWS = $null\n}\n#\n\nRunning the ClassS1.ps1 script generates the following error\n\nParserError: …..\\ClassS1.ps1:7\nLine |\n   7 |      [OBSWebsocketDotNet.OBSWebsocket] $obsWS = $null\n     |       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n     | Unable to find type [OBSWebsocketDotNet.OBSWebsocket].\n\nUsing the [OBSWebsocketDotNet.OBSWebsocket] class defined in obs-websocket-dotnet.dll generates an error only when used inside the powershell class definition.\n\nFor my second attempt, I tried using a powershell module hosting the powershell class definition.\n\n# ClassS2.ps1\nusing module '.\\ClassM2.psm1'\nAdd-Type -path '.\\obs-websocket-dotnet.dll'\n#\n[OBSWebsocketDotNet.OBSWebsocket] $obsWS = $null\n#\n\n# ClassM2.psm1\nclass ClassM2 {\n\t[OBSWebsocketDotNet.OBSWebsocket] $obsWS = $null\n}\n#\n\nRunning the ClassS2.ps1 script generates the following error\n\n.\\ClassS2.ps1: At D:\\Données\\Alain\\CloudStation\\Eglise\\Touch Portal\\Tests\\Classes\\ClassM2.psm1:3 char:3\n+     [OBSWebsocketDotNet.OBSWebsocket] $obsWS = $null\n+      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\nUnable to find type [OBSWebsocketDotNet.OBSWebsocket].\n\nThis error is not surprising because the DLL is only imported after the using module statement, module that needs the [OBSWebsocketDotNet.OBSWebsocket] class.\n\nIn order to bypass the requirement to use the using statement before any other statement, I made a third attempt by placing the Add-Type statement in another AddType.psm1 module.\n\n# AddType.psm1\nAdd-Type -path '.\\obs-websocket-dotnet.dll'\n#\n\n# ClassS3.ps1\nusing module '.\\AddType.psm1'\nusing module '.\\ClassM3.psm1'\n#\n[OBSWebsocketDotNet.OBSWebsocket] $obsWS = $null\n#\n\n# ClassM3.psm1\nclass ClassM3 {\n\t[OBSWebsocketDotNet.OBSWebsocket] $obsWS = $null\n}\n#\n\nRunning the ClassS3.ps1 script does not generate any error\n\nThe fourth attempt uses only the script similar to that of the first attempt but using the AddType.psm1 module from the third attempt.\n\n# ClassS4.ps1\nusing module '.\\AddType.psm1'\n#\n[OBSWebsocketDotNet.OBSWebsocket] $obsWS = $null\n#\t\nclass ClassS4 {\n\t[OBSWebsocketDotNet.OBSWebsocket] $obsWS = $null\n}\n#\n\nRunning the ClassS4.ps1 script does not generate any error\n\nAre these behaviors expected ?\n\n\n### Expected behavior\n\n```console\nno error when running ClassS1.ps1\n```\n\n### Actual behavior\n\n```console\nerror when running ClassS1.ps1\n\nParserError: ......\\ClassS1.ps1:7\nLine |\n   7 |      [OBSWebsocketDotNet.OBSWebsocket] $obsWS = $null\n     |       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n     | Unable to find type [OBSWebsocketDotNet.OBSWebsocket].\n```\n\n### Error details\n\n```console\nException             :\n    Type        : System.Management.Automation.ParseException\n    Errors      :\n        Extent  : OBSWebsocketDotNet.OBSWebsocket\n        ErrorId : TypeNotFound\n        Message : Unable to find type [OBSWebsocketDotNet.OBSWebsocket].\n    Message     : At ......\\ClassS1.ps1:7 char:3\n                  +     [OBSWebsocketDotNet.OBSWebsocket] $obsWS = $null\n                  +      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n                  Unable to find type [OBSWebsocketDotNet.OBSWebsocket].\n    ErrorRecord :\n        Exception             :\n            Type    : System.Management.Automation.ParentContainsErrorRecordException\n            Message : At ......\\ClassS1.ps1:7 char:3\n                      +     [OBSWebsocketDotNet.OBSWebsocket] $obsWS = $null\n                      +      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n                      Unable to find type [OBSWebsocketDotNet.OBSWebsocket].\n            HResult : -2146233087\n        CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException\n        FullyQualifiedErrorId : TypeNotFound\n        InvocationInfo        :\n            ScriptLineNumber : 7\n            OffsetInLine     : 3\n            HistoryId        : 2\n            ScriptName       : ......\\ClassS1.ps1\n            Line             : [OBSWebsocketDotNet.OBSWebsocket] $obsWS = $null\n\n            Statement        : OBSWebsocketDotNet.OBSWebsocket\n            PositionMessage  : At ......\\ClassS1.ps1:7 char:3\n                               +     [OBSWebsocketDotNet.OBSWebsocket] $obsWS = $null\n                               +      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n            PSScriptRoot     : ......\\Classes\n            PSCommandPath    : ......\\ClassS1.ps1\n            CommandOrigin    : Internal\n        ScriptStackTrace      : at \u003cScriptBlock>, \u003cNo file>: line 1\n    TargetSite  :\n        Name          : Create\n        DeclaringType : [System.Management.Automation.ScriptBlock]\n        MemberType    : Method\n        Module        : System.Management.Automation.dll\n    Data        : System.Collections.ListDictionaryInternal\n    Source      : System.Management.Automation\n    HResult     : -2146233087\n    StackTrace  :\n   at System.Management.Automation.ScriptBlock.Create(Parser parser, String fileName, String fileContents)\n   at System.Management.Automation.ExternalScriptInfo.ParseScriptContents(Parser parser, String fileName, String fileContents, Nullable`1 definingLanguageMode)\n   at System.Management.Automation.ExternalScriptInfo.get_ScriptBlock()\n   at System.Management.Automation.CommandDiscovery.CreateCommandProcessorForScript(ExternalScriptInfo scriptInfo, ExecutionContext context, Boolean useNewScope, SessionStateInternal sessionState)\n   at System.Management.Automation.CommandDiscovery.LookupCommandProcessor(CommandInfo commandInfo, CommandOrigin commandOrigin, Nullable`1 useLocalScope, SessionStateInternal sessionState)\n   at System.Management.Automation.CommandDiscovery.LookupCommandProcessor(String commandName, CommandOrigin commandOrigin, Nullable`1 useLocalScope)\n   at System.Management.Automation.ExecutionContext.CreateCommand(String command, Boolean dotSource)\n   at System.Management.Automation.PipelineOps.AddCommand(PipelineProcessor pipe, CommandParameterInternal[] commandElements, CommandBaseAst commandBaseAst, CommandRedirection[] redirections, ExecutionContext context)\n   at System.Management.Automation.PipelineOps.InvokePipeline(Object input, Boolean ignoreInput, CommandParameterInternal[][] pipeElements, CommandBaseAst[] pipeElementAsts, CommandRedirection[][] commandRedirections,\nFunctionContext funcContext)\n   at System.Management.Automation.Interpreter.ActionCallInstruction`6.Run(InterpretedFrame frame)\n   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)\nCategoryInfo          : ParserError: (:) [], ParseException\nFullyQualifiedErrorId : TypeNotFound\nInvocationInfo        :\n    ScriptLineNumber : 7\n    OffsetInLine     : 3\n    HistoryId        : 2\n    ScriptName       : ......\\ClassS1.ps1\n    Line             : [OBSWebsocketDotNet.OBSWebsocket] $obsWS = $null\n\n    Statement        : OBSWebsocketDotNet.OBSWebsocket\n    PositionMessage  : At ......\\ClassS1.ps1:7 char:3\n                       +     [OBSWebsocketDotNet.OBSWebsocket] $obsWS = $null\n                       +      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n    PSScriptRoot     : ......\\Classes\n    PSCommandPath    : ......\\ClassS1.ps1\n    CommandOrigin    : Internal\nScriptStackTrace      : at \u003cScriptBlock>, \u003cNo file>: line 1\n```\n\n### Environment data\n\n```powershell\nName                           Value\n----                           -----\nPSVersion                      7.5.4\nPSEdition                      Core\nGitCommitId                    7.5.4\nOS                             Microsoft Windows 10.0.19045\nPlatform                       Win32NT\nPSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}\nPSRemotingProtocolVersion      2.3\nSerializationVersion           1.1.0.1\nWSManStackVersion              3.0\n```\n\n### Visuals\n\n_No response_","author":{"url":"https://github.com/frogeater","@type":"Person","name":"frogeater"},"datePublished":"2025-11-18T15:56:23Z","url":"https://github.com/PowerShell/PowerShell/issues/26477"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:85dd01cc-ef7f-188e-a4c3-734f2e0f0a03
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idE5B8:5C8B1:D5C94E:134E591:6AFDB119
html-safe-nonce29f1fee6f6adfc437aded739b64710626eef12308469fa001d880e4a7acfce7f
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNUI4OjVDOEIxOkQ1Qzk0RToxMzRFNTkxOjZBRkRCMTE5IiwidmlzaXRvcl9pZCI6IjY3NDkyMTc1Mzc1MDc4MzIwODkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac31c1356a6aff76cf4b5dc0746fed06111c3de1630335072ee90bb0f0e3586886
hovercard-subject-tagissue:3638881594
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/PowerShell/PowerShell/26477/issue_layout
twitter:imagehttps://opengraph.githubassets.com/9066832b413f47a08c6e51f60e373839083e857dfedbf1677b8f6abcad2c2d1f/PowerShell/PowerShell/issues/26477
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/9066832b413f47a08c6e51f60e373839083e857dfedbf1677b8f6abcad2c2d1f/PowerShell/PowerShell/issues/26477
og:image:altPrerequisites Write a descriptive title. Make sure you are able to repro it on the latest released version Search the existing issues. Refer to the FAQ. Refer to Differences between Windows PowerSh...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamefrogeater
hostnamegithub.com
expected-hostnamegithub.com
None3c532f4d069d6fbe9b1837450343d1b9e0619a7d5c4ba0b3b64fd8e0bae67c7e
turbo-cache-controlno-preview
go-importgithub.com/PowerShell/PowerShell git https://github.com/PowerShell/PowerShell.git
octolytics-dimension-user_id11524380
octolytics-dimension-user_loginPowerShell
octolytics-dimension-repository_id49609581
octolytics-dimension-repository_nwoPowerShell/PowerShell
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id49609581
octolytics-dimension-repository_network_root_nwoPowerShell/PowerShell
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release5396ad00d1c6d19097aee7fc4d00a2eb03432c8f
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/PowerShell/PowerShell/issues/26477#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FPowerShell%2FPowerShell%2Fissues%2F26477
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FPowerShell%2FPowerShell%2Fissues%2F26477
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=PowerShell%2FPowerShell
Reloadhttps://github.com/PowerShell/PowerShell/issues/26477
Reloadhttps://github.com/PowerShell/PowerShell/issues/26477
Reloadhttps://github.com/PowerShell/PowerShell/issues/26477
PowerShellhttps://github.com/PowerShell
PowerShellhttps://github.com/PowerShell/PowerShell
Codehttps://github.com/PowerShell/PowerShell
Issues1.3k (1.3k)https://github.com/PowerShell/PowerShell/issues
Pull requests366 (366)https://github.com/PowerShell/PowerShell/pulls
Discussionshttps://github.com/PowerShell/PowerShell/discussions
Actionshttps://github.com/PowerShell/PowerShell/actions
Projectshttps://github.com/PowerShell/PowerShell/projects
Security and quality3 (3)https://github.com/PowerShell/PowerShell/security
Insightshttps://github.com/PowerShell/PowerShell/insights
https://github.com/PowerShell/PowerShell
New issuehttps://github.com/login?return_to=https://github.com/PowerShell/PowerShell/issues/26477
New issuehttps://github.com/login?return_to=https://github.com/PowerShell/PowerShell/issues/26477
Strange behaviour when using in a Powershell class a class defined in a DLL imported with Add-Typehttps://github.com/PowerShell/PowerShell/issues/26477#top
https://github.com/frogeater
frogeaterhttps://github.com/frogeater
on Nov 18, 2025https://github.com/PowerShell/PowerShell/issues/26477#issue-3638881594
latest released versionhttps://github.com/PowerShell/PowerShell/releases
FAQhttps://github.com/PowerShell/PowerShell/blob/master/docs/FAQ.md
Differences between Windows PowerShell 5.1 and PowerShellhttps://learn.microsoft.com/powershell/scripting/whats-new/differences-from-windows-powershell
frogeaterhttps://github.com/frogeater
Needs-TriageThe issue is new and needs to be triaged by a work group.https://github.com/PowerShell/PowerShell/issues?q=state%3Aopen%20label%3A%22Needs-Triage%22
on Nov 18, 2025https://github.com/PowerShell/PowerShell/issues/26477#event-21020055686
https://github.com/frogeater
frogeaterhttps://github.com/frogeater
on Nov 18, 2025https://github.com/PowerShell/PowerShell/issues/26477#issuecomment-3548388175
https://github.com/mklement0
Michael Klement (mklement0)https://github.com/mklement0
on Nov 18, 2025https://github.com/PowerShell/PowerShell/issues/26477#issuecomment-3548721261
Using external types / classes in Custom PowerShell Classes (v5) results in Parsing Error #2074 (comment)https://github.com/PowerShell/PowerShell/issues/2074#issuecomment-428299006
Fix Various PowerShell Class Issues #6652https://github.com/PowerShell/PowerShell/issues/6652
https://github.com/frogeater
frogeaterhttps://github.com/frogeater
on Nov 20, 2025https://github.com/PowerShell/PowerShell/issues/26477#issuecomment-3556902672
frogeaterhttps://github.com/frogeater
duplicatehttps://github.com/PowerShell/PowerShell/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Aduplicate
Using external types / classes in Custom PowerShell Classes (v5) results in Parsing Error #2074https://github.com/PowerShell/PowerShell/issues/2074
on Nov 20, 2025https://github.com/PowerShell/PowerShell/issues/26477#event-21064971879
microsoft-github-policy-servicehttps://github.com/apps/microsoft-github-policy-service
Needs-TriageThe issue is new and needs to be triaged by a work group.https://github.com/PowerShell/PowerShell/issues?q=state%3Aopen%20label%3A%22Needs-Triage%22
on Nov 20, 2025https://github.com/PowerShell/PowerShell/issues/26477#event-21064995265
Sign up for freehttps://github.com/signup?return_to=https://github.com/PowerShell/PowerShell/issues/26477
Sign in to commenthttps://github.com/login?return_to=https://github.com/PowerShell/PowerShell/issues/26477
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.