我正在构建通过 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"
]
}
}
}
有什么想法吗?
最佳答案
我在 lambda 结果中看到了类似的问题:
The type initializer for 'MySql.Data.MySqlClient.MySqlTrace' threw an exception.: TypeInitializationException at MySql.Data.MySqlClient.MySqlTrace.LogError(Int32 id, String msg) at MySql.Data.MySqlClient.MySqlPool.TryToGetDriver() at MySql.Data.MySqlClient.MySqlPool.GetConnection() at MySql.Data.MySqlClient.MySqlConnection.Open() at AWSLambda2.Function.FunctionHandler(SNSEvent input, ILambdaContext context) at lambda_method(Closure , Stream , Stream , ContextInfo )
'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.: FileNotFoundException at AWSLambda.Internal.Bootstrap.LambdaAssemblyLoadContext.Load(AssemblyName assemblyName) at System.Runtime.Loader.AssemblyLoadContext.ResolveUsingLoad(AssemblyName assemblyName) at System.Runtime.Loader.AssemblyLoadContext.Resolve(IntPtr gchManagedAssemblyLoadContext, AssemblyName assemblyName)
对我有用的是使用 dotnet publish 手动发布项目,然后在发布的文件夹中导航到 .\publish\runtimes\unix\lib\netstandard1.3并将在那里发布的 dll 复制到 .\publish。将它们放入该文件夹后,我压缩了发布文件夹的内容(不包括运行时子文件夹),并将其上传到 lambda。
我对为什么会发生这种情况的工作理论是因为 dotnet publish 正在发布,就好像智能系统正在使用结果一样,但是我认为 lambda 正在将程序集加载到另一个不知道在子文件夹中查找依赖项的上下文。
关于c# - AWS Lambda、.Net Core 和 MySql : Could not load file or assembly 'System. Diagnostics.TraceSource,版本 = 4.0.0.0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41794621/
我正在尝试测试是否存在表单。我是Rails新手。我的new.html.erb_spec.rb文件的内容是:require'spec_helper'describe"messages/new.html.erb"doit"shouldrendertheform"dorender'/messages/new.html.erb'reponse.shouldhave_form_putting_to(@message)with_submit_buttonendendView本身,new.html.erb,有代码:当我运行rspec时,它失败了:1)messages/new.html.erbshou
我在我的项目目录中完成了compasscreate.和compassinitrails。几个问题:我已将我的.sass文件放在public/stylesheets中。这是放置它们的正确位置吗?当我运行compasswatch时,它不会自动编译这些.sass文件。我必须手动指定文件:compasswatchpublic/stylesheets/myfile.sass等。如何让它自动运行?文件ie.css、print.css和screen.css已放在stylesheets/compiled。如何在编译后不让它们重新出现的情况下删除它们?我自己编译的.sass文件编译成compiled/t
我在我的项目中添加了一个系统来重置用户密码并通过电子邮件将密码发送给他,以防他忘记密码。昨天它运行良好(当我实现它时)。当我今天尝试启动服务器时,出现以下错误。=>BootingWEBrick=>Rails3.2.1applicationstartingindevelopmentonhttp://0.0.0.0:3000=>Callwith-dtodetach=>Ctrl-CtoshutdownserverExiting/Users/vinayshenoy/.rvm/gems/ruby-1.9.3-p0/gems/actionmailer-3.2.1/lib/action_mailer
在MRIRuby中我可以这样做:deftransferinternal_server=self.init_serverpid=forkdointernal_server.runend#Maketheserverprocessrunindependently.Process.detach(pid)internal_client=self.init_client#Dootherstuffwithconnectingtointernal_server...internal_client.post('somedata')ensure#KillserverProcess.kill('KILL',
我已经从我的命令行中获得了一切,所以我可以运行rubymyfile并且它可以正常工作。但是当我尝试从sublime中运行它时,我得到了undefinedmethod`require_relative'formain:Object有人知道我的sublime设置中缺少什么吗?我正在使用OSX并安装了rvm。 最佳答案 或者,您可以只使用“require”,它应该可以正常工作。我认为“require_relative”仅适用于ruby1.9+ 关于ruby-主要:Objectwhenrun
我花了三天的时间用头撞墙,试图弄清楚为什么简单的“rake”不能通过我的规范文件。如果您遇到这种情况:任何文件夹路径中都不要有空格!。严重地。事实上,从现在开始,您命名的任何内容都没有空格。这是我的控制台输出:(在/Users/*****/Desktop/LearningRuby/learn_ruby)$rake/Users/*******/Desktop/LearningRuby/learn_ruby/00_hello/hello_spec.rb:116:in`require':cannotloadsuchfile--hello(LoadError) 最佳
我在我的Rails项目中使用Pow和powifygem。现在我尝试升级我的ruby版本(从1.9.3到2.0.0,我使用RVM)当我切换ruby版本、安装所有gem依赖项时,我通过运行railss并访问localhost:3000确保该应用程序正常运行以前,我通过使用pow访问http://my_app.dev来浏览我的应用程序。升级后,由于错误Bundler::RubyVersionMismatch:YourRubyversionis1.9.3,butyourGemfilespecified2.0.0,此url不起作用我尝试过的:重新创建pow应用程序重启pow服务器更新战俘
我已经像这样安装了一个新的Rails项目:$railsnewsite它执行并到达:bundleinstall但是当它似乎尝试安装依赖项时我得到了这个错误Gem::Ext::BuildError:ERROR:Failedtobuildgemnativeextension./System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/rubyextconf.rbcheckingforlibkern/OSAtomic.h...yescreatingMakefilemake"DESTDIR="cleanmake"DESTDIR="
我正在尝试修改当前依赖于定义为activeresource的gem:s.add_dependency"activeresource","~>3.0"为了让gem与Rails4一起工作,我需要扩展依赖关系以与activeresource的版本3或4一起工作。我不想简单地添加以下内容,因为它可能会在以后引起问题:s.add_dependency"activeresource",">=3.0"有没有办法指定可接受版本的列表?~>3.0还是~>4.0? 最佳答案 根据thedocumentation,如果你想要3到4之间的所有版本,你可以这
关闭。这个问题需要detailsorclarity.它目前不接受答案。想改进这个问题吗?通过editingthispost添加细节并澄清问题.关闭8年前。Improvethisquestion在首页我有:汽车:VolvoSaabMercedesAudistatic_pages_spec.rb中的测试代码:it"shouldhavetherightselect"dovisithome_pathit{shouldhave_select('cars',:options=>['volvo','saab','mercedes','audi'])}end响应是rspec./spec/request