14 Replies Latest reply on Oct 10, 2019 10:41 AM by 5abee375-bef1-450a-82dd-19fc4b8e1869

    Object Referenced Not Set to an instance of an Object (in docker only)

    Ryan Sites

      I am using Nuget Package Oracle.ManagedDataAccess.Core 2.18.5 in a Asp.Net Core web api. I am able to run fine locally from both Windows and Mac machine.

       

      Inside my docker image however, I am unable to connect to Oracle database.

       

      I keep getting the following stack trace :

      Error occured while calling  PR CreateNewPR(Int32, Boolean, OracleInternal.ConnectionPool.ConnectionString, Oracle.ManagedDataAccess.Client.OracleConnection, System.String, System.Collections.Generic.List`1[System.String]) Details : Object reference not set to an instance of an object.", "exception": "System.NullReferenceException: Object reference not set to an instance of an object.\n   at OracleInternal.ConnectionPool.PoolManager`3.CreateNewPR(Int32 reqCount, Boolean bForPoolPopulation, ConnectionString csWithDiffOrNewPwd, OracleConnection connRefForCriteria, String instanceName, List`1 switchFailedInstNames)\n   at OracleInternal.ConnectionPool.PoolManager`3.Get(ConnectionString csWithDiffOrNewPwd, Boolean bGetForApp, OracleConnection connRefForCriteria, String affinityInstanceName, Boolean bForceMatch)\n   at OracleInternal.ConnectionPool.OraclePoolManager.Get(ConnectionString csWithNewPassword, Boolean bGetForApp, OracleConnection connRefForCriteria, String affinityInstanceName, Boolean bForceMatch)\n   at OracleInternal.ConnectionPool.OracleConnectionDispenser`3.Get(ConnectionString cs, PM conPM, ConnectionString pmCS, SecureString securedPassword, SecureString securedProxyPassword, OracleConnection connRefForCriteria)\n   at Oracle.ManagedDataAccess.Client.OracleConnection.Open()

       

      My docker image is using the microsoft base image

      FROM microsoft/dotnet:2.1-aspnetcore-runtime
      

       

       

      Connection string is as follows

      ConnectionString = $"User Id={oracleUsername};Password={oraclePassword};Data Source= (DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = 1.2.3.4)(PORT = 1521))(CONNECT_DATA =(SERVER = DEDICATED)(SERVICE_NAME = ServiceName))); ";
      

       

       

      Fails on line 3

       

      OracleConnection connection = new OracleConnection();
      connection.ConnectionString = ConnectionString;
      connection.Open();
      

       

      Any and all help would be appreciated. Again, only happens from within docker image, and I am using latest version of nuget package!

        • 1. Re: Object Referenced Not Set to an instance of an Object (in docker only)
          Alex Keh - Product Manager-Oracle

          Is there an inner exception? The main exception is fairly generic.

           

          Also, what Windows OS version are you trying to connect from?

           

          Is the Oracle DB inside or outside the Docker instance?

           

          More than likely, we'll need an ODP.NET trace (level 7) to see at what point in the connection process the error occurs and some clues to why.

          • 2. Re: Object Referenced Not Set to an instance of an Object (in docker only)
            James Driscoll

            Hi Alex,

             

            I have been getting exactly the same issues. My local Docker image works fine, but not when I move to OpenShift.

            NB I am using version 18.6 of the package.

             

            Hopefully the following will help you dig out the exact line of code that is wrong!!

             

            Trace Level 7

            I have enabled tracing to level 7 as you suggested, and get the following (redacted) info:

            2019-03-27 12:43:58.126219 TID:12  (PRI) (ENT) (CP) PoolManager.CreateNewPRThreadFunc()
            2019-03-27 12:43:58.127176 TID:12  (PRI) (ENT) (CP) PoolManager.CreateNewPRThreadFunc() (initiated by TID:5)
            2019-03-27 12:43:58.177689 TID:12  (PRI) (SVC) (ENT) OracleConnectionImpl.Connect() (oper=open) (aff=n/a) (inst=) (affmatch=n/a) (pr.service=) (pr.pdb=) (pr.edition=) (sessid=-1:-1) (F;F;F;;N) (pmid=22933728) 
            2019-03-27 12:43:58.181179 TID:12  (PRI) (BUF) (COBP.CTOR) (poolid:1) (parentpoolid:36472305) (OracleConnectionImpl.Connect)
            2019-03-27 12:43:58.239593 TID:12  (NET) (ENT) TcpTransportAdapter.Connect()
            2019-03-27 12:43:58.252124 TID:12  (NET)      Trying (host=xxxxxxxx.yyy) (port=0000)
            2019-03-27 12:43:58.252181 TID:12  (NET) (EXT) TcpTransportAdapter.Connect()
            2019-03-27 12:43:58.259736 TID:12  (NET) (ENT) TcpTransportAdapter.ConnectIterate()
            2019-03-27 12:43:58.259989 TID:12  (NET)      Trying (address=111.111.111.111) (port=0000)
            2019-03-27 12:43:58.296548 TID:12  (PRI) (BUF) (ALLOCATION) (bufid:1)
            2019-03-27 12:43:58.627856 TID:12  (NET)      NS Handshake completed successfully
            2019-03-27 12:43:58.627889 TID:12  (NET)      Negotiated SDU size = 8192
            2019-03-27 12:43:58.637933 TID:12  (PRI) (BUF) (ALLOCATION) (bufid:3)
            2019-03-27 12:43:58.641187 TID:12  (PRI) (BUF) (OBP.GET) (poolid:36472305) (key:8192) (bufid:3) (count:0) (ConOraBufPool.Init)
            2019-03-27 12:43:58.643241 TID:12  (PRI) (BUF) (COBP.PUT) (poolid:1) (key:8192) (bufid:3) (count:1) (OracleConnectionImpl.Connect)
            2019-03-27 12:43:58.643309 TID:12  (PRI) (BUF) (ALLOCATION) (bufid:4)
            2019-03-27 12:43:58.643525 TID:12  (PRI) (BUF) (OBP.GET) (poolid:36472305) (key:8192) (bufid:4) (count:0) (ConOraBufPool.Init)
            2019-03-27 12:43:58.643649 TID:12  (PRI) (BUF) (COBP.PUT) (poolid:1) (key:8192) (bufid:4) (count:2) (OracleConnectionImpl.Connect)
            2019-03-27 12:43:58.643704 TID:12  (PRI) (BUF) (ALLOCATION) (bufid:5)
            2019-03-27 12:43:58.643824 TID:12  (PRI) (BUF) (OBP.GET) (poolid:36472305) (key:8192) (bufid:5) (count:0) (ConOraBufPool.Init)
            2019-03-27 12:43:58.643948 TID:12  (PRI) (BUF) (COBP.PUT) (poolid:1) (key:8192) (bufid:5) (count:3) (OracleConnectionImpl.Connect)
            2019-03-27 12:43:58.643980 TID:12  (PRI) (BUF) (ALLOCATION) (bufid:6)
            2019-03-27 12:43:58.644118 TID:12  (PRI) (BUF) (OBP.GET) (poolid:36472305) (key:8192) (bufid:6) (count:0) (ConOraBufPool.Init)
            2019-03-27 12:43:58.644245 TID:12  (PRI) (BUF) (COBP.PUT) (poolid:1) (key:8192) (bufid:6) (count:4) (OracleConnectionImpl.Connect)
            2019-03-27 12:43:58.644278 TID:12  (PRI) (BUF) (ALLOCATION) (bufid:7)
            2019-03-27 12:43:58.644454 TID:12  (PRI) (BUF) (OBP.GET) (poolid:36472305) (key:8192) (bufid:7) (count:0) (ConOraBufPool.Init)
            2019-03-27 12:43:58.644590 TID:12  (PRI) (BUF) (COBP.PUT) (poolid:1) (key:8192) (bufid:7) (count:5) (OracleConnectionImpl.Connect)
            2019-03-27 12:43:58.644624 TID:12  (PRI) (BUF) (ALLOCATION) (bufid:8)
            2019-03-27 12:43:58.644759 TID:12  (PRI) (BUF) (OBP.GET) (poolid:36472305) (key:8192) (bufid:8) (count:0) (ConOraBufPool.Init)
            2019-03-27 12:43:58.644878 TID:12  (PRI) (BUF) (COBP.PUT) (poolid:1) (key:8192) (bufid:8) (count:6) (OracleConnectionImpl.Connect)
            2019-03-27 12:43:58.644911 TID:12  (PRI) (BUF) (ALLOCATION) (bufid:9)
            2019-03-27 12:43:58.645036 TID:12  (PRI) (BUF) (OBP.GET) (poolid:36472305) (key:8192) (bufid:9) (count:0) (ConOraBufPool.Init)
            2019-03-27 12:43:58.645159 TID:12  (PRI) (BUF) (COBP.PUT) (poolid:1) (key:8192) (bufid:9) (count:7) (OracleConnectionImpl.Connect)
            2019-03-27 12:43:58.645205 TID:12  (PRI) (BUF) (ALLOCATION) (bufid:10)
            2019-03-27 12:43:58.645339 TID:12  (PRI) (BUF) (OBP.GET) (poolid:36472305) (key:8192) (bufid:10) (count:0) (ConOraBufPool.Init)
            2019-03-27 12:43:58.645496 TID:12  (PRI) (BUF) (COBP.PUT) (poolid:1) (key:8192) (bufid:10) (count:8) (OracleConnectionImpl.Connect)
            2019-03-27 12:43:58.656861 TID:12  (PRI) (BUF) (COBP.GET) (poolid:1) (key:8192) (bufid:10) (count:7) (OraBufWriter.Initialize)
            2019-03-27 12:43:58.662915 TID:12  (PRI) (SVC) (ENT) OracleConnectionImpl.DoProtocolNegotiation()
            2019-03-27 12:43:58.664293 TID:12  (PRI) (TTC) (ENT) TTCProtocolNegotiation.WriteMessage()
            2019-03-27 12:43:58.665139 TID:12  (PRI) (TTC) (ENT) TTCMessage.WriteTTCCode()
            2019-03-27 12:43:58.665900 TID:12  (PRI) (TTC) (EXT) TTCMessage.WriteTTCCode()
            2019-03-27 12:43:58.667044 TID:12  (PRI) (TTC) (EXT) TTCProtocolNegotiation.WriteMessage()
            2019-03-27 12:43:58.698942 TID:12  (PRI) (TTC) (ENT) TTCProtocolNegotiation.ReadResponse()
            2019-03-27 12:43:58.703051 TID:12  (PRI) (BUF) (COBP.GET) (poolid:1) (key:8192) (bufid:9) (count:6) (OraBufReader.GetDataFromNetwork)
            2019-03-27 12:43:58.773962 TID:12  (PRI) (TTC) (EXT) TTCProtocolNegotiation.ReadResponse()
            2019-03-27 12:43:58.774141 TID:12  (PRI) (SVC) DoProtocolNegotiation : ServerCharSet = 31, ServerNCharSet = 871, ServerFlags: 1
            2019-03-27 12:43:58.799651 TID:12  (PRI) (SVC) After Charset Negotiation : ServerCharSet = 31, ServerNCharSet = 871, NetworkCharSet = 31, ServerConvFlags: 3, Network CHARSET  MaxBytesPerChar = 1
            2019-03-27 12:43:58.799734 TID:12  (PRI) (SVC) (EXT) OracleConnectionImpl.DoProtocolNegotiation()
            2019-03-27 12:43:58.802586 TID:12  (PRI) (SVC) (ENT) OracleConnectionImpl.DoDataTypeNegotiation()
            2019-03-27 12:43:58.807355 TID:12  (PRI) (TTC) (ENT) TTCMessage.WriteTTCCode()
            2019-03-27 12:43:58.807459 TID:12  (PRI) (TTC) (EXT) TTCMessage.WriteTTCCode()
            2019-03-27 12:43:58.847667 TID:12  (PRI) (SVC) (EXT) OracleConnectionImpl.DoDataTypeNegotiation()
            2019-03-27 12:43:58.850624 TID:12  (PUB) (ENT) OracleIntervalDS.ctor()
            2019-03-27 12:43:58.854176 TID:12  (PUB) (ENT) OracleIntervalDS.ctor()
            2019-03-27 12:43:58.854264 TID:12  (PUB) (EXT) OracleIntervalDS.ctor()
            2019-03-27 12:43:58.854312 TID:12  (PUB) (ENT) OracleIntervalDS.ctor()
            2019-03-27 12:43:58.854429 TID:12  (PUB) (EXT) OracleIntervalDS.ctor()
            2019-03-27 12:43:58.854464 TID:12  (PUB) (ENT) OracleIntervalDS.ctor()
            2019-03-27 12:43:58.854491 TID:12  (PUB) (EXT) OracleIntervalDS.ctor()
            2019-03-27 12:43:58.854521 TID:12  (PUB) (EXT) OracleIntervalDS.ctor()
            2019-03-27 12:43:58.861252 TID:12  (PRI) (SVC) (ENT) OracleConnectionImpl.DoAuthentication()
            2019-03-27 12:43:58.886991 TID:12  (PRI) (ENT) OracleConnectionImpl.DoAuthentication()
            2019-03-27 12:43:58.906666 TID:12  (PRI) (SVC) (ERR) OracleConnectionImpl.DoAuthentication() (txnid=n/a) System.NullReferenceException: Object reference not set to an instance of an object.
               at OracleInternal.TTC.TTCAuthenticate..ctor(MarshallingEngine marshallingEngine, Int32 lcid)
               at OracleInternal.ServiceObjects.OracleConnectionImpl.get_AuthenticateObject()
               at OracleInternal.ServiceObjects.OracleConnectionImpl.DoAuthentication(String userId, SecureString securePassword, String proxyUserId, SecureString secureProxyPassword, SecureString secureNewPassword, Boolean bDoExternalAuth, Boolean bOpenEndUserSession)
            2019-03-27 12:43:58.906783 TID:12  (PRI) (EXT) OracleConnectionImpl.DoAuthentication()
            2019-03-27 12:43:58.907055 TID:12  (PRI) (SVC) (EXT) OracleConnectionImpl.DoAuthentication()
            2019-03-27 12:43:58.907207 TID:12  (PRI) (ENT) OracleConnectionImpl.Connect()
            2019-03-27 12:43:58.907528 TID:12  (PRI) (SVC) (ERR) OracleConnectionImpl.Connect() (txnid=n/a) System.NullReferenceException: Object reference not set to an instance of an object.
               at OracleInternal.TTC.TTCAuthenticate..ctor(MarshallingEngine marshallingEngine, Int32 lcid)
               at OracleInternal.ServiceObjects.OracleConnectionImpl.get_AuthenticateObject()
               at OracleInternal.ServiceObjects.OracleConnectionImpl.DoAuthentication(String userId, SecureString securePassword, String proxyUserId, SecureString secureProxyPassword, SecureString secureNewPassword, Boolean bDoExternalAuth, Boolean bOpenEndUserSession)
               at OracleInternal.ServiceObjects.OracleConnectionImpl.Connect(ConnectionString cs, Boolean bOpenEndUserSession, OracleConnection connRefForCriteria, String instanceName)
            2019-03-27 12:43:58.907599 TID:12  (PRI) (EXT) OracleConnectionImpl.Connect()
            2019-03-27 12:43:58.907748 TID:12  (PRI) (SVC) (EXT) OracleConnectionImpl.Connect() (oper=open) (aff=n/a) (inst=) (affmatch=n/a) (pr.service=) (pr.pdb=) (pr.edition=) (sessid=-1:-1) (F;F;F;;N) (pmid=22933728) 
            2019-03-27 12:43:58.907983 TID:12  (PRI) (EXT) (CP) PoolManager.CreateNewPRThreadFunc()
            

             

            Our Hypothesis

            Our experience is that this is because OpenShift is setting up users with arbitary IDs

            https://docs.openshift.com/container-platform/3.9/creating_images/guidelines.html#openshift-specific-guidelines has some interesting notes under "Support Arbitrary User IDs":

            Because the user ID of the container is generated dynamically, it will not have an associated entry in /etc/passwd. This can cause problems for applications that expect to be able to look up their user ID. One way to address this problem is to dynamically create a passwd file entry with the container’s user ID as part of the image’s start script.

             

            Related reading: Can't connect with ODP.Net Core Beta 3

             

            Original Docker File

            Our original docker file looked like this:

             

            # This is a multistage docker build
            # The first "sdk" image provides a "clean" build environment (named "build-env") - this does the heavy work of building the application
            FROM microsoft/dotnet:2.2.104-sdk as build-env
            WORKDIR /app
            
            # To make use of caching, and therefore make builds faster we'll copy the .sln and .csproj files, then do a dotnet restore.
            # Since we're likely to change the code more often than the packages we'll be able to reuse the cached layers,
            # ie, no need to restore the packages again unless they change!
            COPY ./*.sln ./*.Config ./**/*.csproj ./
            
            # Then within a RUN command to copy them to the right folders.
            RUN for file in $(ls *.csproj); do mkdir -p ${file%.*}/ && mv $file ${file%.*}/; done \
                && dotnet restore --configfile ./Nuget.Config
            
            # Copy all the source code across
            COPY . .
            
            # Run the tests in a separate container
            #FROM build-env as testrunner
            #WORKDIR /app/Walrus.Test
            #RUN dotnet test -c Release --no-restore --logger:"nunit;"
            
            FROM build-env as publish
            WORKDIR /app
            RUN dotnet publish "./Walrus/Walrus.csproj" --configuration Release --output ../output
            
            # The "runtime" image is built based on the output of the intermediate "publish" image and only contains the built application
            FROM microsoft/dotnet:2.2.2-aspnetcore-runtime
            WORKDIR /app
            COPY --from=publish /app/output ./
            #COPY --from=testrunner /app/Walrus.Test/TestResults/TestResults.xml ./test/Test.Results.xml
            ENTRYPOINT ["dotnet", "Walrus.dll"]
            
            

             

            Workaround

            To fix this we now have a script file "uid_entrypoint":

            #!/bin/sh
            if ! whoami &> /dev/null; then
              if [ -w /etc/passwd ]; then
                echo "${USER_NAME:-default}:x:$(id -u):0:${USER_NAME:-default} user:${HOME}:/sbin/nologin" >> /etc/passwd
              fi
            fi
            exec "$@"
            

             

            Then our dockerfile becomes:

             

            # This is a multistage docker build
            # The first "sdk" image provides a "clean" build environment (named "build-env") - this does the heavy work of building the application
            FROM microsoft/dotnet:2.2.104-sdk as build-env
            WORKDIR /app
            
            # To make use of caching, and therefore make builds faster we'll copy the .sln and .csproj files, then do a dotnet restore.
            # Since we're likely to change the code more often than the packages we'll be able to reuse the cached layers,
            # ie, no need to restore the packages again unless they change!
            COPY ./*.sln ./*.Config ./**/*.csproj ./
            
            # Then within a RUN command to copy them to the right folders.
            RUN for file in $(ls *.csproj); do mkdir -p ${file%.*}/ && mv $file ${file%.*}/; done \
                && dotnet restore --configfile ./Nuget.Config
            
            # Copy all the source code across
            COPY . .
            
            # Run the tests in a separate container
            #FROM build-env as testrunner
            #WORKDIR /app/Walrus.Test
            #RUN dotnet test -c Release --no-restore --logger:"nunit;"
            
            FROM build-env as publish
            WORKDIR /app
            RUN dotnet publish "./Walrus/Walrus.csproj" --configuration Release --output ../output
            
            # The "runtime" image is built based on the output of the intermediate "publish" image and only contains the built application
            FROM microsoft/dotnet:2.2.2-aspnetcore-runtime
            WORKDIR /app
            ENV PATH=/app:${PATH} HOME=/app
            COPY uid_entrypoint .
            RUN chmod -R u+x /app && \
                chgrp -R 0 /app && \
                chmod -R g=u /app /etc/passwd
            COPY --from=publish /app/output ./
            #COPY --from=testrunner /app/Walrus.Test/TestResults/TestResults.xml ./test/Test.Results.xml
            USER 10001
            WORKDIR /app
            ENTRYPOINT ["uid_entrypoint"]
            CMD ["dotnet", "Walrus.dll"]
            

             

            This works in OpenShift, but not in local Docker!! It also creates other issues in OpenShift that we need to try and solve (but don't want to!!).

            So we really don't want to be using this workaround for long - so I do hope we can get a resolution to this published quickly!!

             

            Best regards,

             

            James

            • 3. Re: Object Referenced Not Set to an instance of an Object (in docker only)
              Christian.Shay -Oracle

              Hi Ryan,

              I'm not able to reproduce this error with a simple test case. Maybe you can figure out what is different.

               

              1) I am using Windows 10 with latest Docker for Windows installed (but enabling docker for linux via the menu)

              2) I'm using the latest VS 2017

              3) I'm creating a .NET Core project, Empty type, Docker for Linux enabled, disable HTTPs (Note that the dockerfile it creates is using microsoft/dotnet:2.1-aspnetcore-runtime

              4) I go to nuget and add ODP.NET core 18.6

              5) I add some simple connect code and add an exception handler to print out any error I get

              6) Run the project (run without debugging), it opens the webpage and connects and selects successfully.

               

              Hi James,

              Kubernetes issues are beyond the scope of this forum I am afraid. See if you can reproduce it without involving Kubernetes.

              • 4. Re: Object Referenced Not Set to an instance of an Object (in docker only)
                James Driscoll

                Hi Christian,

                 

                Disappointment

                Firstly, this response is so disappointing on so many levels. I have taken considerable time to help diagnose the issue, and given you nearly all the clues you need to see what is going on, yet all I get back is "it works for me!".

                Christian.Shay -Oracle wrote:

                 

                Hi James,

                Kubernetes issues are beyond the scope of this forum I am afraid. See if you can reproduce it without involving Kubernetes.

                So what is the scope of this forum then? The only thing I can see is ODP.NET. That being the case and given that Oracle's cloud provisions include Kubernetes, why is Docker OK, but Kubernetes not?

                Suspected Difference Between Your Setup and Ryan

                Christian.Shay -Oracle wrote:

                 

                Hi Ryan,

                I'm not able to reproduce this error with a simple test case. Maybe you can figure out what is different.

                 

                1) I am using Windows 10 with latest Docker for Windows installed (but enabling docker for linux via the menu)

                My guess is that you are using Docker under Windows, and that Ryan is using Docker on his Mac - he mentions running this natively on both Windows and Mac.

                NB it works for me under Windows - unfortunately, I don't have a Mac to prove the point.

                Further Hypothesis

                So let me hypothesize about this further. Let's start with things I know about:

                 

                1. Our evidence shows that this works with Docker under Windows
                2. Our evidence shows this doesn't work under Kubernetes unless the user actually exists in the /etc/passwd file
                3. Within an Oracle database, you can run this SQL to get the Operating System Username: Select Sys_Context( 'userenv', 'os_user' ) From Dual;

                Back to some assumptions:

                1. The only way that the database can get the OS_USER is if the client passes it in
                2. The sensible place for that to occur would be on connection
                3. From a .NET perspective, Environment.UserName would seem like a sensible place to get this

                So, taking this further, I wrote a sample application with the following for Program.cs:

                    public class Program
                    {
                        public static void Main(string[] args)
                        {
                            WriteConsoleValue(nameof(Environment.UserName), Environment.UserName);
                            CreateWebHostBuilder(args).Build().Run();
                        }
                
                
                        private static void WriteConsoleValue(string description, string text)
                        {
                            Console.Write(description);
                            Console.Write(": ");
                            if (text == null)
                            {
                                Console.WriteLine("*Null*");
                            }
                            else
                            {
                                Console.WriteLine(text);
                            }
                        }
                
                
                        public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
                            WebHost.CreateDefaultBuilder(args)
                                .UseUrls("http://*:8080")
                                .UseStartup<Startup>();
                
                
                
                
                
                
                
                
                   
                

                 

                So here's what I get in the different scenarios:

                EnvironmentResult
                Docker for WindowsUserName: root
                Kubernetes with original dockerfileUserName: *Null*
                Kubernetes with new dockerfileUserName: default

                 

                The Smoking Gun

                So let's look at the Microsoft Documentation for Environment.UserName. In the remarks, we see:

                 

                On Unix platforms the UserName property wraps a call to the getpwuid_r function.

                 

                So let's look at the documentation for that. And this is what we see:

                Name

                getpwnam, getpwnam_r, getpwuid, getpwuid_r - get password file entry

                [...]

                Description

                The getpwnam() function returns a pointer to a structure containing the broken-out fields of the record in the password database (e.g., the local password file /etc/passwd, NIS, and LDAP) that matches the username name.

                [...]

                Return Value

                The getpwnam() and getpwuid() functions return a pointer to a passwd structure, or NULL if the matching entry is not found or an error occurs.

                Wager

                So given all of the above let's look at my original trace:

                2019-03-27 12:43:58.906666 TID:12  (PRI) (SVC) (ERR) OracleConnectionImpl.DoAuthentication() (txnid=n/a) System.NullReferenceException: Object reference not set to an instance of an object.  
                   at OracleInternal.TTC.TTCAuthenticate..ctor(MarshallingEngine marshallingEngine, Int32 lcid)  
                   at OracleInternal.ServiceObjects.OracleConnectionImpl.get_AuthenticateObject()  
                   at OracleInternal.ServiceObjects.OracleConnectionImpl.DoAuthentication(String userId, SecureString securePassword, String proxyUserId, SecureString secureProxyPassword, SecureString secureNewPassword, Boolean bDoExternalAuth, Boolean bOpenEndUserSession)  
                

                 

                I would be happy to wager a considerable proportion of my annual salary that within OracleConnectionImpl.DoAuthentication you retrieve Environment.UserName in order to pass it across to Oracle such that it has an OS_USER. I then expect that you probably then assume that it will not be null. My guess is that you need to do some sort of encoding based on the length of the string, and may even do something along the lines of Environment.UserName.Length - thereby causing the NullReferenceException.

                 

                I hope this gives you enough information to finally track down the problem and get us a swift resolution!

                 

                Best regards,

                 

                James

                • 5. Re: Object Referenced Not Set to an instance of an Object (in docker only)
                  Christian.Shay -Oracle

                  James, Ryan,

                   

                  Are you connecting to Oracle database with a username and password? Are you using "OS Authentication" (where that is not needed)?. If so, can you please try passing in an explicit user/pass and see if that works?

                   

                  Please also tell us the full version of Linux you are using (eg the host OS where this is crashing).

                   

                  Thanks,

                  Christian

                  • 6. Re: Object Referenced Not Set to an instance of an Object (in docker only)
                    James Driscoll

                    Hi Christian,

                     

                    I have tried connecting using the following formats:

                     

                    1. "User ID=username;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(Host=host)(Port=port)))(CONNECT_DATA=(SID=sid)));Password=password"
                    2. "User ID=username;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(Host=host)(Port=port)))(CONNECT_DATA=(SERVICE_NAME=service_name)));Password=password"
                    3. "User ID=username;Data Source=host:port/service_name;Password=password"

                    ... and experienced the same issues with each.

                     

                    With regards to versions:

                     

                     cat /etc/os-release
                    PRETTY_NAME="Debian GNU/Linux 9 (stretch)"
                    NAME="Debian GNU/Linux"
                    VERSION_ID="9"
                    VERSION="9 (stretch)"
                    ID=debian
                    HOME_URL="https://www.debian.org/"
                    SUPPORT_URL="https://www.debian.org/support"
                    BUG_REPORT_URL="https://bugs.debian.org/"
                    $ uname -r
                    3.10.0-957.1.3.el7.x86_64
                    

                     

                    Have you had any joy looking into Environment.UserName?

                    Best regards,

                     

                    James

                    • 7. Re: Object Referenced Not Set to an instance of an Object (in docker only)
                      James Driscoll

                      Hi again,

                       

                      Any news on how Environment.UserName is affecting this?

                      I would be happy to trial a debug or patch version of the .DLL if that will help identify / fix problems!

                       

                      Kind regards,

                       

                      James

                      • 8. Re: Object Referenced Not Set to an instance of an Object (in docker only)
                        James Driscoll

                        Hi Alex / Christian,

                         

                        Any update on this one please?

                         

                        Thanks,

                         

                        James

                        • 9. Re: Object Referenced Not Set to an instance of an Object (in docker only)
                          Christian.Shay -Oracle

                          Hi James,

                          Unfortunately we currently only support ODP.NET Core on the following flavors of Linux:

                           

                          1) Oracle Linux 7

                          2) Red Hat Enterprise Linux 7

                           

                          https://docs.oracle.com/en/database/oracle/oracle-data-access-components/18.3/odpnt/InstallSystemRequirements.html#GUID-…

                           

                          We will gradually expand this list to include additional flavors, but for now, if you are doing this for a work project, you should use one of those two.

                          • 10. Re: Object Referenced Not Set to an instance of an Object (in docker only)
                            James Driscoll

                            Hi Christian,

                             

                            That being the case, we will demonstrate the same problem on RHEL7 and get back to you (probably next week now).

                            FWIW, I still believe that you have issues with Environment.UserName

                             

                            Regards,

                             

                            James

                            • 11. Re: Object Referenced Not Set to an instance of an Object (in docker only)
                              Christian.Shay -Oracle

                              Thanks James. If you do continue to see the problem using Red Hat, please also try to reproduce it outside of Kubernetes.

                              • 12. Re: Object Referenced Not Set to an instance of an Object (in docker only)
                                6e455d0c-6d8e-4a90-b828-8fcf725b3339

                                Hi, I have the same problem, and I aplyed a temporary fix this way:

                                 

                                int i = 4, iw = 10;

                                do

                                {

                                try

                                {

                                RecNum = db.ExecuteProc("PASSENGER_PACK.add_psg2export", dbParams.ToArray());

                                }

                                catch (Exception ex)

                                {

                                Thread.Sleep(1000 * iw);

                                }

                                break;

                                } while (i-- > 0);

                                I also use timeout, this way:

                                 

                                Task t = Task.Run( () => {

                                db.ExecuteProc("PASSENGER_PACK.add_psg2export", dbParams.ToArray());

                                } );

                                if (! t.Wait(TimeSpan.FromMilliseconds(15000)))

                                   Console.WriteLine("The timeout interval elapsed.");

                                • 13. Re: Object Referenced Not Set to an instance of an Object (in docker only)
                                  826caa6d-eb8f-487d-b1e2-92ca37489698

                                  Big Kudos to Ryan Sites and James Driscoll. We ran into the same problem on RHEL7 and your detailed analysis and workaround description helped me a lot.

                                   

                                  The error occured when we changed the base image of our build pipeline from the default microsoft image to this puppy:

                                   

                                  registry.access.redhat.com/dotnet/dotnet-22-runtime-rhel7

                                  https://access.redhat.com/containers/#/registry.access.redhat.com/dotnet/dotnet-22-runtime-rhel7

                                   

                                  This image is running on an Red Hat OpenShift cluster and all our Oracle connections were no longer possible due to an internal NullReferenceException. Adding the missing entry to the /etc/passwd file helped to fix the problem. I am not quite sure for what reasons the Oracle connections requires the username when credentials are provided. However, it shouldn't fail because of that.

                                  • 14. Re: Object Referenced Not Set to an instance of an Object (in docker only)
                                    5abee375-bef1-450a-82dd-19fc4b8e1869

                                    I've had the same issue running in Kubernetes using Helm and resolved it by removing securityContext set in deployment.yaml of the Helm chart.