Aws-lambda-dotnet: [aws-lambda-dotnet] 无法加载程序集

创建于 2018-12-15  ·  6评论  ·  资料来源: aws/aws-lambda-dotnet

你好,
我在尝试运行 AWS .NET Mock Lambda 测试工具时遇到错误。
我收到无法加载程序集 NLog.AWS.Logger.dll
当我运行我的测试时,一切正常。
我试图将所有 dll 从 nuget 包复制到输出,但错误仍在继续。
错误发生在为 lambda 配置 NLog 的函数上,在它执行期间(调用本地主机上的执行函数按钮:5050)

 public virtual void Init(ILambdaContext context)
        {
            this.ConfigureNLog(context);  // <----- ERROR WHEN CALLLING
            Log = LogManager.GetCurrentClassLogger();
            InitIoC();
        }
  internal void ConfigureNLog(ILambdaContext context)
        {
            var config = new LoggingConfiguration();

            var consoleTarget = new ColoredConsoleTarget();
            config.AddTarget("console", consoleTarget);
            var jsonLayout = new JsonLayout
            {
                Attributes =
    {
                    new JsonAttribute("time", "${longdate}"),
                    new JsonAttribute("level", "${level:upperCase=true}"),
                    new JsonAttribute("message", "${message}"),
                    new JsonAttribute("type", "${exception:format=Type}"),
                    new JsonAttribute("message", "${exception:format=Message}"),
                    new JsonAttribute("stacktrace","${stacktrace:format=raw"),
                    new JsonAttribute("innerException", new JsonLayout
                    {

                        Attributes =
                        {
                            new JsonAttribute("type", "${exception:format=:innerFormat=Type:MaxInnerExceptionLevel=1:InnerExceptionSeparator=}"),
                            new JsonAttribute("message", "${exception:format=:innerFormat=Message:MaxInnerExceptionLevel=1:InnerExceptionSeparator=}"),
                        },
                          RenderEmptyObject = false
                    },

        false)
    }
            };


            var awsTarget = new AWSTarget()
            {
                LogGroup = context.LogGroupName,
                Region = context.ClientContext.Environment["AWS_DEFAULT_REGION"],
                Layout = jsonLayout
            };

            config.AddTarget("aws", awsTarget);
            config.LoggingRules.Add(new LoggingRule("*", LogLevel.Debug, consoleTarget));
            config.LoggingRules.Add(new LoggingRule("*", LogLevel.Debug, awsTarget));

            LogManager.Configuration = config;
        }
guidance

最有用的评论

嗨,大家好,
@Kralizek @normj
在花了一些时间了解问题后,我终于弄明白了。
我在 2.2 版本上有一些包,如 EF Core 和 Configurations。
共享框架 (Microsoft.NetCore.App) 是 .NEt Core 2.1,因此它从 %program files%\dotnet\shared\Microsoft.AspNetCore.App\2.1.6 加载 Dll。
此文件夹包含 EF Core 和 Configurations DLL 版本 2.1.* ,因此在我将包更改为 2.1.* 版本后它工作正常。
在使用 Microsoft.NetCore.App 2.1 时,Microsft 建议使用 2.1.*

最好的

德里奥

所有6条评论

感谢您报告问题。 您是否有机会发布您的 csproj 文件并描述您的解决方案布局?

@normj ,很抱歉耽搁了这么久。 我正在度假。
在我的 CSPROJ 下方:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netcoreapp2.2</TargetFramework>
    <GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
    <AWSProjectType>Lambda</AWSProjectType>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Amazon.Lambda.Core" Version="1.0.0" />
    <PackageReference Include="Amazon.Lambda.Serialization.Json" Version="1.4.0" />
    <PackageReference Include="AWS.Logger.NLog" Version="1.3.1" />
    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.2.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.2.0" />
    <PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="2.2.0" />
    <PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.2.0" />
    <PackageReference Include="NLog" Version="4.5.11" />
    <PackageReference Include="SimpleInjector" Version="4.4.2" />
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\App.AppService\App.AppService.csproj" />
    <ProjectReference Include="..\App.Data\App.Data.csproj" />
    <ProjectReference Include="..\App.Infra\App.Infra.csproj" />
  </ItemGroup>

  <ItemGroup>
    <None Update="appsettings.Development.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
    <None Update="appsettings.Debug.json">
      <IsTransformFile>true</IsTransformFile>
      <DependentUpon>appsettings.json</DependentUpon>
    </None>
    <None Update="appsettings.json">
      <TransformOnBuild>true</TransformOnBuild>
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
    <None Update="appsettings.Release.json">
      <IsTransformFile>true</IsTransformFile>
      <DependentUpon>appsettings.json</DependentUpon>
    </None>
    <None Update="appsettings.Test.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
  </ItemGroup>

  <ItemGroup>
    <Folder Include="Integrations\" />
  </ItemGroup>

</Project>

最好的

尝试更改您的函数以使用.netcoreapp2.1 ,因为 Lambda 不支持 .NET Core 2.2 :)

我已经将其更改为 2.1。
同样的错误继续存在。

嗨,大家好,
@Kralizek @normj
在花了一些时间了解问题后,我终于弄明白了。
我在 2.2 版本上有一些包,如 EF Core 和 Configurations。
共享框架 (Microsoft.NetCore.App) 是 .NEt Core 2.1,因此它从 %program files%\dotnet\shared\Microsoft.AspNetCore.App\2.1.6 加载 Dll。
此文件夹包含 EF Core 和 Configurations DLL 版本 2.1.* ,因此在我将包更改为 2.1.* 版本后它工作正常。
在使用 Microsoft.NetCore.App 2.1 时,Microsft 建议使用 2.1.*

最好的

德里奥

很高兴你能解决问题。

此页面是否有帮助?
0 / 5 - 0 等级