Oi,
Estou enfrentando um erro ao tentar executar a AWS .NET Mock Lambda Test Tool.
Estou recebendo Não foi possível carregar o Assembly NLog.AWS.Logger.dll
Quando executo meus testes tudo funciona bem.
Eu tentei copiar todas as dlls dos pacotes nuget para a saída, mas o erro continua.
O erro ocorre na função que configura o NLog para lambda, durante sua execução (Botão de função de execução de chamada em localhost: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;
}
Obrigado por relatar o problema. Alguma chance de você postar seu arquivo csproj e descrever o layout da sua solução?
Oi @normj , desculpe a demora. Eu estava de férias.
Abaixo meu 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>
Melhor
Tente alterar sua função para usar .netcoreapp2.1
, pois o .NET Core 2.2 não é suportado pelo Lambda :)
Já mudei para 2.1.
O mesmo erro continua.
Oi pessoal,
@Kralizek @normj
Depois de passar algum tempo para entender o problema, finalmente descobri.
Eu tinha alguns pacotes como EF Core e Configurations na versão 2.2.
A estrutura compartilhada (Microsoft.NetCore.App) é .NEt Core 2.1, portanto, carrega Dlls de %program files%\dotnet\shared\Microsoft.AspNetCore.App\2.1.6.
Esta pasta contém EF Core e DLLs de Configurações versão 2.1.* , portanto, depois de alterar meus pacotes para a versão 2.1.*, funcionou bem.
A Microsft recomenda exatamente isso, use 2.1.*, ao usar o Microsoft.NetCore.App 2.1
Melhor
Delio
Que bom que você conseguiu resolver o problema.
Comentários muito úteis
Oi pessoal,
@Kralizek @normj
Depois de passar algum tempo para entender o problema, finalmente descobri.
Eu tinha alguns pacotes como EF Core e Configurations na versão 2.2.
A estrutura compartilhada (Microsoft.NetCore.App) é .NEt Core 2.1, portanto, carrega Dlls de %program files%\dotnet\shared\Microsoft.AspNetCore.App\2.1.6.
Esta pasta contém EF Core e DLLs de Configurações versão 2.1.* , portanto, depois de alterar meus pacotes para a versão 2.1.*, funcionou bem.
A Microsft recomenda exatamente isso, use 2.1.*, ao usar o Microsoft.NetCore.App 2.1
Melhor
Delio