Bug 37368 - EntryPointNotFoundException at System.Data.Common.SafeNativeMethods when using ODBC
Summary: EntryPointNotFoundException at System.Data.Common.SafeNativeMethods when usin...
Status: NEW
Alias: None
Product: Class Libraries
Classification: Mono
Component: System.Data (show other bugs)
Version: 4.2.0 (C6)
Hardware: PC Linux
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2016-01-03 20:06 UTC by Lars Hollenbach
Modified: 2017-11-21 08:26 UTC (History)
14 users (show)

See Also:
Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Sample that causes the Exception, needs to be linked to System.Data (641 bytes, text/x-csharp)
2016-01-03 20:06 UTC, Lars Hollenbach
Details
A patch that uses Marshal instead os SafeNativeMethods (2.25 KB, patch)
2016-01-05 17:56 UTC, Lars Hollenbach
Details | Diff

Description Lars Hollenbach 2016-01-03 20:06:26 UTC
Created attachment 14426 [details]
Sample that causes the Exception, needs to be linked to System.Data

My setup:
Mono 4.2.0 from openSUSE Tumbleweed or Mono built from github
A Program that uses ODBC to connect to a PostgreSQL Database with the DSN Psql_testdb (any Db should work, though) and makes a simple SELECT.

What do I expect:
My Program lists all tables.

What happens:
ExecuteReader() throws an EntryPointNotFoundException:

System.EntryPointNotFoundException: LocalAlloc
  at (wrapper managed-to-native) System.Data.Common.SafeNativeMethods:LocalAlloc (int,intptr)
  at System.Data.ProviderBase.DbBuffer..ctor (Int32 initialSize, Boolean zeroBuffer) [0x00033] in /home/abuild/rpmbuild/BUILD/mono-4.2.1/external/referencesource/System.Data/System/Data/ProviderBase/DbBuffer.cs:37 
  at System.Data.ProviderBase.DbBuffer..ctor (Int32 initialSize) [0x00000] in /home/abuild/rpmbuild/BUILD/mono-4.2.1/external/referencesource/System.Data/System/Data/ProviderBase/DbBuffer.cs:45 
  at System.Data.Odbc.CNativeBuffer..ctor (Int32 initialSize) [0x00000] in /home/abuild/rpmbuild/BUILD/mono-4.2.1/external/referencesource/System.Data/System/Data/Odbc/OdbcUtils.cs:20 
  at System.Data.Odbc.OdbcCommand.GetStatementHandle () [0x00039] in /home/abuild/rpmbuild/BUILD/mono-4.2.1/external/referencesource/System.Data/System/Data/Odbc/OdbcCommand.cs:387 
  at System.Data.Odbc.OdbcCommand.ExecuteReaderObject (CommandBehavior behavior, System.String method, Boolean needReader, System.Object[] methodArguments, SQL_API odbcApiMethod) [0x0001c] in /home/abuild/rpmbuild/BUILD/mono-4.2.1/external/referencesource/System.Data/System/Data/Odbc/OdbcCommand.cs:552 
  at System.Data.Odbc.OdbcCommand.ExecuteReaderObject (CommandBehavior behavior, System.String method, Boolean needReader) [0x00022] in /home/abuild/rpmbuild/BUILD/mono-4.2.1/external/referencesource/System.Data/System/Data/Odbc/OdbcCommand.cs:531 
  at System.Data.Odbc.OdbcCommand.ExecuteReader (CommandBehavior behavior) [0x0000a] in /home/abuild/rpmbuild/BUILD/mono-4.2.1/external/referencesource/System.Data/System/Data/Odbc/OdbcCommand.cs:515 
  at System.Data.Odbc.OdbcCommand.ExecuteReader () [0x00000] in /home/abuild/rpmbuild/BUILD/mono-4.2.1/external/referencesource/System.Data/System/Data/Odbc/OdbcCommand.cs:509 
  at (wrapper remoting-invoke-with-check) System.Data.Odbc.OdbcCommand:ExecuteReader ()
  at OdbcTest.MainClass.Main (System.String[] args) [0x00027] in /home/<me>/Dokumente/CSharp/OdbcTest/OdbcTest/Program.cs:15

