AWS Lambda, .Net Core, and MySql: Failed to load file or assembly. System.Diagnostics.TraceSource, Version = 4.0.0.0

I create lambda microservices that access data through MySql in RDS. My local unit tests work fine, but when I publish AWS, I get the following error:

    {
  "TypeName": "MySql.Data.MySqlClient.MySqlTrace",
  "Message": "The type initializer for 'MySql.Data.MySqlClient.MySqlTrace' threw an exception.",
  "Data": {},
  "InnerException": {
    "Message": "Could not load file or assembly 'System.Diagnostics.TraceSource, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.\n",
    "FileName": "System.Diagnostics.TraceSource, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a",
    "Data": {},
    "InnerException": {
      "Message": "'System.Diagnostics.TraceSource, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' not found in the deployment package or in the installed Microsoft.NETCore.App.",
      "FileName": null,
      "Data": {},
      "InnerException": null,
      "StackTrace": "   at AWSLambda.Internal.Bootstrap.LambdaAssemblyLoadContext.Load(AssemblyName assemblyName)\n   at System.Runtime.Loader.AssemblyLoadContext.ResolveUsingLoad(AssemblyName assemblyName)\n   at System.Runtime.Loader.AssemblyLoadContext.Resolve(IntPtr gchManagedAssemblyLoadContext, AssemblyName assemblyName)",
      "HelpLink": null,
      "Source": "Bootstrap",
      "HResult": -2147024894
    },
    "StackTrace": null,
    "HelpLink": null,
    "Source": null,
    "HResult": -2147024894
  },
  "StackTrace": "   at MySql.Data.MySqlClient.MySqlTrace.LogError(Int32 id, String msg)\n   at MySql.Data.MySqlClient.MySqlPool.TryToGetDriver()\n   at MySql.Data.MySqlClient.MySqlPool.GetConnection()\n   at MySql.Data.MySqlClient.MySqlConnection.Open()\n   at HealthStats.Functions.GetLocationTypes(APIGatewayProxyRequest request, ILambdaContext context)",
  "HelpLink": null,
  "Source": "MySql.Data",
  "HResult": -2146233036
}

Here is my project.json file. I tried to add the library System.Diagnostics.TraceSourceas a standard project dependency (not shown) and as a structure dependency (shown below). My thinking, perhaps at the time of publication, was that it did not add the assembly because I did not use TraceSource directly in my code. However, not a single attempt resolved the problem:

{
  "version": "1.0.0-*",
  "buildOptions": {
    "emitEntryPoint": false
  },

  "dependencies": {
    "Amazon.Lambda.APIGatewayEvents": "1.0.1",
    "Amazon.Lambda.Core": "1.0.0",
    "Amazon.Lambda.Serialization.Json": "1.0.1",
    "Amazon.Lambda.Tools": {
      "type": "build",
      "version": "1.1.0-preview1"
    },
    "Microsoft.NETCore.App": {
      "type": "platform",
      "version": "1.0.0"
    },
    "MySql.Data": "7.0.6-IR31"
  },

  "tools": {
    "Amazon.Lambda.Tools" : "1.1.0-preview1"
  },

  "frameworks": {
    "netcoreapp1.0": {
      "dependencies": {
        "System.Diagnostics.TraceSource": "4.0.0"
      },
      "imports": [
        "dnxcore50",
        "portable-net45+win8"
      ]
    }
  }
}

Any ideas?

+4
4

:

'MySql.Data.MySqlClient.MySqlTrace' .: TypeInitializationException MySql.Data.MySqlClient.MySqlTrace.LogError(Int32 id, String msg) MySql.Data.MySqlClient.MySqlPool.TryToGetDriver() MySql.Data.MySqlClient.MySqlPool.GetConnection() MySql.Data.MySqlClient.MySqlConnection.Open() AWSLambda2.Function.FunctionHandler( SNSEvent, ILambdaContext) lambda_method (Closure, Stream, Stream, ContextInfo)

'System.Diagnostics.TraceSource, Version = 4.0.0.0, Culture = neutral, PublicKeyToken = b03f5f7f11d50a3a' Microsoft.NETCore.App.: FileNotFoundException AWSLambda.Internal.Bootstrap.LambdaAssemblyLoadContext.Load(AssemblyName assemblyName) System.Runtime.Loader.AssemblyLoadContext.ResolveUsingLoad(AssemblyName assemblyName) System.Runtime.Loader.AssemblyLoadContext.Resolve(IntPtr gchManagedAssemblyLoadContext, AssemblyName assemblyName)

, , dotnet publish, , .\publish\runtimes\unix\lib\netstandard1.3 DLL, , .\publish. , , , .

, , , dotnet publish , , , , .

+4

- project.json.

"scripts": {    "prepublish": [ "xcopy./bin/Release/netcoreapp1.0/publish/runtimes/unix/libnetstandard1.3/System.Diagnostics.TraceSource.dll./bin/Release/" ],    "postpublish": [ "dotnet publish-iis --publish-folder% publish: OutputPath% --framework% publish: FullTargetFramework%" ] } , AWS .

0

@alduar, , postpublish, dll . , . : .

    "scripts": {
       "postpublish": [ "xcopy bin\\Release\\netcoreapp1.0\\publish\\runtimes\\unix\\lib\\netstandard1.3\\System.Diagnostics.TraceSource.dll bin\\Release\\netcoreapp1.0\\publish\\" ]
    },
0

.

dotnet publish src\Lambda.csproj -c Release

, runtimes\unix\lib\netstandard1.3, .

, , . .

dotnet publish src\Lambda.csproj -c Release -r linux

, .

0

Source: https://habr.com/ru/post/1667496/


All Articles