2013-02-19 3 views
0
  1. 타사 응용 프로그램이 C# 내에서 실행될 때보 다 명령 셸 내에서 실행되면 다른 방식으로 동작하는 이유는 무엇입니까? System.Diagnostics.Process.Start("ThirdPartyApp.exe");을 사용하는 응용 프로그램?.NET 4.0 응용 프로그램은 다른 .NET 4.0 (C#) 응용 프로그램에서 시작될 때 ApplicationException을 throw합니다.

  2. C#에서 응용 프로그램을 시작하여 명령 셸에서 실행될 때와 같이 정확히처럼 실행되는 방법이 있습니까?

상세 사항 : 나는 제 3 자 .NET 4.0 응용 프로그램 (소스 코드는 제공되지 않는)를 설치하고 내 PC에서 실행해야합니다. IIS에서 실행되는 웹 서비스와 함께 제공됩니다. SOAP 메시지를 사용하여 이러한 웹 서비스를 호출하는 C# 응용 프로그램을 작성했습니다. (두 응용 프로그램은 동일한 PC에 설치되어 실행됩니다.) 내 응용 프로그램을 실행하기 전에 타사 응용 프로그램이 실행 중이면 문제없이이 프로그램과 통신 할 수 있습니다. 타사 앱이 내 앱을 실행하기 전에 실행 중이 아니면 시작할 수 있기를 원합니다. SomeWebService에 통화

using (var soapClient = new ThirdPartyAppSoapClient()) 
{ 
    soapClient.SomeWebService(); 
} 

, 제 3 자 응용 프로그램은 다음과 같은 예외를 throw : 다음 내 SOAP 클라이언트를 통해 웹 서비스에 액세스하려고하면

if (!System.Diagnostics.Process.GetProcesses().Select(rec => rec.ProcessName).Contains("ThirdPartyApp")) 
{ 
    System.Diagnostics.Process.Start("ThirdPartyApp.exe"); 
} 

: 나는 다음과 같은 코드를 시도 :

2013-02-18 19:43:33,884 [17] ERROR ThirdPartyApp.Manager Error Exception Caught 
System.IO.FileNotFoundException: Could not load file or assembly 'file:///C:\Pro 
gram Files (x86)\Common Files\Microsoft Shared\DevServer\10.0\ThirdPartyDependen 
cy.dll' or one of its dependencies. The system cannot find the file specified. 
File name: 'file:///C:\Program Files (x86)\Common Files\Microsoft Shared\DevServ 
er\10.0\ThirdPartyDependency.dll' 
    at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String cod 
eBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& 
stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppre 
ssSecurityChecks) 
    at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName as 
semblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntr 
ospection, Boolean suppressSecurityChecks) 
    at System.Reflection.RuntimeAssembly.InternalLoadFrom(String assemblyFile, Ev 
idence securityEvidence, Byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm, 
Boolean forIntrospection, Boolean suppressSecurityChecks, StackCrawlMark& stackM 
ark) 
    at System.Reflection.Assembly.LoadFrom(String assemblyFile) 
    at ... 

WRN: Assembly binding logging is turned OFF. 
To enable assembly bind failure logging, set the registry value [HKLM\Software\M 
icrosoft\Fusion!EnableLog] (DWORD) to 1. 
Note: There is some performance penalty associated with assembly bind failure lo 
gging. 
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fus 
ion!EnableLog]. 


Unhandled Exception: System.ApplicationException: Object synchronization method 
was called from an unsynchronized block of code. 
    at System.Threading.Mutex.ReleaseMutex() 
    at ... 
    at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, C 
ontextCallback callback, Object state, Boolean ignoreSyncCtx) 
    at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, C 
ontextCallback callback, Object state) 
    at System.Threading.ThreadHelper.ThreadStart() 

나는 내 응용 프로그램을 시작하기 전에 제 3 자 응용 프로그램이 이미 실행중인 경우 잘 SomeWebService를 호출 할 수 있어요, 그래서 그것을 열심히 속인다 찾을 누락 된 종속성이 있습니다. 하지만이 서드 파티 앱을 유머러스하게 만들기 위해 누락 된 파일을 지정된 폴더에 복사하여 문제가 해결되는지 확인했습니다. 종속성에 대한 첫 번째 오류 메시지가 InvalidCastException로 변경되지만 두 번째 오류 메시지 (System.ApplicationException: Object synchronization method was called from an unsynchronized block of code.)는 계속 나타나며 변경되지 않습니다.

내가 잘못하고있는 것을 이해하는 데 도움이되는 어떤 도움과이 타사 앱이 C# 응용 프로그램 외부에서 실행되는지 여부에 관계없이 동일한 동작을 수행하는 방법에 대해 큰 도움이 될 것입니다.

답변

2

응용 프로그램이 실행되는 사용자 컨텍스트와 관련이있을 수 있습니다. 예를 들어 관리자로 응용 프로그램을 실행하는 경우 Process.Start은 동일한 컨텍스트에서 프로세스를 시작하려고 시도합니다.

InvalidCastException

+0

귀하는 정확합니다. 필자의 제 3 자 앱은 시작될 때 작업 디렉토리가 무엇인지에 크게 의존합니다. ProcessStartInfo에서이 매개 변수를 설정하면 문제가 해결됩니다. 감사! –

+0

신난다, 기꺼이 도와주세요! :) – animaonline

관련 문제