c# - 在 azure 函数的新应用程序域中创建对象的实例会引发 FileNotFoundException
问题描述
我需要在新的应用程序域中运行一些代码。所以我试图在新的应用程序域中创建我的对象的一个实例......这是我正在使用的代码:
public static class Program
{
private static ITemplateEngineProvider _templateEngineProvider;
static Program()
{
AppDomain ad = AppDomain.CreateDomain("New domain");
ObjectHandle handle = ad.CreateInstance(
assemblyName: typeof(RazorTemplateEngineProvider).Assembly.FullName,
typeName: "RazorTemplateEngineProvider"
//ignoreCase: false,
//bindingAttr: BindingFlags.CreateInstance,
//binder: null,
//args: new object[] { new string[] { templatePath, layoutPath } },
//culture: CultureInfo.InvariantCulture,
//activationAttributes: null
);
_templateEngineProvider = (RazorTemplateEngineProvider)handle.Unwrap();
}
}
RazorTemplateEngineProvider
是具有公共构造函数的自定义公共类。MyCustomLib.dll
它已在我在 azure 函数中引用的类库 () 中实现。该类实现了在另一个类库 ( IMyCustomLib.dll
) 中定义的接口,该接口仅由前一个类库引用,而不是由 azure 函数引用。
目前RazorTemplateEngineProvider
类内没有代码:
public class RazorTemplateEngineProvider : MarshalByRefObject, ITemplateEngineProvider
{
public RazorTemplateEngineProvider()
{ }
}
当我尝试做ad.CreateInstance
一个FileNotFoundException
已经抛出:
无法加载文件或程序集“MyCustomLib.dll,Version=1.0.0.0,Culture=neutral,PublicKeyToken=...”或其依赖项之一。该系统找不到指定的文件。
但是该文件存在并且它应该已经正确加载......事实上,如果我运行这个“查询”
IEnumerable<string> loadedAssemblies = AppDomain.CurrentDomain.GetAssemblies()
.Where(a => !a.IsDynamic && !a.FullName.Contains("Version=0.0.0.0") && File.Exists(a.Location) && !a.Location.Contains("CompiledRazorTemplates.Dynamic") && a.FullName.Contains("My"))
.Select(f => f.FullName)
.ToArray();
我看到我的两个dll。那么,为什么我会收到这个错误?
谢谢
更新
我认为问题是天蓝色的,因为我在控制台应用程序中复制并粘贴了我的代码并且它可以工作。
更新
我正在观看 fusionlong,它似乎正在尝试从“错误”路径加载程序集:file:///C:/Users/csimb/AppData/Local/Azure.Functions.Cli/1.0.12/MyCustomLib.dll
.. 我预计路径是 bin 文件夹...
解决方案
推荐阅读
- unicode - 如何确定 Grapheme Cluster 是否按字母顺序排列?
- python - 在不计算整个句子的情况下估计给定句子的标记概率/logits
- reactjs - 当前未启用对实验性“jsx”的支持
- php - Laravel 7 会话中断在不同域中的 IFRAME
- css - 在 R pagedown 包中编辑边距框大小
- amazon-web-services - 在每个 EC2 实例 [应用架构] 中缩放 AWS 弹性 beantalk 中的 docker 容器数量
- python - 如果我在具有 1 个线程的 vps 服务器上运行 2 个线程的应用程序会发生什么?
- python - Python如何使用__wrapped__键入提示Callable
- javascript - 猫鼬 Model.save() 只返回 { _id, __v }
- javascript - 不知道如何异步这个