Efcore: SqlConnection: System.MissingMethodException: 'Method not found: 'Boolean System.String.Contains(Char)'.'

Created on 7 Jun 2018  路  7Comments  路  Source: dotnet/efcore

There is a missing method when targeting UWP Windows10, version 1803
imagen

Exception message:
Method not found: 'Boolean System.String.Contains(Char)'.

Stack trace:
at System.Data.SqlClient.SNI.DataSource.InferNamedPipesInformation()
at System.Data.SqlClient.SNI.DataSource.ParseServerName(String dataSource)
at System.Data.SqlClient.SNI.SNIProxy.CreateConnectionHandle(Object callbackObject, String fullServerName, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Byte[]& instanceName, Byte[]& spnBuffer, Boolean flushCache, Boolean async, Boolean parallel, Boolean isIntegratedSecurity)
at System.Data.SqlClient.SNI.TdsParserStateObjectManaged.CreatePhysicalSNIHandle(String serverName, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Byte[]& instanceName, Byte[]& spnBuffer, Boolean flushCache, Boolean async, Boolean parallel, Boolean isIntegratedSecurity)
at System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, Boolean withFailover)
at System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, Boolean withFailover)
at System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString connectionOptions, SqlCredential credential, TimeoutTimer timeout)
at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer timeout, SqlConnectionString connectionOptions, SqlCredential credential, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance)
at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, 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.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource1 retry, DbConnectionOptions userOptions)
at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
at System.Data.SqlClient.SqlConnection.Open()
at App3.MainPage.Page_Loaded(Object sender, RoutedEventArgs e)

### Steps to reproduce
Create a UWP project
Add reference to Microsoft.EntityFrameworkCore.SqlServer (this will add also a update reference of System.Data.SqlClient)

In main xaml add following code using a sql server:
```c#
SqlConnection con = new SqlConnection("Data Source=jackson;Initial Catalog=Database;user id=***;password=***;");
con.Open();

Same error appears when EFcore is used with SQL server in UWP projects. The project is that SqlClient reference has been updated and missingfunction is launched.

region Assembly System.Data.SqlClient, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a

// C:\Usersagonzalezgorordo.nuget\packages\system.data.sqlclient*4.5.0*\ref\netstandard2.0\System.Data.SqlClient.dll

endregion

Further technical details

EF Core version: 2.1
Database Provider: Microsoft.EntityFrameworkCore.SqlServer
Operating system: Windows10
IDE: Visual Studio 2017 15.7.3

closed-external customer-reported

All 7 comments

@asiergonzalezgorordo This could be an issue with the combination of packages and versions being used. Can you post your csproj file?

I get the same error message, this is reproducable, just create a new empty project and add these package references (see screenshot)

Upgrading to .NET Standard library v2.0.3 also makes no difference...

packages

@edoust - Can you upgrade NETStandard.Library to 2.0.3 and see if it still happens? UWP 6.1.5 release says that it upgraded it but if you reference 2.0.1 explicitly you are causing a downgrade which may not be compatible and cause errors.

@smitpatel I have tried that already, it makes no difference...

The problem is with system.data.sqlclient reference because it is updated
to version 4.5.0 when adding sqlserver reference.

If you create a new project and just add that reference it throws same
error.

See screenshot:

imagen

Hi again.

I have been investigating a bit...
The problem is in following function of SNIProxy.cs of System.Data.SqlClient reference in if (!_dataSourceAfterTrimmingProtocol.Contains(BackSlashSeparator)) code.

private bool InferNamedPipesInformation()
{
    // If we have a datasource beginning with a pipe or we have already determined that the protocol is Named Pipe
    if (_dataSourceAfterTrimmingProtocol.StartsWith(PipeBeginning) || ConnectionProtocol == Protocol.NP)
    {
        // If the data source is "np:servername"
        if (!_dataSourceAfterTrimmingProtocol.Contains(BackSlashSeparator))
        {
            PipeHostName = ServerName = _dataSourceAfterTrimmingProtocol;
            InferLocalServerName();
            PipeName = SNINpHandle.DefaultPipePath;
            return true;
        }
...

System.String.Contains method in UWP does not implement contains with a char, this can be checked by adding following code in an UWP project.

const char BackSlashSeparator = '\\';
string s = string.Empty;
s.Contains(BackSlashSeparator);

It will try to add a Linq reference.

Maybe it helps

This issue was moved to dotnet/corefx#30255

Was this page helpful?
0 / 5 - 0 ratings