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.
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!!