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?