question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Hosted PS core in ASP.Net core The system cannot find the file specified

See original GitHub issue

ASP.NET core 2.0 app.

.csproj:

    <PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.0" PrivateAssets="All" />
    <PackageReference Include="Microsoft.PowerShell.Commands.Diagnostics" Version="6.0.0-beta.8" />
    <PackageReference Include="Microsoft.PowerShell.SDK" Version="6.0.0-beta.8" />
    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.0" PrivateAssets="All" />
    <PackageReference Include="Microsoft.WSMan.Management" Version="6.0.0-beta.8" />

controller code:

    using (PowerShell ps = PowerShell.Create())
            {
                var result = ps.AddScript(@"New-Item -Path 'C:\Programming\' -Type Directory -Name TestFolder").Invoke();
            }

Results in an exeption:

System.Management.Automation.RuntimeException: The following errors occurred when updating the assembly list for the runspace: Could not load file or assembly ‘C:\Programming\Intranet\Intranet\Microsoft.PowerShell.Commands’. The system cannot find the file specified. Could not load file or assembly ‘C:\Programming\Intranet\Intranet\Microsoft.PowerShell’. The system cannot find the file specified. Could not load file or assembly ‘C:\Programming\Intranet\Intranet\Microsoft.PowerShell.Commands’. The system cannot find the file specified. Could not load file or assembly ‘C:\Programming\Intranet\Intranet\Microsoft.PowerShell.Commands’. The system cannot find the file specified. Could not load file or assembly ‘C:\Programming\Intranet\Intranet\Microsoft.PowerShell’. The system cannot find the file specified. Could not load file or assembly ‘C:\Programming\Intranet\Intranet\Microsoft.WSMan’. The system cannot find the file specified…

at System.Management.Automation.ExecutionContext.UpdateAssemblyCache()

at System.Management.Automation.Runspaces.RunspaceConfigurationEntryCollection`1.Update(Boolean force)

at System.Management.Automation.Runspaces.RunspaceConfiguration.Bind(ExecutionContext executionContext)

at System.Management.Automation.AutomationEngine…ctor(PSHost hostInterface, RunspaceConfiguration runspaceConfiguration, InitialSessionState iss)

at System.Management.Automation.Runspaces.LocalRunspace.DoOpenHelper()

at System.Management.Automation.Runspaces.LocalRunspace.OpenHelper(Boolean syncCall)

at System.Management.Automation.Runspaces.RunspaceBase.CoreOpen(Boolean syncCall)

at System.Management.Automation.Runspaces.RunspaceBase.Open()

at System.Management.Automation.PowerShell.Worker.CreateRunspaceIfNeededAndDoWork(Runspace rsToUse, Boolean isSync)

at System.Management.Automation.PowerShell.CoreInvokeHelper[TInput,TOutput](PSDataCollection1 input, PSDataCollection1 output, PSInvocationSettings settings)

at System.Management.Automation.PowerShell.CoreInvoke[TInput,TOutput](PSDataCollection1 input, PSDataCollection1 output, PSInvocationSettings settings)

at System.Management.Automation.PowerShell.CoreInvoke[TOutput](IEnumerable input, PSDataCollection`1 output, PSInvocationSettings settings)

at System.Management.Automation.PowerShell.Invoke(IEnumerable input, PSInvocationSettings settings)

at System.Management.Automation.PowerShell.Invoke()

at Intranet.Controllers.PowershellController.Test() in C:\Programming\Intranet\Intranet\Controllers\PowershellController.cs:line 30

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:19 (13 by maintainers)

github_iconTop GitHub Comments

1reaction
chunqingchencommented, Nov 3, 2017

I have verified that this bug is not related to #4196 and therefore not fixed by #4942 #4196. Although the behavior is very similar, but regardless the change of #4196, it repros anyway. I can take a look.

0reactions
chunqingchencommented, Nov 4, 2017

After talked with dongbo and verified the issue with further steps, the fix actually works.

The keypoint is building nuget package with the code change as local package and reference to the local package instead of going online (of course, the code change won’t affect the online package, beta.8 in this case).

Here is a repro step:

  1. Generate the nuget package locally with the code change: $VersionSuffix = (“v6.0.0-beta.9” -split ‘-’)[-1] Publish-NuGetFeed -VersionSuffix $VersionSuffix

  2. edit the nuget config file include the local package: go to …\PowerShell\docs\host-powershell\sample-dotnet2.0-powershell.beta.3 add following config to NuGet.config <add key="local-feed" value="C:\Github\powershellfull\p2\PowerShell\nuget-artifacts" /> where C:\Github\powershellfull\p2\PowerShell\nuget-artifacts is folder where previous neget package generates.

  3. go to …\sample-dotnet2.0-powershell.beta.3\MyApp dotnet restore dotnet run

The exception is gone.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ASP.NET Core The system cannot find the file specified
It looks like it is unable to find node.exe. I saw the same error after installing Node for the first time. It was...
Read more >
Could not load file or assembly 'Microsoft.AspNet. ...
The system cannot find the file specified. Assembly manager loaded from: C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll Running under executable C:\ ...
Read more >
Building a Windows service with Worker ...
WindowsServices but I found another similar Microsoft.AspNetCore.Hosting.WindowsServices but it does not have the UseWindowsService method.
Read more >
How to Solve the Command or File Was Not Found EF ...
In this article, we are going to learn how to solve the Command or File Was Not Found EF Core migration error.
Read more >
Professional C# and .NET - Google Books Result
invoking the method RequestStart does not count metrics, and the Stopwatch ... AspNetCore.Hosting, Microsoft-AspNetCore-Server-Kestrel, and System.Net.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found