我正在构建通过关系数据库中的MySql访问数据的lambda微服务。我的本地单元测试运行良好,但当我发布到AWS时,我得到以下错误:
{
"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
}这是我的project.json文件。我尝试将System.Diagnostics.TraceSource库添加为标准项目依赖项(未显示)和框架依赖项(如下所示)。我的想法是,可能在发布期间,它没有添加程序集,因为我没有在代码中直接使用TraceSource。然而,两次尝试都没有解决问题:
{
"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"
]
}
}
}有什么想法吗?
发布于 2018-01-30 22:37:01
在运行以下命令后,我也遇到了同样的问题。
dotnet publish src\Lambda.csproj -c Release
起初,我按照Jon Peterson的建议,通过从runtimes\unix\lib\netstandard1.3复制文件来修复它。
我找到了一个看起来更干净的解决方案。现在,我只运行以下命令。
dotnet publish src\Lambda.csproj -c Release -r linux
这将创建一个包含所有正确文件的发布文件夹。
https://stackoverflow.com/questions/41794621
复制相似问题