gpt4 book ai didi

c# - Azure Function 不是无状态的

转载 作者:行者123 更新时间:2023-12-04 04:18:14 26 4
gpt4 key购买 nike

我在使用反射的消费计划上有一个 .NetCore 2 Azure 函数(运行时 2),它在当前域中加载一个程序集(Assembly.LoadFrom()) 并用它做其他事情。

大多数时候该函数运行良好,但有时它会提示程序集已经加载。我虽然这不应该是可能的,因为消费计划中的功能应该无状态地运行......

我错过了什么吗?

最佳答案

是的,它是无状态的,但您的应用程序域将无限期保持加载状态,除非您卸载它。当您使用 Azure Functions v2 时,这意味着您处于 .NET Core 领域,这意味着您没有可以使用的 AppDomain。但是,您可以使用 AssemblyLoadContext .例如:

public class FooContext : AssemblyLoadContext
{
public FooContext() : base(isCollectible: true)
{
}
}

现在:

var myLoader = new FooContext();

var assembly = myLoader.LoadFromAssemblyPath("your-path");

// Now do stuff with "assembly" as you did before

最后记得清理一下:

myLoader.Unload();

关于c# - Azure Function 不是无状态的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60099893/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com