Apostrophe in filepath breaks Import-Module when the module has a class in it
See original GitHub issueWhen there is an apostrophe in the filepath to a module Import-Module will work with modules that only have functions in however will fail if there is a class in the module. The exact same code will work when the module is located on a different path.
This situation was encountered due to the default OneDrive for Business path including an apostrophe. When using the user windowspowershell module with folder redirection all use modules now have an apostrophe in the path.
This affects both Version 5.1 and Version 6beta3
Steps to reproduce
Create Folder C:\Te’mp Save the below code to C:\Te’mp\TypeName.psm1
# Define a class
class TypeName
{
# Property with validate set
[ValidateSet("val1", "Val2")]
[string] $P1
# Constructor
TypeName ([string] $s)
{
$this.P1 = $s
}
}
Import-Module 'C:\te''mp\TypeName.psm1'
Expected behavior
Module Loaded Successfully / No Output
Actual behavior
Import-Module : The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047)
At line:1 char:1
+ Import-Module 'C:\Te''mp\TypeName.psm1'
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Import-Module], FileLoadException
+ FullyQualifiedErrorId : System.IO.FileLoadException,Microsoft.PowerShell.Commands.ImportModuleCommand
Environment data
> $PSVersionTable
Name Value
---- -----
PSVersion 6.0.0-beta
PSEdition Core
GitCommitId v6.0.0-beta.3
OS Microsoft Windows 10.0.14393
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Name Value
---- -----
PSVersion 5.1.15063.413
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.15063.413
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
Issue Analytics
- State:
- Created 6 years ago
- Comments:8 (2 by maintainers)
Top Results From Across the Web
python - How do I read a XLSX if the filepath or filename ...
1 Answer. The problem isn't with the apostrophe, it's with the backslash ( \ ) character. It is being used simultaneously as a...
Read more >Bug in PowerShell classes when script is in a folder ...
My client's PowerShell scripts aren't working for a new user who happens to have a single-quote in their name - which means their...
Read more >Swift Error Module Importing Failed Invalid Pathname
I was playing around with Swift on Ubuntu and got the same message just launching the swift REPL. ... Apostrophe in filepath breaks...
Read more >What's New in Windows PowerShell 5.0
These release notes describe the new features and changes in Windows PowerShell 5.x.
Read more >Swift Error Module Importing Failed Invalid Pathname
Importing locally developed module fails with Import. Apostrophe in filepath breaks Import-Module when the. ImportError: DLL load failed: The specified ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

And don’t forget that you can now use the Unicode esc sequence in dq strings e.g.
"`u{2019}". 😃I’ve written a (very quick and VERY dirty) script which loops through all visible ASCII chars and outputs the ones that fail. In version 5.1 the following fail: 39 ('), 44 (,) and 61 (=). Interestingly enough testing with version 6.0 Beta 3 the same 3 fail as well as 126 (~)