Я добавил в ссылку на dll Powershell (C: \ Program Files (x86) \ Reference Assemblies \ Microsoft \ WindowsPowerShell \ 3.0 \ System.Management.Automation.dll); Я также удалил эту ссылку и открыл файл проекта и добавлен в <Reference Include="System.Management.Automation />
. Тем не менее, ни одна из этих работ, я всегда получаю следующее сообщение об ошибке:Невозможно выполнить Powershell из приложения C#
Could not load file or assembly 'System.Management.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. Strong name validation failed. (Exception from HRESULT: 0x8013141A)
Вот мой код:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Management.Automation;
using System.Management.Automation.Runspaces;
namespace Powershell_Execution
{
class Program
{
static void Main(string[] args)
{
foreach (String str in PowerShell.Create().AddScript("Get-Process").AddCommand("Out-String").Invoke<String>())
{
Console.WriteLine(str);
}
Console.ReadLine();
}
}
}
Любые идеи? Все, с чем я столкнулся, просто сказал, что добавляет <Reference Include="System.Management.Automation />
, но это просто создает ту же ошибку времени выполнения.
возможно дубликат [Strong Name Validation Failed] (http://stackoverflow.com/questions/403731/strong-name-validation-failed) – OldProgrammer
Try с помощью инструмента Fuslogvw.exe для просмотра сообщений об ошибках, связанных с ошибкой, может быть связано с несовместимым ключом: http: //msdn.microsoft.com/en-us/library/e74a18c4%28v=vs.110%29.aspx –
@LeslieDavies, если только Я неправильно интерпретирую как использовать fuslogvw, ничего не появляется в журналах приложений, когда я запускаю fuslogvw. –