Additional Info:
LocalAlloc appears to be in ExternDll.Kernel32.
Comment 1 Esteban Troscé 2016-01-05 15:20:55 UTC
I have the same issue: it seems there is no corresponding implementation for LocalAlloc in https://github.com/mono/mono/blob/master/mono/metadata/marshal.c (mono_win32_compat_LocalAlloc is missing)
Comment 2 Lars Hollenbach 2016-01-05 17:56:35 UTC
Created attachment 14449 [details]
A patch that uses Marshal instead os SafeNativeMethods

This path makes DbBuffer use Marshal where it previously relied on Kernel32.

Remarks:
PtrToStringUni(int offset) might now go out of the actually allocated space, previously it would have done weird stuff on characters that take 32 bits and gone out of buffer space in lstrlenW.
Comment 3 Justin Wilson 2016-01-11 15:43:55 UTC
I too am running into the same error but using unixODBC w/IBM DB2 for i (dsdriver).
Comment 4 Arthur 2016-02-09 14:05:34 UTC
I had the same problem so I recompiled mono with patch provided by Lars Hollenbach and I have linked the new System.Data.dll to my project.
The patch does not work because now I'im falling into Seg fault !
Comment 5 Esteban Troscé 2016-02-09 18:46:51 UTC
I think the correct fix is adding mono_win32_compat_LocalAlloc just like other mono_win32_compat_* implementions. Then, a reference to that call has to be added to the config file just like the ones already added for others mono_win32_compat_* methods.

I'm not sure how this new mono_win32_compat_LocalAlloc method should be implemented. Maybe just wrapping a call to malloc would do the job.
Comment 6 Jack Zhang 2016-08-03 16:57:01 UTC
Any update on the issue,  I am using Mono 4.2.0 on Ubuntu 16.04LTS . ODBC with DB2, Sybase, Oracle, MS SQL Server 

All with the error as described above.

How to solve it?
Comment 7 Jack Zhang 2016-08-03 17:05:27 UTC
On Sun Solaris 11.3 compiled Mono4.2.0.  the same issue as Linux, ODBCcommand.ExecuteReader failed.

But 
using IBM.Data.DB2;
using System.Data.OracleClient;
using System.Data.SqlClient;

CommandObject.ExecuteReader are all good

Why 
using System.Data.Odbc;
CommandObject.ExecuteReader  broken with System.EntryPointNotFoundException: LocalAlloc ?


Just apply the same logic code to System.Data.Odbc
from 
IBM.Data.DB2 or System.Data.OracleClient or System.Data.SqlClient


 It should be fixed !!!
Comment 8 Anders Marchsteiner 2016-08-11 13:07:34 UTC
I can confirm this as well

# mono -V 
Mono JIT compiler version 4.4.2 (Stable 4.4.2.11/f72fe45 Fri Jul 29 09:58:49 UTC 2016)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
        TLS:           __thread
        SIGSEGV:       altstack
        Notifications: epoll
        Architecture:  amd64
        Disabled:      none
        Misc:          softdebug 
        LLVM:          supported, not enabled.
        GC:            sgen
Comment 9 Gery Vessere 2016-09-14 04:08:23 UTC
same problem here with odbc connector and 4.4.2.11. Is there any planned fix for this?
Comment 10 Sasha Unknown 2016-10-24 11:25:00 UTC
Any workarounds?
Comment 11 ken.ingersoll 2017-02-06 21:00:57 UTC
Are there any workarounds yet? Or any news on a planned fix yet?
Comment 12 Régis L 2017-04-06 08:12:20 UTC
I have the same problem, I can't update to 16.04, used to work fine on 14.04.
I really need it !!
Comment 13 Egorbo 2017-04-12 20:58:27 UTC
the ODBC stuff as well as the whole System.Data is currently moving to corefx sources.
Comment 14 Ryan 2017-11-13 19:05:02 UTC
I'm also having this problem, and have not yet been able to come up with a workaround.  Using older versions of mono has been suggested, but I run into issues when attempting to install the older versions of the mod-mono package found in those snapshot repos.  This seems to be a fairly major problem that has been around for almost 2 years now.

What is the status of the port of System.Data?  And what does it mean that System.Data is currently moving to corefx sources?  Is this no longer going to be something supported in Mono and we'll need to start using the new .NET Core?  That has a number of it's own limitations that would prevent it's use for my application in particular, and I'm sure others are in the same boat.  Is this the end of ODBC support entirely?  How was it working previously, and why can't that functionality be put back in place?

Note You need to log in before you can comment on or make changes to this bug.