This should work, but it does not anymore.
PS> Add-Type "public class Style : System.Windows.DependencyObject {}" -ReferencedAssemblies "WindowsBase"
PS>
PS> Add-Type "public class Style : System.Windows.DependencyObject {}" -ReferencedAssemblies "WindowsBase"
Add-Type: (1,37): error CS0234: The type or namespace name 'DependencyObject' does not exist in the namespace 'System.Windows' (are you missing an assembly reference?)
public class Style : System.Windows.DependencyObject {}
^
Add-Type: Cannot add type. Compilation errors occurred.
PS>
Exception :
Type : System.IO.FileNotFoundException
Message : Could not find file 'C:\Program Files\PowerShell\7\WindowsBase'.
FileName : C:\Program Files\PowerShell\7\WindowsBase
TargetSite :
Name : CreateFile
DeclaringType : [Microsoft.Win32.SafeHandles.SafeFileHandle]
MemberType : Method
Module : System.Private.CoreLib.dll
Source : System.Private.CoreLib
HResult : -2147024894
StackTrace :
at Microsoft.Win32.SafeHandles.SafeFileHandle.CreateFile(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options)
at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, Nullable`1 unixCreateMode)
at System.IO.Strategies.OSFileStreamStrategy..ctor(String path, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, Nullable`1 unixCreateMode)
at System.IO.Strategies.FileStreamHelpers.ChooseStrategyCore(String path, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, Nullable`1 unixCreateMode)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
at Roslyn.Utilities.StandardFileSystem.OpenFile(String filePath, FileMode mode, FileAccess access, FileShare share)
at Roslyn.Utilities.CommonCompilerFileSystemExtensions.OpenFileWithNormalizedException(ICommonCompilerFileSystem fileSystem, String filePath, FileMode fileMode, FileAccess fileAccess, FileShare fileShare)
at Microsoft.CodeAnalysis.MetadataReference.CreateFromFile(String path, MetadataReferenceProperties properties, DocumentationProvider documentation)
at Microsoft.PowerShell.Commands.AddTypeCommand.GetPortableExecutableReferences()
at Microsoft.PowerShell.Commands.AddTypeCommand.CompileToAssembly(List`1 syntaxTrees, CompilationOptions compilationOptions, EmitOptions emitOptions)
at Microsoft.PowerShell.Commands.AddTypeCommand.SourceCodeProcessing()
at System.Management.Automation.CommandProcessorBase.Complete()
CategoryInfo : NotSpecified: (:) [Add-Type], FileNotFoundException
FullyQualifiedErrorId : System.IO.FileNotFoundException,Microsoft.PowerShell.Commands.AddTypeCommand
InvocationInfo :
MyCommand : Add-Type
ScriptLineNumber : 1
OffsetInLine : 1
HistoryId : 2
Line : Add-Type "public class Style : System.Windows.DependencyObject {}" -ReferencedAssemblies "$PSHome\WindowsBase"
Statement : Add-Type "public class Style : System.Windows.DependencyObject {}" -ReferencedAssemblies "$PSHome\WindowsBase"
PositionMessage : At line:1 char:1
+ Add-Type "public class Style : System.Windows.DependencyObject {}" -R …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
InvocationName : Add-Type
CommandOrigin : Internal
ScriptStackTrace : at <ScriptBlock>, <No file>: line 1
Prerequisites
Steps to reproduce
This should work, but it does not anymore.
I have to pass the full path to the DLLs to get them to load:
This appears to be because the assemblies are in
$PSHomebutAdd-Typeis searching$PSHome\refPowerShell/src/Microsoft.PowerShell.Commands.Utility/commands/utility/AddType.cs
Lines 801 to 808 in 0f3fd20
PowerShell/src/Microsoft.PowerShell.Commands.Utility/commands/utility/AddType.cs
Lines 643 to 646 in 0f3fd20
Expected behavior
Actual behavior
Error details
Environment data
Visuals
No response