Skip to content

"using assembly" can't find assembly in scriptdir on non-Windows because of bug in Parser.cs line:5136 #21161

@JamesWTruher

Description

@JamesWTruher

Prerequisites

Steps to reproduce

create an assembly and run a script with the following content:

using assembly mydll.dll
[mydll.mytype]

Expected behavior

no errors

Actual behavior

ParserError: /Users/james/bin/testit.ps1:1
Line |
   1 |  using assembly mydll.dll
     |                 ~~~~~~~~~~~~~~~~~~
     | Cannot load assembly 'mydll.dll'.

Error details

line 5136:

assemblyFileName = workingDirectory + @"\" + assemblyFileName

on a Unix System, \ is not a directory separator but a valid filename character.

The fix is:

assemblyFileName = Path.Combine(workingDirectory, assemblyFileName);

Environment data

> $psversiontable

Name                           Value
----                           -----
PSVersion                      7.4.0
PSEdition                      Core
GitCommitId                    7.4.0
OS                             Darwin 23.3.0 Darwin Kernel Version 23.3.0: Wed Dec 20 21:28:58 PST 2023; root:xnu-10002.81.5~7/RELEASE_X86_64
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions