Repository navigation
Description
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](PSDataCollection
1 input, PSDataCollection1 output, PSInvocationSettings settings)at System.Management.Automation.PowerShell.CoreInvoke[TInput,TOutput](PSDataCollection
1 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
Activity
markekraus commentedon Oct 11, 2017
I can repro this, but I'm not exactly strong on the hosted app side.
Dongbo Wang (@daxian-dbw) ?
iSazonov commentedon Oct 11, 2017
Our docs https://github.com/PowerShell/PowerShell/tree/master/docs/host-powershell
markekraus commentedon Oct 11, 2017
Ilya (@iSazonov) I can repro this with the
sample-dotnet2.0-powershell.beta.3by just changingbeta.3tobeta.8in theMyApp.csproj. Does not repro withbeta.7.iSazonov commentedon Oct 11, 2017
If it's a regression, it's my only thought that we need a CI test or we should manually test this before we release the new Beta version.
iSazonov commentedon Oct 11, 2017
I remember only one related PR in last time #4196 - Mark Kraus (@markekraus) if you have time you can revert locally the change and test.
daxian-dbw commentedon Oct 11, 2017
Mark Kraus (@markekraus) Sorry that I cannot reproduce the issue by following the instructions at https://github.com/PowerShell/PowerShell/tree/master/docs/host-powershell#net-core-sample-application
Can you please point me what I might be missing?
This is what I did:
markekraus commentedon Oct 11, 2017
Dongbo Wang (@daxian-dbw) That's exactly what I did. The difference may be that I have never don't the hosted app before so I was downloading the sdk nuget for the first time. did you test this in a fresh environment?
daxian-dbw commentedon Oct 11, 2017
I think I can repro it now.
MyApp.exefrom thepublishfolder works fine (i.e..\bin\release\netcoreapp2.0\win10-x64\publish\MyApp.exe), but the one fromwin10-x64is having problem (i.e..\bin\release\netcoreapp2.0\win10-x64\MyApp.exe).I'm looking into it.
markekraus commentedon Oct 11, 2017
Dongbo Wang (@daxian-dbw) fails with
dotnet runtoo.Qowy commentedon Oct 11, 2017
Thank you all for your efforts in fixing this. I just wanted to repeat I did not use a .Net core project (although we see it has been reproduced there), but a ASP.NET core one instead.
Just in case somebody also wants to try and reproduce it there (or check a potential fix).
daxian-dbw commentedon Oct 11, 2017
Yeah,
dotnet runis essentially running the exe fromwin10-x64folder.markekraus commentedon Oct 11, 2017
Qowy I originally reproduced it in an fresh MVC project. It has the same issues as the more basic MyApp. We are using the MyApp as a baseline to rule out project specific issues. In theory, if this is fixed for the MyApp, it should also work for ASP.NET Core apps.
Dongbo Wang (@daxian-dbw) thanks!!
daxian-dbw commentedon Oct 12, 2017
Just confirmed that Ilya (@iSazonov) was right, this is a regression caused by #4196 -- the passed in
filenameis just a filename without extension, soAssembly.LoadFromfails.This regression could be fixed by #4942 because that PR will change
powershell.Invoke()to not depend onRunspaceConfiguration. However, I think we need to revisit the change of #4196 to make it more reliable./cc Steve Lee (@SteveL-MSFT)
iSazonov commentedon Oct 12, 2017
I've seen the same long ago for powershell.exe - from the publish folder it works fine but from win7-x64 it is having problem (no with Beta.8). Also locally I can not get tests with Add-Type passed - ref error - path not found. I guess it can related.
SteveL-MSFT commentedon Oct 12, 2017
I reopened #3325
daxian-dbw commentedon Oct 12, 2017
Ilya (@iSazonov) Prior to adopting .NET Core 2.0, PowerShell needs to spin up a separate AssemblyLoadContext to handle assembly loading by itself, and the assembly probing path it uses is the base folder of S.M.A.dll. So at that time, it's by design that the hosting application needs to be built with
dotnet publishand run from the publish folder, where all dependent assemblies are placed.After adopting .NET Core 2.0, powershell uses the default CLR loader and there is no need for a separate load context. So it's OK to run the hosting application from outside the publish folder, or with
dotnet run.As for
Add-Type, we can possibly solve the problem if we are able to package thereffolder into the nuget package as content files.iSazonov commentedon Oct 12, 2017
Dongbo Wang (@daxian-dbw) Thanks!
chunqingchen commentedon 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.
chunqingchen commentedon 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:
Generate the nuget package locally with the code change:
$VersionSuffix = ("v6.0.0-beta.9" -split '-')[-1]
Publish-NuGetFeed -VersionSuffix $VersionSuffix
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
where C:\Github\powershellfull\p2\PowerShell\nuget-artifacts is folder where previous neget package generates.
go to ..\sample-dotnet2.0-powershell.beta.3\MyApp
dotnet restore
dotnet run
The exception is gone.