When using Sql Data Client or EF in .Net Core 1.0 on AWS Lambda the code errors out indicating that the platform is not supported. Is it true that I can get to Sql Server from node.js on Lambda but not C#? Seems a bit odd. Following is the text of the error:
{
"errorType": "AggregateException",
"errorMessage": "One or more errors occurred. (The type initializer for 'System.Data.SqlClient.MetaType' threw an exception.)",
"stackTrace": [
"at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)",
"at System.Threading.Tasks.Task 1.GetResultCore(Boolean waitCompletionNotification)",
"at lambda_method(Closure , Stream , Stream , ContextInfo )"
],
"cause": {
"errorType": "TypeInitializationException",
"errorMessage": "The type initializer for 'System.Data.SqlClient.MetaType' threw an exception.",
"stackTrace": [
"at System.Data.SqlClient.MetaType.GetMetaTypeFromSqlDbType(SqlDbType target, Boolean isMultiValued)",
"at System.Data.SqlClient.SqlParameter.set_SqlDbType(SqlDbType value)",
"at initRestoreDB.Function.<FunctionHandler>d__6.MoveNext()"
],
"cause": {
"errorType": "TypeInitializationException",
"errorMessage": "The type initializer for 'System.Data.Common.ADP' threw an exception.",
"stackTrace": [
"at System.Data.SqlClient.MetaType..cctor()"
],
"cause": {
"errorType": "PlatformNotSupportedException",
"errorMessage": "Operation is not supported on this platform.",
"stackTrace": [
"at System.Runtime.InteropServices.OSPlatform.get_Windows()",
"at System.Data.Common.ADP..cctor()"
]
}
}
}
}
The is repeatable for any SQL call from Lambda which runs .Net Core 1.0 on AWS Linux.
Facing same issue.
_SCENARIO:_ When opening a connection to a SQL Server database running on Linux (specifically an AWS Lambda), the framework is throwing an unsupported operation exception since System.Runtime.InteropServices operations aren't supported.
_SUGGESTED RESOLUTION:_ Don't throw this exception on non-Windows clients. Similar situation here: https://github.com/StackExchange/StackExchange.Redis/pull/588/commits/6fe10de7e04171c98bab17d682559d2692f33895
_STACK TRACE:_
System.Data.SqlClient.SqlException: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: TCP Provider, error: 35 - An internal exception was caught) ---> System.AggregateException: One or more errors occurred. (Operation is not supported on this platform.) ---> _System.PlatformNotSupportedException: Operation is not supported on this platform.
at System.Runtime.InteropServices.OSPlatform.get_Windows()
at System.Data.SqlClient.SNI.SNITCPHandle.
--- End of inner exception stack trace ---
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
at System.Threading.Tasks.Task.Wait(TimeSpan timeout)
at System.Data.SqlClient.SNI.SNITCPHandle..ctor(String serverName, Int32 port, Int64 timerExpire, Object callbackObject, Boolean parallel)
--- End of inner exception stack trace ---
at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, Boolean applyTransientFaultHandling)
at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions)
at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource1 retry, DbConnectionOptions userOptions)
at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource1 retry)
at System.Data.SqlClient.SqlConnection.Open()
It appears there is an issue with "System.Data.SqlClient" version greater than "4.1.0". Any version after this breaks on OS detection in the AWS Linux version used as the OS for Lambda functions. Rolling back my "Microsoft.EntityFrameworkCore.SqlServer" package to version "1.0.3" allows the code to work. Not sure if this allows the issue to be closed or not as there is clearly still a bug in the newer versions of the "System.Data.SqlClient".
Even with "Microsoft.EntityFrameworkCore.SqlServer": "1.0.3" I get the same error. See bottom of the stack trace below and project.json for reference.
STACK TRACE FROM CLOUDWATCH:
One or more errors occurred. (A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: TCP Provider, error: 35 - An internal exception was caught)): AggregateException
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
at lambda_method(Closure , Stream , Stream , ContextInfo )
at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, Boolean applyTransientFaultHandling)
at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions)
at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource1 retry, DbConnectionOptions userOptions)
at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource1 retry)
at System.Data.SqlClient.SqlConnection.Open()
at Utility.SqlServerDatabaseUtility.GetConnection() <-- My utility function to connect to SQL Server
_...my Lambda function handler methods..._
One or more errors occurred. (Operation is not supported on this platform.): AggregateException
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
at System.Threading.Tasks.Task.Wait(TimeSpan timeout)
at System.Data.SqlClient.SNI.SNITCPHandle..ctor(String serverName, Int32 port, Int64 timerExpire, Object callbackObject, Boolean parallel)
Operation is not supported on this platform.: PlatformNotSupportedException
at System.Runtime.InteropServices.OSPlatform.get_Windows()
at System.Data.SqlClient.SNI.SNITCPHandle.
PROJECT.JSON (for reference)
{
"version": "1.0.0-*",
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.1"
},
"Amazon.Lambda.Core": "1.0.0",
"Microsoft.EntityFrameworkCore.SqlServer": "1.0.3",
_...other dependencies..._
},
"frameworks": {
"netcoreapp1.0": {
"imports": "dnxcore50"
}
}
}
@stephentoub are you familiar with this System.Runtime.InteropServices.OSPlatform.get_Windows() issue on Linux?
are you familiar with this System.Runtime.InteropServices.OSPlatform.get_Windows() issue on Linux?
The Windows property does not throw a PlatformNotSupportedException in the code, regardless of OS:
https://github.com/dotnet/corefx/blob/master/src/System.Runtime.InteropServices.RuntimeInformation/src/System/Runtime/InteropServices/RuntimeInformation/OSPlatform.cs#L15
The only way I believe that could happen is if the build of the System.Runtime.InteropServices.RuntimeInformation.dll that was used was produced with the GeneratePlatformNotSupportedAssembly somehow enabled:
https://github.com/dotnet/corefx/blob/master/src/System.Runtime.InteropServices.RuntimeInformation/src/System.Runtime.InteropServices.RuntimeInformation.csproj#L13
which suggest some kind of build and/or deployment problem.
cc: @ericstj, @weshaggard
I agree with @stephentoub that the wrong one must be getting deployed. Can you look at your lock/assets file and see which asset you are getting for System.Runtime.InteropServices.RuntimeInformation? Which package version and which binary path to it?
Here's what's in my project.lock.json file (relevant portions as far as I understand). Let me know if you need more.
Since "System.Data.SqlClient/4.1.0" depends on "System.Runtime.InteropServices.RuntimeInformation": "4.0.0", should there be "System.Runtime.InteropServices.RuntimeInformation/4.0.0": {" target and library nodes (in addition to the 4.3.0 target and library nodes that currently exist)?
_Note: Please correct me if I'm wrong here since I'm not very well-versed with these lock files._
{
...
"targets":
...
"Microsoft.EntityFrameworkCore/1.0.3": …,
"Microsoft.EntityFrameworkCore.Relational/1.0.3": …,
"Microsoft.EntityFrameworkCore.SqlServer/1.0.3": {
"type": "package",
"dependencies": {
"Microsoft.EntityFrameworkCore.Relational": "1.0.3",
"System.Data.SqlClient": "4.1.0",
"System.Threading.Thread": "4.0.0"
},
"compile": {
"lib/netstandard1.3/Microsoft.EntityFrameworkCore.SqlServer.dll": {}
},
"runtime": {
"lib/netstandard1.3/Microsoft.EntityFrameworkCore.SqlServer.dll": {}
}
},
…
"System.Data.SqlClient/4.1.0": {
"type": "package",
"dependencies": {
"Microsoft.NETCore.Platforms": "1.0.1",
"Microsoft.Win32.Primitives": "4.0.1",
"System.Collections": "4.0.11",
"System.Collections.Concurrent": "4.0.12",
"System.Data.Common": "4.1.0",
"System.Diagnostics.Debug": "4.0.11",
"System.Diagnostics.DiagnosticSource": "4.0.0",
"System.Globalization": "4.0.11",
"System.IO": "4.1.0",
"System.IO.Pipes": "4.0.0",
"System.Linq": "4.1.0",
"System.Net.NameResolution": "4.0.0",
"System.Net.Primitives": "4.0.11",
"System.Net.Security": "4.0.0",
"System.Net.Sockets": "4.1.0",
"System.Reflection": "4.1.0",
"System.Reflection.TypeExtensions": "4.1.0",
"System.Resources.ResourceManager": "4.0.1",
"System.Runtime": "4.1.0",
"System.Runtime.Extensions": "4.1.0",
"System.Runtime.Handles": "4.0.1",
"System.Runtime.InteropServices": "4.1.0",
"System.Runtime.InteropServices.RuntimeInformation": "4.0.0",
"System.Security.Cryptography.X509Certificates": "4.1.0",
"System.Security.Principal": "4.0.1",
"System.Security.Principal.Windows": "4.0.0",
"System.Text.Encoding": "4.0.11",
"System.Text.Encoding.CodePages": "4.0.1",
"System.Text.Encoding.Extensions": "4.0.11",
"System.Text.RegularExpressions": "4.1.0",
"System.Threading": "4.0.11",
"System.Threading.Tasks": "4.0.11",
"System.Threading.Thread": "4.0.0",
"System.Threading.ThreadPool": "4.0.10",
"System.Threading.Timer": "4.0.1",
"System.Xml.ReaderWriter": "4.0.11",
"runtime.native.System.Data.SqlClient.sni": "4.0.0"
},
"compile": {
"ref/netstandard1.3/System.Data.SqlClient.dll": {}
},
"runtimeTargets": {
"runtimes/unix/lib/netstandard1.3/System.Data.SqlClient.dll": {
"assetType": "runtime",
"rid": "unix"
},
"runtimes/win/lib/netstandard1.3/System.Data.SqlClient.dll": {
"assetType": "runtime",
"rid": "win"
}
}
},
…
"System.Runtime.InteropServices.RuntimeInformation/4.3.0": {
"type": "package",
"dependencies": {
"System.Reflection": "4.3.0",
"System.Reflection.Extensions": "4.3.0",
"System.Resources.ResourceManager": "4.3.0",
"System.Runtime": "4.3.0",
"System.Runtime.InteropServices": "4.3.0",
"System.Threading": "4.3.0",
"runtime.native.System": "4.3.0"
},
"compile": {
"ref/netstandard1.1/System.Runtime.InteropServices.RuntimeInformation.dll": {}
},
"runtime": {
"lib/netstandard1.1/System.Runtime.InteropServices.RuntimeInformation.dll": {}
},
"runtimeTargets": {
"runtimes/unix/lib/netstandard1.1/System.Runtime.InteropServices.RuntimeInformation.dll": {
"assetType": "runtime",
"rid": "unix"
},
"runtimes/win/lib/netstandard1.1/System.Runtime.InteropServices.RuntimeInformation.dll": {
"assetType": "runtime",
"rid": "win"
}
}
},
…
"libraries":
...
"System.Runtime.InteropServices.RuntimeInformation/4.3.0": {
"sha512": "ch47S3N0ci2TdrBaG5PANOTDxnYzd/YqK+SMKI9YpN+eQ6yanpQN3VSfWOmYXKi9L7m6H1HBFMiXVhb5qROXXw==",
"type": "package",
"path": "System.Runtime.InteropServices.RuntimeInformation/4.3.0",
"files": [
"System.Runtime.InteropServices.RuntimeInformation.4.3.0.nupkg.sha512",
"System.Runtime.InteropServices.RuntimeInformation.nuspec",
"ThirdPartyNotices.txt",
"dotnet_library_license.txt",
"lib/MonoAndroid10/_._",
"lib/MonoTouch10/_._",
"lib/net45/System.Runtime.InteropServices.RuntimeInformation.dll",
"lib/netstandard1.1/System.Runtime.InteropServices.RuntimeInformation.dll",
"lib/win8/System.Runtime.InteropServices.RuntimeInformation.dll",
"lib/wpa81/System.Runtime.InteropServices.RuntimeInformation.dll",
"lib/xamarinios10/_._",
"lib/xamarinmac20/_._",
"lib/xamarintvos10/_._",
"lib/xamarinwatchos10/_._",
"ref/MonoAndroid10/_._",
"ref/MonoTouch10/_._",
"ref/netstandard1.1/System.Runtime.InteropServices.RuntimeInformation.dll",
"ref/xamarinios10/_._",
"ref/xamarinmac20/_._",
"ref/xamarintvos10/_._",
"ref/xamarinwatchos10/_._",
"runtimes/aot/lib/netcore50/System.Runtime.InteropServices.RuntimeInformation.dll",
"runtimes/unix/lib/netstandard1.1/System.Runtime.InteropServices.RuntimeInformation.dll",
"runtimes/win/lib/net45/System.Runtime.InteropServices.RuntimeInformation.dll",
"runtimes/win/lib/netcore50/System.Runtime.InteropServices.RuntimeInformation.dll",
"runtimes/win/lib/netstandard1.1/System.Runtime.InteropServices.RuntimeInformation.dll"
]
},
Thanks for the information. There are a couple of interesting things here:
To fix this there are a couple options:
I would go with option (1) if you don't have any reason to be a netcoreapp1.0 application.
@ericstj this is an interesting case of the package dependencies being lifted.
Here are the references that are pulling in the 4.3.0 package:
{
...
"targets":
...
"System.IdentityModel.Tokens.Jwt/5.1.2": { _<-- Being referenced by the Box.V2.Core/2.14.2 API which I'm using_
"type": "package",
"dependencies": {
"Microsoft.IdentityModel.Tokens": "5.1.2"
},
"compile": {
"lib/netstandard1.4/System.IdentityModel.Tokens.Jwt.dll": {}
},
"runtime": {
"lib/netstandard1.4/System.IdentityModel.Tokens.Jwt.dll": {}
}
},
"Microsoft.IdentityModel.Tokens/5.1.2": {
"type": "package",
"dependencies": {
"Microsoft.IdentityModel.Logging": "1.1.2",
"Newtonsoft.Json": "9.0.1",
"System.Collections": "4.3.0",
"System.Diagnostics.Tools": "4.3.0",
"System.Runtime": "4.3.0",
"System.Runtime.Extensions": "4.3.0",
"System.Runtime.InteropServices": "4.3.0",
"System.Runtime.InteropServices.RuntimeInformation": "4.3.0",
"System.Security.Claims": "4.3.0",
"System.Security.Cryptography.Algorithms": "4.3.0",
"System.Security.Cryptography.Csp": "4.3.0",
"System.Security.Cryptography.X509Certificates": "4.3.0",
"System.Text.RegularExpressions": "4.3.0",
"System.Threading": "4.3.0",
"System.Xml.ReaderWriter": "4.3.0"
},
"compile": {
"lib/netstandard1.4/Microsoft.IdentityModel.Tokens.dll": {}
},
"runtime": {
"lib/netstandard1.4/Microsoft.IdentityModel.Tokens.dll": {}
}
},
...
"NETStandard.Library/1.6.1": { _<-- Being referenced by the Box.V2.Core/2.14.2 API which I'm using_
"type": "package",
"dependencies": {
"Microsoft.NETCore.Platforms": "1.1.0",
"Microsoft.Win32.Primitives": "4.3.0",
"System.AppContext": "4.3.0",
"System.Collections": "4.3.0",
"System.Collections.Concurrent": "4.3.0",
"System.Console": "4.3.0",
"System.Diagnostics.Debug": "4.3.0",
"System.Diagnostics.Tools": "4.3.0",
"System.Diagnostics.Tracing": "4.3.0",
"System.Globalization": "4.3.0",
"System.Globalization.Calendars": "4.3.0",
"System.IO": "4.3.0",
"System.IO.Compression": "4.3.0",
"System.IO.Compression.ZipFile": "4.3.0",
"System.IO.FileSystem": "4.3.0",
"System.IO.FileSystem.Primitives": "4.3.0",
"System.Linq": "4.3.0",
"System.Linq.Expressions": "4.3.0",
"System.Net.Http": "4.3.0",
"System.Net.Primitives": "4.3.0",
"System.Net.Sockets": "4.3.0",
"System.ObjectModel": "4.3.0",
"System.Reflection": "4.3.0",
"System.Reflection.Extensions": "4.3.0",
"System.Reflection.Primitives": "4.3.0",
"System.Resources.ResourceManager": "4.3.0",
"System.Runtime": "4.3.0",
"System.Runtime.Extensions": "4.3.0",
"System.Runtime.Handles": "4.3.0",
"System.Runtime.InteropServices": "4.3.0",
"System.Runtime.InteropServices.RuntimeInformation": "4.3.0",
"System.Runtime.Numerics": "4.3.0",
"System.Security.Cryptography.Algorithms": "4.3.0",
"System.Security.Cryptography.Encoding": "4.3.0",
"System.Security.Cryptography.Primitives": "4.3.0",
"System.Security.Cryptography.X509Certificates": "4.3.0",
"System.Text.Encoding": "4.3.0",
"System.Text.Encoding.Extensions": "4.3.0",
"System.Text.RegularExpressions": "4.3.0",
"System.Threading": "4.3.0",
"System.Threading.Tasks": "4.3.0",
"System.Threading.Timer": "4.3.0",
"System.Xml.ReaderWriter": "4.3.0",
"System.Xml.XDocument": "4.3.0"
}
},
…
}
@abbasl did changing to netcoreapp1.1 fix this for you?
In order to root cause this we need to track back the package reference all the way to the one you reference, so who is referencing NETStandard.Library 1.6.1?
Still testing it. Will post my findings.
Note: NETStandard.Library 1.6.1 is also being referenced by the Box API. Having said that, I only added the Box API reference on 3/22 i.e. after posting the PlatformNotSupportedException.
I changed to netcoreapp1.1 but now my application won't run -- I get the following exception. This is even after specifically adding a System.Data.SqlClient/4.1.0 dependency and verifying it exists in the lock file. Having tried this, I'm not sure if AWS Lambda supports .NET Core 1.1, but I will validate this assumption with a separate test.
EXCEPTION:
{
"errorType": "AggregateException",
"errorMessage": "One or more errors occurred. (Could not load file or assembly 'System.Data.SqlClient, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
)",
"stackTrace": [
"at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)",
"at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)",
"at lambda_method(Closure , Stream , Stream , ContextInfo )"
],
"cause": {
"errorType": "FileNotFoundException",
"errorMessage": "Could not load file or assembly 'System.Data.SqlClient, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.",
"stackTrace": [
"at *",
"at *.
],
"cause": {
"errorType": "FileNotFoundException",
"errorMessage": "'System.Data.SqlClient, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' not found in the deployment package or in the installed Microsoft.NETCore.App.",
"stackTrace": [
"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)"
]
}
}
}
PROJECT.JSON
{
"version": "1.1.0",
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.1.0"
},
...
"System.Data.SqlClient": "4.1.0",
//"Microsoft.EntityFrameworkCore.SqlServer": "1.0.3", <-- tried with this dependency and without; same exception
...
},
"frameworks": {
"netcoreapp1.1": {
"imports": "dnxcore50"
}
}
}
PROJECT.LOCK.JSON
"System.Data.SqlClient/4.1.0": {
"sha512": "yqMZgzzKHdG84QmA/PPZUORaoisfvztvFqyPs7dPafJhNxlS7STf9OMCFrP/tITQCqImkm1+X4d2oiWOT2oTKg==",
"type": "package",
"path": "System.Data.SqlClient/4.1.0",
"files": [
"System.Data.SqlClient.4.1.0.nupkg.sha512",
"System.Data.SqlClient.nuspec",
"ThirdPartyNotices.txt",
"dotnet_library_license.txt",
"lib/MonoAndroid10/_._",
"lib/MonoTouch10/_._",
"lib/net451/System.Data.SqlClient.dll",
"lib/net46/System.Data.SqlClient.dll",
"lib/xamarinios10/_._",
"lib/xamarinmac20/_._",
"lib/xamarintvos10/_._",
"lib/xamarinwatchos10/_._",
"ref/MonoAndroid10/_._",
"ref/MonoTouch10/_._",
"ref/net451/System.Data.SqlClient.dll",
"ref/net46/System.Data.SqlClient.dll",
"ref/netstandard1.2/System.Data.SqlClient.dll",
"ref/netstandard1.2/System.Data.SqlClient.xml",
"ref/netstandard1.2/de/System.Data.SqlClient.xml",
"ref/netstandard1.2/es/System.Data.SqlClient.xml",
"ref/netstandard1.2/fr/System.Data.SqlClient.xml",
"ref/netstandard1.2/it/System.Data.SqlClient.xml",
"ref/netstandard1.2/ja/System.Data.SqlClient.xml",
"ref/netstandard1.2/ko/System.Data.SqlClient.xml",
"ref/netstandard1.2/ru/System.Data.SqlClient.xml",
"ref/netstandard1.2/zh-hans/System.Data.SqlClient.xml",
"ref/netstandard1.2/zh-hant/System.Data.SqlClient.xml",
"ref/netstandard1.3/System.Data.SqlClient.dll",
"ref/netstandard1.3/System.Data.SqlClient.xml",
"ref/netstandard1.3/de/System.Data.SqlClient.xml",
"ref/netstandard1.3/es/System.Data.SqlClient.xml",
"ref/netstandard1.3/fr/System.Data.SqlClient.xml",
"ref/netstandard1.3/it/System.Data.SqlClient.xml",
"ref/netstandard1.3/ja/System.Data.SqlClient.xml",
"ref/netstandard1.3/ko/System.Data.SqlClient.xml",
"ref/netstandard1.3/ru/System.Data.SqlClient.xml",
"ref/netstandard1.3/zh-hans/System.Data.SqlClient.xml",
"ref/netstandard1.3/zh-hant/System.Data.SqlClient.xml",
"ref/xamarinios10/_._",
"ref/xamarinmac20/_._",
"ref/xamarintvos10/_._",
"ref/xamarinwatchos10/_._",
"runtimes/unix/lib/netstandard1.3/System.Data.SqlClient.dll",
"runtimes/win/lib/net451/System.Data.SqlClient.dll",
"runtimes/win/lib/net46/System.Data.SqlClient.dll",
"runtimes/win/lib/netstandard1.3/System.Data.SqlClient.dll"
]
},
I don't believe AWS Lambdas support netcoreapp1.1 at this time
I am now going back to netcoreapp1.0. Perhaps this 'trimmed dependencies' project will yield some results.
EXCEPTION:
{
"errorType": "FileNotFoundException",
"errorMessage": "Could not load file or assembly 'System.Data.SqlClient, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.",
"stackTrace": [
"at .SqlServerDatabaseUtility.InsertIntoDatabase(SpecialData data, ILogger logger)",
"at *.**.FunctionHandler(Stream input, ILambdaContext context)",
"at lambda_method(Closure , Stream , Stream , ContextInfo )"
],
"cause": {
"errorType": "FileNotFoundException",
"errorMessage": "'System.Data.SqlClient, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' not found in the deployment package or in the installed Microsoft.NETCore.App.",
"stackTrace": [
"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)"
]
}
}
PROJECT.JSON
{
"version": "1.0.0-*",
"buildOptions": {
},
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.1.0"
},
"Amazon.Lambda.Core": "1.0.0*",
"Amazon.Lambda.Serialization.Json": "1.0.1",
"Amazon.Lambda.Tools": {
"type": "build",
"version": "1.4.0"
},
"System.Data.SqlClient": "4.1.0",
"System.Xml.XmlSerializer": "4.3.0"
},
"tools": {
"Amazon.Lambda.Tools" : "1.4.0"
},
"frameworks": {
"netcoreapp1.1": {
"imports": "dnxcore50"
}
}
}
I'm now able to write to SQL Server using netcoreapp1.0 and System.Data.SqlClient/4.1.0 :-)
The dependencies that force the project to use an incompatible library version:
Option 2 didn't work for me. It causes the AWS Lambda to exit with message "Process exited before completing request".
My conclusion: I'll be refactoring my project to segregate incompatible dependencies.
Thanks for all your help! If you need additional details for this issue, I'd be happy to provide them.
Thanks for looking into the issue.
[Linking to a similar [issue ](http://stackoverflow.com/questions/41613781/trouble-connecting-to-sql-server-express-with-a-c-sharp-aws-lambda-function) on StackOverflow.]
After adding the following dependencies explicitly, it is now able to connect to SQL Server again.
"System.Data.SqlClient": "4.1.0", "System.Runtime.InteropServices.RuntimeInformation": "4.0.0"
Wonder if there will be a permanent fix without having to add the above?
@imkheong a fix depends if the above information is sufficient - @weshaggard do you know what's going on here?
Note that AWS Linux is not officially supported distro, so while we do not want to block it intentionally, we do not have any test coverage or any knowledge about what is so special on this distro -- we need community help here to help us understand specifics. If you can get a repro on one of the supported distros, that would be tremendous help.
If you can get a repro on one of the supported distros, that would be tremendous help.
@karelz Does it mean running the code on Ubuntu Linux to simulate the issue?
Yes, Ubuntu repro is something we can easily run in-house and reason about. That would definitely help.
Okay, will try that once I get a chance.
cc @dsplaisted for sdk potentiall issues or @gkhanna79 for host issues.
After chatting with @ericstj on this this seems like it could be a tool or runtime issue. Can you guys tell me whether or not your output folder contains and folders that look like "win-x64", etc? If so the host should be resolving those runtime specific assets at runtime and thus shouldn't be picking up the dummy version of RuntimeInformation, which is causing these PNSE's to be thrown.
@weshaggard there is no folder with the name of "win-x64" in my case. The deployment package is a zip file bundled by the AWS Toolkit for Visual Studio. By right clicking on the serverless project (implementing the AWS Serverless Application Model (SAM), select "Publish to AWS Lambda...". The files necessary to run the application is zipped into a zip file and subsequently sent to the AWS S3. Attached is the list of files found in the packaged zip file for reference. Note: There are not any folders within the zip file.
@karelz I have completed the exercise to create an Ubuntu 16.04.2 EC2 instance that will execute the erroneous code to access the database. It ran just fine.
On the other end, the issue also appears to be a non-issue after a retry on AWS Lambda just a while ago.
@imkheong what do you mean by retry? Rebuild and redeploy? Or is it intermittent issue which comes and goes over time?
It's bummer if you can't repro on Ubuntu. Let's see if @weshaggard can come up with some ideas ...
@dsplaisted @livarcocc are you guys aware of any deployment issues with AWS? At a high level it appears that the RID folders aren't getting published with the output so it is picking the incorrect version of RuntimeInformation which is the fallback which throw PNSE for everything.
@karelz What I did was clean, rebuild and 'publish to AWS Lambda' using Visual Studio. The same code that was giving this error appears working correctly.
I second @weshaggard observation on the missing RID folders. Before the issue, the same code works before some time February 12th. The packaged file includes a runtime folder that contains the other runtimes assemblies. I believe these are RID folders that @weshaggard has mentioned.
Given the above observations, likely that an update to the AWS Toolkit for Visual Studio introduced a breaking change that affected the zip packaging format, which then affected the DLLs available at runtime.
Can someone also assert that the issue is not appearing any more?
OK, so the issue seems to be resolved. I will opportunistically close it.
If I am wrong, or if it still repros, feel free to reopen the issue or file a new one. Thanks!
I hope this could help, in my situation I was deploying a netcore app v1.0 to AWS Lambda.
I also use EF Core for data management.
Trying to make a Sql Server connection gave me this exception (System.PlatformNotSupportedException).
After downgrade from System.Data.SqlClient from 4.3.0 to 4.1.0 I can confirm it works for me.
Downgrade from 4.30. to 4.1.0 works for me too.
When I use the 4.3.0 package, the following code doest not work: System.Runtime.InteropServices.RuntimeInformation.OSDescription , on AWS lambda, it says that is not supported on the OS.
as per help received on https://github.com/aws/aws-lambda-dotnet/issues/181, you have to reference more than just specific versions of those 2 dll's - there are quite a few.
after taking the advise of @ibuchan72390 on there i found the following packages had to be there, and at these specific versions, for sql to work in lambda:
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="1.0.3" />
<PackageReference Include="Microsoft.AspNetCore" Version="1.0.5" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.0.4" />
<PackageReference Include="System.Runtime.InteropServices" Version="4.1.0" />
<PackageReference Include="System.Runtime.InteropServices.RuntimeInformation" Version="4.0.0" />
<PackageReference Include="System.Data.SqlClient" Version="4.1.0" IncludeAssets="All" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="1.0.6" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.0.2" />
<PackageReference Include="System.Security.Cryptography.Algorithms" Version="4.2.1" />
<PackageReference Include="System.Security.Cryptography.Cng" Version="4.2.0" />
<PackageReference Include="System.Security.Cryptography.Encoding" Version="4.0.0" />
<PackageReference Include="System.Security.Cryptography.Primitives" Version="4.0.0" />
<PackageReference Include="System.Security.Cryptography.X509Certificates" Version="4.1.0" />
<PackageReference Include="System.Security.Cryptography.OpenSsl" Version="4.0.1" />
<PackageReference Include="AWSSDK.SimpleNotificationService" Version="3.3.0.23" />
<PackageReference Include="Amazon.Lambda.AspNetCoreServer" Version="0.10.2-preview1" />
<PackageReference Include="Amazon.Lambda.Logging.AspNetCore" Version="1.1.0" />
<PackageReference Include="Amazon.Lambda.Tools" Version="1.9.0" />
[EDIT] Link the aws-lambda-dotnet issue & add syntax highlighting by @karelz
I ran into this issue again with SqlClient 4.6.0. Reverting to 4.5.1 fixed the issue.