1

I am getting some "ref" vs "out" keyword errors using the sql-net and C# Sqlite combination for windows phone 7.1. Is this due to a wrong combination of libraries that I am using?

App Type: Windows Phone 7.1

Using:

  1. sql-net Version 1.0.5, Source Nuget thru Visual Studio
  2. C# Sqlite for WP7 (wp7sqlite) ( Community.CSharpSqlite.WP7) Version 0.1.1, Source Nuget thru Visual Studio.

The exact error I receive is below

Error 5 The best overloaded method match for Community.CsharpSqlite.Sqlite3.sqlite3_open(string, ref Community.CsharpSqlite.Sqlite3.sqlite3)' has some invalid arguments C:\Dev\Learning\SQLite.cs Line:2492 Column: 29

The next error then hints that it is related to the parameter being passed as "out" type instead of "ref" type.

Error 6 Argument 2 must be passed with the 'ref' keyword C:\Dev\Learning\SQLite.cs Line: 2492 Column: 64

I can make the compile errors go away by replacing the "out" keyword with the "ref" keyword, but that is likely to lead to other issues. Given that I do not see much complain about this issue - I may be doing something wrong but not able to detect easily.

j0k
  • 22,600
  • 28
  • 79
  • 90
param
  • 13
  • 5

2 Answers2

2

The parameter was changed in csharp-sqlite (optionally(?) used by sqlite-net) between 3.7.6.3 and 3.7.7.1 from ref to out, see this commit (look for line 2692).

If you don't want to update your code, you will need to use the newer version of csharp-sqlite. You probably don't see many questions about this because you're one of the few using an older version for whatever reason.

  • Thanks. That explains the core of the problem I faced. The version of sql-net released thru NuGet has not been updated to match the C# Sqlite released thru NuGet. Given the high usage, I was not expecting that. Checking the latest source code for sql-net: It still has not been updated for these changes from CSharp-Sqlite. I will follow up with the developers of sql-net. – param Nov 26 '12 at 12:00
  • @param Ah, yuck, it looks like http://wp7sqlite.codeplex.com/ is based on an old version of http://code.google.com/p/csharp-sqlite/, and and sqlite-net uses the latter. Misleadingly, the http://wp7sqlite.codeplex.com/ code is what's available on NuGet as csharpsqlite. –  Nov 26 '12 at 12:47
0

Following method signature

Community.CsharpSqlite.Sqlite3.sqlite3_open(string, ref Community.CsharpSqlite.Sqlite3.sqlite3)

Clearly states that 2nd argument is passed by reference (ref)

so, when calling this method use ref keyword instead of out.

Here also you'll find a lot of info:

Difference between ref and out parameters in .NET

Community
  • 1
  • 1
Azodious
  • 13,752
  • 1
  • 36
  • 71
  • Its probably also worth adding that if it really is important to call it with `out` instead of `ref` that you could create some kind of wrapper function that has the same signature except with `out`... I am not sure I can see what problems this could cause though so wouldn't have thought it was necessary... – Chris Nov 26 '12 at 10:21
  • @Azodious Thanks for the quick response. As you suggested and I had stated, I can make those errors go away by replacing out with ref keyword. **But that code is from open source (sql-net) and has been in use for a while without users reporting this issue**. – param Nov 26 '12 at 10:36
  • if it was compiling before, that means `ref` was not replaced by `out`. You need to analyze more. – Azodious Nov 26 '12 at 10:53