C#、Windows 服务和 Microsoft.Bcl.Async

标签 c# .net windows asynchronous service

我正在使用 Nuget 中的 Microsoft.Bcl.Async 包构建 C# Windows 服务。

一切正常,但当我尝试将它安装在机器上时(XP 或 Win7<- 仅使用 .NET 4.0),我收到 1001 错误。这是使用带有安装程序类的 InstallUtil 或 InstallShield 2013 LE。

我打开了 Fusion 日志记录,这是失败的部分:

*** Assembly Binder Log Entry  (5/1/2014 @ 1:23:13 PM) ***

The operation failed.
Bind result: hr = 0x80070002. The system cannot find the file specified.

Assembly manager loaded from:  C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable  C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: User = someuser
LOG: DisplayName = System.Threading.Tasks, Version=1.5.11.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
 (Fully-specified)
LOG: Appbase = file:///C:/WINDOWS/Microsoft.NET/Framework/v4.0.30319/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = InstallUtil.exe
Calling assembly : Microsoft.Threading.Tasks, Version=1.0.12.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a.
===
LOG: This bind starts in LoadFrom load context.
WRN: Native image will not be probed in LoadFrom context. Native image will only be probed in default load context, like with Assembly.Load().
LOG: Using application configuration file: C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe.Config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: System.Threading.Tasks, Version=1.5.11.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
LOG: The same bind was seen before, and was failed with hr = 0x80070002.
ERR: Unrecoverable error occurred during pre-download check (hr = 0x80070002).

我什至尝试过从头开始构建服务并立即安装 Microsoft.Bcl.Async 以得到相同的结果。

我没有引用不同版本的 System.Threading.Tasks。它在我的服务的 bin 目录中。我已经搜索了好几天试图弄清楚这一点,但我不知所措。

编辑:奇怪的是,我可以从我的项目中删除所有“async”和“await”关键字,现在使用任何异步扩展,如“StreamWriter.WriteLineAsync();”并在项目中保留 Microsoft.Bcl.Async 的引用,该服务将正常安装。当我尝试在我的代码中使用“async”或“await”时,我就开始遇到这些问题。

最佳答案

尝试在this bcl blog link中寻找答案 我认为此页面中的第 6 期就是您要查找的内容。

关于C#、Windows 服务和 Microsoft.Bcl.Async,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23414294/

相关文章:

c# - 以编程方式将新用户插入到 aspnet 成员资格架构中

.net - Paths/ASP.NET/Https 和/Microsoft/UserSecrets) 在 mac 上未共享

mysql - Windows非管理员环境下启动MySQL

c++ - 在 Windows : Cannot open include file: 'Magick++.h' : No such file or directory 中编译 ZBar 示例时出错

windows - 在 Windows 注册表中注册应用程序

c# - 实时优化传感器数据,通过省略条目来减少日志文件的大小

c# - 通过 cmd 行传递消息的单实例应用程序?

c# - mvc重复用户验证错误

.net - 计算包含 Visual Studio 解决方案的代码行数

.net - 为 Azure Function App 启用 VNet 集成时出现 "Http2ConnectionException: HTTP/2 error code ' PROTOCOL_ERROR ' (0x1)"错误