Skip to main content
 首页 » 编程设计

c#之带有 Async/Await 关键字的 WebRole 未在 Azure 上运行

2024年01月28日30qlqwjy

我正在使用以下代码从 http 请求中读取文件。

var streamProvider = new MultipartMemoryStreamProvider(); 
streamProvider = await Request.Content.ReadAsMultipartAsync(streamProvider);    

我正在使用 .net 4.0。因此,对于 async/await 关键字,我已经安装了 Microsoft.Bcl.Async NuGet 包。这在我的本地机器上运行良好.但是当我尝试将包上传到azure时,webrole无法运行。

请您参考如下方法:

对不起,这行不通。您不能在 ASP.NET(包括 Web 角色)上使用 Microsoft.Bcl.Async 包。这是因为 ASP.NET needed some rewriting of some core types in order to support async/await ,而您无法通过 NuGet 包获得此功能。

在 ASP.NET 上,您必须以 .NET 4.5 为目标才能使用 async/await。