【发布时间】:2017-06-07 06:29:35
【问题描述】:
我正在构建通过 RDS 中的 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"
]
}
}
}
有什么想法吗?
【问题讨论】:
-
您最终找到了答案吗?我正在做同样的事情,除了我将 ef core 与 mysql 的 sapientguardian nuget 包一起使用。
-
刚刚找到解决类似问题的方法。我要做的是
dotnet publish,然后将 dll 从 \publish\runtimes\unix\lib\netstandard1.3 子文件夹复制到发布文件夹。压缩发布文件夹的内容(不包括运行时文件夹)并将其上传到 lambda。让我知道它是否适合您@xeon 和@SnOrfus -
@JonPeterson 如果您想将其发布为答案,我会投赞成票。它对我有用。我曾尝试将程序集复制到发布文件夹中,然后使用 Visual Studio 中的发布(认为它会拾取复制的程序集),但这不起作用。所以我走在了正确的轨道上。感谢您的提示!
标签: c# mysql amazon-web-services .net-core aws-lambda