【问题标题】:Load assembly from binary array in Amazon lambda function by using reflection使用反射从 Amazon lambda 函数中的二进制数组加载程序集
【发布时间】:2021-11-04 19:37:51
【问题描述】:

在我的 C# aws lambda 函数中,我使用带有二进制数组的 Assembly.Load()。我执行以下操作:

//
// "item" is an object that has the property "DotNetAssembly" with
// the binary array that has the assembly that I need to load
//
// this works perfectly!
var assembly = AppDomain.CurrentDomain.Load(item.DotNetAssembly)

现在我从“程序集”变量创建一个实例:

//
// "item" is an object that has a property "DotNetType"
// with the name of the class that I need to instance
//
// this works perfectly!
var obj = assembly.CreateInstance(item.DotNetType);

但是现在,当我尝试从“obj”变量中调用方法“ABC”时

//
// this doesn't work!
obj.ABC();

我收到以下错误: System.MissingMethodException:找不到方法“AmazonDynamoDBClient”

“obj.ABC()”方法正在使用“AmazonDynamoDBClient”的一个实例,因此很明显 dotnet 无法解析这种依赖关系。

我找到了这篇微软的文章: https://docs.microsoft.com/en-us/dotnet/framework/deployment/best-practices-for-assembly-loading 但我不清楚使用 Assembly.Load(binary_array) 时如何解决依赖关系

如何解决变量“obj”或其类所需的依赖关系?

【问题讨论】:

    标签: c# reflection aws-lambda


    【解决方案1】:

    我找到了一些可以帮助你的信息

    ** https://docs.microsoft.com/en-us/dotnet/api/system.reflection.assembly.load?view=net-5.0

    public static System.Reflection.Assembly Load (byte[] rawAssembly);

    【讨论】:

    • 请在您的回答中提供更多详细信息。正如目前所写的那样,很难理解您的解决方案。
    猜你喜欢
    • 2017-04-19
    • 1970-01-01
    • 2013-03-09
    • 1970-01-01
    • 1970-01-01
    • 2016-02-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多