简体   繁体   English

C#:。Net:用于控制台应用程序的代码。 在WCF服务上运行时,相同的代码失败

[英]C# : .Net : Code working on Console application . Same code is failing when running on WCF service

I have an application which is using a module A(.net assembly) and module A uses module B(.net assembly) and module B uses module C(C++). 我有一个使用模块A(.net程序集)的应用程序,模块A使用模块B(.net程序集),模块B使用模块C(C ++)。

Since many applications in the server use this, i have registered the managed modules to registry and installed them in GAC. 由于服务器中的许多应用程序都使用此功能,因此我已将托管模块注册到注册表并将其安装在GAC中。

Now i am accessing module A(which does all the job) by below code : 现在我通过以下代码访问模块A(完成所有工作):

Type moduleAType = Type.GetTypeFromProgID("ModuleA.Class1"); 输入moduleAType = Type.GetTypeFromProgID(“ModuleA.Class1”); object class1Object = Activator.CreateInstance(moduleAType); object class1Object = Activator.CreateInstance(moduleAType);

The above two lines of Code works fine when running as console application. 上面两行代码在作为控制台应用程序运行时工作正常。 But the same code throws an error when i deploy it as WCF service and make a request : 但是,当我将其部署为WCF服务并发出请求时,相同的代码会引发错误:

"Could not load the assembly ModuleB or one of its dependencies". “无法加载程序集ModuleB或其依赖项之一”。

To try fix the above error in WCF service , i copied all the dlls ModuleA , ModuleB and ModuleC to the bin of my service installation folder and now i get the same above error while browsing the service. 为了在WCF服务中尝试修复上述错误,我将所有dll ModuleA,ModuleB和ModuleC复制到我的服务安装文件夹的bin中,现在我在浏览服务时遇到了同样的错误。 I guess some system modules are not being picked up when running as WCF service. 我想有些系统模块在作为WCF服务运行时没有被选中。

I tried using ProcMon to see where Asp.Net is picking up the dlls from , but i was not able to figure it out. 我尝试使用ProcMon来查看Asp.Net从哪里拿起dll,但我无法弄明白。 Any suggestions / help would be very helpfull 任何建议/帮助都会非常有帮助

Note : Both Console App and WCF service run under same user in the same machine. 注意:Console App和WCF服务在同一台计算机上的同一用户下运行。

I somehow made this work for me. 我以某种方式为我做了这项工作。 Hope it helps others by sharing it. 希望通过分享来帮助他人。

I did some logging and found that the running directory of my service is c:\\windows\\system32\\inetsrv and in dependency walker i found most of the dlls(system specific) that my ModuleB depends are in c:\\windows\\system32. 我做了一些日志记录,发现我的服务的运行目录是c:\\ windows \\ system32 \\ inetsrv,在依赖walker中,我发现我的ModuleB所依赖的大多数dll(系统特定的)都在c:\\ windows \\ system32中。

So i created a shortcut to system32(c:\\windows\\system32) folder inside inetsrv(c:\\windows\\system32\\inetsrv) and it started working for me. 所以我在inetsrv(c:\\ windows \\ system32 \\ inetsrv)中创建了system32(c:\\ windows \\ system32)文件夹的快捷方式,它开始为我工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 运行批处理文件的C#代码在控制台应用程序中工作,但相同的代码在WCF服务中不起作用 - C# code to run a batch file works in console application, but same code doesnt work in WCF Service C#WCF HTTP服务控制台应用程序在辅助系统上不起作用 - C# WCF HTTP Service Console Application Not Working on Secondary System 从Windows服务和控制台应用程序访问相同的运行代码? - Access the same running code from a Windows Service and a console application? 代码在控制台应用程序中有效,但在Windows Service中运行时不起作用 - Code works in a console application, but does not work when running in windows service 运行 C# 控制台应用程序作为 Windows 服务 - Running a C# console application as a Windows service C# WCF 服务获取状态码 - C# WCF Service Get Status Code C#-WCF客户端/服务器在服务应用程序上打开控制台 - C# - WCF Client/Server Open a Console on Service Application 重新启动由C#控制台应用程序托管的WCF服务 - Restart a WCF service hosted by a C# console application Windows 服务给出的字符串未被识别为有效的 DateTime 异常,但相同的代码在控制台应用程序中正常运行 - Windows Service gives String was not recognized as a valid DateTime exception but the same code running properly in Console Application Visual Studio Code - C# 控制台应用程序 - Visual Studio Code - C# Console Application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM