添加异步时无法找到System.Runtime

问题描述 投票:1回答:1

我正在制作Azure功能,我需要它来做一些异步工作。但我得到这个奇怪的错误,一旦我调用一个等待的方法,它无法加载程序集System.Runtime

[FunctionName("MyTestFunction")]
async public static void Run(
    [ServiceBusTrigger("testtopic", "testsubscription", AccessRights.Listen, Connection = "MyServiceBusConnection")]
    string mySbMsg,
    TraceWriter log)
{
    client = new DocumentClient(new System.Uri(ENDPOINT), ENDPOINT_KEY);
    await client.CreateDocumentAsync(UriFactory.CreateDocumentCollectionUri(DATABASE, COLLECTION_ID), string.Format("{ \"newmessage\": {0} }", mySbMsg));

    log.Info($"C# ServiceBus topic trigger function processed message: {mySbMsg}");
}

我在这里错过了什么?

c# asynchronous azure-functions
1个回答
1
投票

这个问题有一个解决方法 - 请看看这个example

使用Azure功能内置功能似乎更容易,并且不需要您等待任何事情,这可能会解决您的问题。

此外,DocumentClient类旨在实例化一次,并在应用程序的整个生命周期中重用。请看看这篇文章 - Improper Instantiation antipattern

© www.soinside.com 2019 - 2024. All rights reserved.