C# Powershell - Error Could not load file or assembly 'C:\C# Projects\....\bin\Release\net8.0-windows10.0.17763.0\runtimes\win\lib\net8.0\System.Management.Automation.resources.dll'. The system cannot find the file specified.

John Sparks 10 Reputation points
2024-08-28T16:45:06.1033333+00:00

Hi, I'm working on a C# Application that makes PowerShell Calls. It used to work but since upgrading Nuget packages it now gives me the error:

"System.IO.FileNotFoundException: 'Could not load file or assembly 'C:\C# Projects\WpfApp-PS\WpfApp-PS\bin\Debug\net8.0-windows10.0.17763.0\runtimes\win\lib\net8.0\System.Management.Automation.resources.dll'. The system cannot find the file specified.'"

When I look at this folder I can see "System.Management.Automation.dll" but not "System.Management.Automation.resources.dll'"

I have the laste System.Management.Automation (7.4.5) installed. I have uninstalled it, reinstalled it and cleaned and rebuilt the solution but get the same error.

How can I fix this? Thanks.

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,912 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,509 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Jiale Xue - MSFT 45,006 Reputation points Microsoft Vendor
    2024-08-29T07:43:20.6933333+00:00

    Hi @John Sparks , Welcome to Microsoft Q&A,

    System.Management.Automation.resources.dll is a resource file used for localization, usually stored in the runtimes\win\lib\net8.0 folder. This folder should contain resource folders corresponding to your system language, such as zh-Hans (Simplified Chinese) or en (English). If the file is missing, you can try to reinstall the relevant package or manually copy the resource file.

    You can try to delete the System.Management.Automation package and reinstall it to make sure there will be no problems during the installation. But it didn't work after you tried it, which is not normal.

    If you confirm that the file is missing, you can try to manually copy the System.Management.Automation.resources.dll file from another installation of the same version of System.Management.Automation to the specified directory.

    Best Regards,

    Jiale


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". 

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


  2. John Sparks 10 Reputation points
    2024-08-30T08:52:10.54+00:00

    This seems to be an pre-exception error and is misleading. I'll create another question. Please delete this.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.