Home

Powershell .net core runspace creation error

%3CLINGO-SUB%20id%3D%22lingo-sub-696142%22%20slang%3D%22en-US%22%3EPowershell%20.net%20core%20runspace%20creation%20error%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-696142%22%20slang%3D%22en-US%22%3E%3CP%3EHello%20guys%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20am%20trying%20to%20make%20some%20remote%20requests%20to%20Exchange%20from%20a%20.NET%20core%20api%20but%20I%20am%20having%20some%20issues%20and%20I%20am%20unable%20to%20find%20a%20solution.%3C%2FP%3E%3CP%3EI%20created%20a%20singleton%20pattern%20so%20I%20can%20only%20have%20one%20powershell%20session%20per%20user%20and%20whenever%20I%20have%20to%20make%26nbsp%3B%20a%20call%20to%20exchange%20I%20retrive%20that%20session.%20The%20problem%20is%20that%20I%20get%20an%20System.IO.FileNotFoundException'%20en%20System.Management.Automation.dll%20error%20when%20I%20try%20to%20create%20the%20runspace%20and%20I%20cannot%20run%20any%20command.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20am%20hosting%20my%20api%20in%20a%20local%20IIS%20in%20Windows%2010%20and%20I%20use%20.NET%20Core%202.2.%26nbsp%3B%20If%26nbsp%3B%20i%20make%20a%20request%20direcctly%20to%20the%20IIS%20Express%2C%20when%20running%20my%20code%20in%20Visual%20Studio%2C%20I%20get%20no%20error%20but%20I%20do%20get%20the%20exception%20when%20I%20make%20the%20request%20to%20the%20IIS%20site.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIn%20the%20attach%20file%20I%20put%20the%20code%20of%20my%20singleton%20pattern%20and%20how%20I%20try%20to%20create%20the%20runspace.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20tried%20to%20create%20the%20runspace%20locally%20and%20connect%20to%20Exchange%20but%20I%20also%20tried%20to%20connect%20remotelly%20and%20save%20that%20configuration%20so%20I%20would%20only%20have%20to%20import%20the%20session.%3C%2FP%3E%3CP%3EWe%20also%20tried%20to%20update%20the%20.net%20core%20to%203%20version%20but%20we%20had%20no%20luck.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAny%20help%20will%20be%20appreciated!!!%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThank%20you!!!%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-696142%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3E.Net%20Core%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EWindows%20PowerShell%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-698952%22%20slang%3D%22en-US%22%3ERe%3A%20Powershell%20.net%20core%20runspace%20creation%20error%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-698952%22%20slang%3D%22en-US%22%3E%3CP%3EI%20found%20the%20solution%20for%20my%20problem.%20When%20I%20created%20the%20api%20I%20downloaded%20the%20powershell%20sdk%20with%20nuget%20but%20when%20I%20published%20it%20with%20that%20SDK%2C%20IIS%20could%20not%20access%20the%20dependecies%20needed.%20So%20I%20uninstalled%20the%20SDK%20and%20instead%20I%20installed%20powershell%206%20on%20my%20PC%20and%20linked%20the%20dependencies%20in%20the%20assembly%20and%20it%20worked!!%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
byaby93
New Contributor

Hello guys,

 

I am trying to make some remote requests to Exchange from a .NET core api but I am having some issues and I am unable to find a solution.

I created a singleton pattern so I can only have one powershell session per user and whenever I have to make  a call to exchange I retrive that session. The problem is that I get an System.IO.FileNotFoundException' en System.Management.Automation.dll error when I try to create the runspace and I cannot run any command.

 

I am hosting my api in a local IIS in Windows 10 and I use .NET Core 2.2.  If  i make a request direcctly to the IIS Express, when running my code in Visual Studio, I get no error but I do get the exception when I make the request to the IIS site.

 

In the attach file I put the code of my singleton pattern and how I try to create the runspace.

 

I tried to create the runspace locally and connect to Exchange but I also tried to connect remotelly and save that configuration so I would only have to import the session.

We also tried to update the .net core to 3 version but we had no luck.

 

Any help will be appreciated!!!

 

Thank you!!!

 

1 Reply

I found the solution for my problem. When I created the api I downloaded the powershell sdk with nuget but when I published it with that SDK, IIS could not access the dependecies needed. So I uninstalled the SDK and instead I installed powershell 6 on my PC and linked the dependencies in the assembly and it worked!!