Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling FbServerProperties.GetDatabasesInfo() generates a NullReference exception [DNET641] #599

Closed
firebird-automations opened this issue Nov 6, 2015 · 3 comments

Comments

@firebird-automations
Copy link

Submitted by: Peter Taylor (petertaylor)

The uninitialsied List<string> _databases member is used by FbDatabasesInfo.AddDatabase(string database) method [ _databases.Add(database)]

_databases IS initialised by a call to FbDatabasesInfo.Databases property - but that is too late.

Here is the offending code ( I can send a simple sample project demonstrating the issue, if required):

/\* This is the code where it goes wrong: NETProvider\\src\\FirebirdSql\.Data\.FirebirdClient\\Services\\FbDatabasesInfo\.cs

    using System;
    using System\.Collections\.Generic;

    namespace FirebirdSql\.Data\.Services
    \{
        public class FbDatabasesInfo
        \{
	        public int ConnectionCount \{ get; internal set; \}

            // this member is used before being initialised
            private List<string\> \_databases; // = new List<string\>\(\);
    #&#x2060;if \(NET\_40\)
	        public IList<string\> Databases
    #&#x2060;else
	        public IReadOnlyList<string\> Databases
    #&#x2060;endif
	        \{
		        get
		        \{
			        return \(\_databases ?? \(\_databases = new List<string\>\(\)\)\)\.AsReadOnly\(\);
		        \}
	        \}

	        internal FbDatabasesInfo\(\)
	        \{ \}

	        internal void AddDatabase\(string database\)
	        \{
                // this is where the uninitialised member is used, when FbServerProperties\.GetDatabasesInfo\(\) is called
		        \_databases\.Add\(database\);
	        \}
        \}
    \}

\*/

Commits: e94a4dd

@firebird-automations
Copy link
Author

Commented by: André Ziegler (andre.ziegler)

When I test this call in a .net 40 applciation I get a System.MissingMethodException:

ExceptionType="System.MissingMethodException" ExceptionMessage="Methode nicht gefunden: "System.Collections.Generic.IList`1<System.String> FirebirdSql.Data.Services.FbDatabasesInfo.get_Databases()"." ExceptionEIP="0x0" ExceptionHRESULT="-2.146.233.069" ExceptionFlags="CLSCompliant" ClrInstanceID="11"

looks like related to this #⁠if call:

#⁠if (NET_40)
public IList<string> Databases
#⁠else

So I can't test it

@firebird-automations
Copy link
Author

Commented by: André Ziegler (andre.ziegler)

@jiri Cincura

I checked the ETW ModuleLoad Events in WPA.exe and see that FirebirdSql.Data.FirebirdClient.dll gets loaded from GAC: C:\Windows\http://Microsoft.Net\assembly\GAC_MSIL\FirebirdSql.Data.FirebirdClient\v4.0_4.9.0.0__3750abcc3150b00c\FirebirdSql.Data.FirebirdClient.dll

This FirebirdSql.Data.FirebirdClient.dll is .net 4.5, while the project uses .net 4.0. And because the 4.5 version is loaded the Method is missing and I get the crash.

So try to avoid such #⁠if calls and use the types that are part of all versions.

@firebird-automations
Copy link
Author

Modified by: @cincuranet

status: Open [ 1 ] => Resolved [ 5 ]

resolution: Fixed [ 1 ]

Fix Version: vNext [ 10742 ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants