-
为什么第三方应用程序从命令shell中启动时的行为与使用
System.Diagnostics.Process.Start("ThirdPartyApp.exe");
?
-
有没有一种方法可以在C#中启动应用程序,使其正常运行
确切地
就像从命令shell启动一样?
细节:
我的电脑上安装并运行了第三方.NET 4.0应用程序(没有可用的源代码)。它附带了在IIS中运行的web服务。我已经编写了一个C#应用程序,它使用SOAP消息来调用这些web服务。(两个应用程序都安装在同一台电脑上并运行。)如果第三方应用程序在启动我的应用程序之前正在运行,我可以毫无问题地与它通信。如果第三方应用程序在启动我的应用程序之前没有运行,我希望能够启动它。我尝试了以下代码:
if (!System.Diagnostics.Process.GetProcesses().Select(rec => rec.ProcessName).Contains("ThirdPartyApp"))
{
System.Diagnostics.Process.Start("ThirdPartyApp.exe");
}
如果我尝试通过SOAP客户端访问web服务:
using (var soapClient = new ThirdPartyAppSoapClient())
{
soapClient.SomeWebService();
}
在呼叫时
SomeWebService
,第三方应用程序引发以下异常:
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()
我可以打电话
SomeWebService公司
如果在我启动应用程序之前第三方应用程序已经在运行,那就好了,所以我很难相信会有缺失的依赖项;但为了幽默这个第三方应用程序,我将丢失的文件复制到指定的文件夹中,看看这是否能解决问题。关于缺少依赖项的第一条错误消息随后更改为InvalidCastException,但第二条错误消息(
System.ApplicationException: Object synchronization method was called from an unsynchronized block of code.
)仍然出现并且保持不变。
如果能帮助我理解我做错了什么,以及我如何让这个第三方应用程序表现得一样,无论它是从C#应用程序内部还是外部启动的,我们将不胜感激!