1
나가는 큐에있는 메시지 수를 가져 오려고합니다. 나는 이것을 달성하기 위해 Powershell과 C#을 사용하고있다. 나는 명령MSMQ에서 메시지 수 얻기 아웃 큐
Get-MsmqOutgoingQueue | Format-Table -Property MessageCount
이 명령은 PowerShell을 명령 프롬프트에서 성공적으로 실행지고 아래로 사용하고 있습니다.
string scriptTest = "Get-MsmqOutgoingQueue | Format-Table -Property MessageCount";
Runspace runspace = RunspaceFactory.CreateRunspace();
runspace.Open();
Pipeline pipeline = runspace.CreatePipeline();
pipeline.Commands.AddScript(scriptText);
pipeline.Commands.Add("Out-String");
Collection<PSObject> results = pipeline.Invoke();
runspace.Close();
string s = "";
foreach (PSObject obj in results)
{
s = obj.ToString();
}
Console.WriteLine(s);
나는 모든함으로써이 코드를 시도 : 아래
The type initializer for 'Microsoft.Msmq.PowerShell.Commands.Utilities' threw an exception.
내가이 명령을 실행하는 데 사용하고 C# 코드입니다 : 나는 C#을에서이 작업을 할 때, 그것은 다음과 같은 예외를주고있다 허가하지만 동일한 예외가 발생합니다.
InnerException이 있습니까? – stuartd
InnerException을 확인하고 예외를 발견했습니다 : "런타임의 버전 'v2.0.50727'에 대해 혼합 모드 어셈블리가 작성되었으며 추가 구성 정보없이 4.0 런타임에로드 할 수 없습니다."App.Config를 수정하여 문제를 해결했습니다. – Brijesh