Hi,
I am experiencing an error when I try to run AWS .NET Mock Lambda Test Tool.
I am getting Could not load Assembly NLog.AWS.Logger.dll
When I run my tests all works OK.
I have tried to copy all dlls from nuget packages to output but the error continues.
The error occurs at the function that configures NLog for lambda, during it execution (Call execute function button on 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;
}
Thanks for reporting the issue. Any chance you could post your csproj file and describe your solution layout?
Hi @normj , sorry for long delay. I was on vacation.
Below my 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>
Best
Try changing your function to use .netcoreapp2.1
as .NET Core 2.2 is not supported by Lambda :)
I've already changed it to 2.1.
The same error continues.
Hi Guys,
@Kralizek @normj
After spent some time to understand the problem, I finally figured it out.
I had some packages like EF Core and Configurations on 2.2 version.
The shared framework (Microsoft.NetCore.App) is .NEt Core 2.1 so, it loads Dlls from %program files%\dotnet\shared\Microsoft.AspNetCore.App\2.1.6.
This folder contains EF Core and Configurations DLLs version 2.1.* , so after I have changed my packages to 2.1.* version it worked fine.
Microsft recomend exactly this, use 2.1.*, when using Microsoft.NetCore.App 2.1
Best
Delio
Glad you were able solve the problem.
Most helpful comment
Hi Guys,
@Kralizek @normj
After spent some time to understand the problem, I finally figured it out.
I had some packages like EF Core and Configurations on 2.2 version.
The shared framework (Microsoft.NetCore.App) is .NEt Core 2.1 so, it loads Dlls from %program files%\dotnet\shared\Microsoft.AspNetCore.App\2.1.6.
This folder contains EF Core and Configurations DLLs version 2.1.* , so after I have changed my packages to 2.1.* version it worked fine.
Microsft recomend exactly this, use 2.1.*, when using Microsoft.NetCore.App 2.1
Best
Delio