Exception message:

[NullReferenceException: Object reference not set to an instance of the object.]
   iAnywhere.Data.SQLAnywhere.SAConnection.CalledByEntityFramework() +263
   iAnywhere.Data.SQLAnywhere.SAConnection.get_ConnectionString() +538
   Dapper.Identity..ctor(String sql, Nullable`1 commandType, IDbConnection connection, Type type, Type parametersType, Type[] otherTypes) +73
   Dapper.<QueryInternal>d__13`1.MoveNext() +545
   System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) +381
   System.Linq.Enumerable.ToList(IEnumerable`1 source) +58
   Dapper.SqlMapper.Query(IDbConnection cnn, String sql, Object param, IDbTransaction transaction, Boolean buffered, Nullable`1 commandTimeout, Nullable`1 commandType) +218
   Dapper.SqlMapper.Query(IDbConnection cnn, String sql, Object param, IDbTransaction transaction, Boolean buffered, Nullable`1 commandTimeout, Nullable`1 commandType) +88

Everything works fine until sybase create fix v 12.3457 and in 16 version nothing chcanges - the same error! I look into connection object in debug. In _connStr property cinnection string is right, but in + ConnectionString I see exception message - 'cn.ConnectionString' threw an exception of type 'System.NullReferenceException' string {System.NullReferenceException}

asked 18 Mar '13, 09:24

vepr85's gravatar image

vepr85
31115
accept rate: 0%

edited 18 Mar '13, 10:47

Jeff%20Albion's gravatar image

Jeff Albion
10.8k171175

Can you provide some more details about how you're seeing this error (including any code samples required to reproduce it)? Is this error seen when trying to do a function import on Entity Framework? If so, you may be encountering CR #718762 - but this issue is fixed in SQL Anywhere 16.

(18 Mar '13, 10:45) Jeff Albion
1

I am using microOrm dapper .net for developing my site, and i did't have any problem till new EBF 3817. So after install this ebf i get error.

[NullReferenceException: Object reference not set to an instance of the object.] 
iAnywhere.Data.SQLAnywhere.SAConnection.CalledByEntityFramework() +263 
System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) +381 
...

We've found that this error because we lose string of connection.

After our investigation we've found problem in this method in Data.SQLAnywhere.v4.0.dll

// iAnywhere.Data.SQLAnywhere.SAConnection
private bool CalledByEntityFramework()
{
    string[] array = new string[]
    {
        "System.Data.Entity"
    };
    StackTrace stackTrace = new StackTrace();
    for (int i = 0; i < stackTrace.FrameCount; i++)
    {
        Type declaringType = stackTrace.GetFrame(i).GetMethod().DeclaringType;
        string[] array2 = array;
        for (int j = 0; j < array2.Length; j++)
        {
            string value = array2[j];
            //here  Exception
            if (declaringType.FullName.StartsWith(value, StringComparison.InvariantCultureIgnoreCase)) 
            {
                return true;
            }
        }
    }
    return false;
}

So you are ignory this fact that FullName can be "null" Also this problem we've found in ASA 16.0

Here is full code of my test asp.net mvc app: repository and controller

//
public class BaseDapperRepository : IDisposable
{
    protected DbConnection MDbConnection;

    private readonly ConnectionStringSettings _connectionSettings
        = ConfigurationManager.ConnectionStrings["ApplicationServices"];

    public BaseDapperRepository()
    {
        var providerFactory = DbProviderFactories.GetFactory(_connectionSettings.ProviderName);

        MDbConnection = providerFactory.CreateConnection();
        if (MDbConnection == null)
            throw new Exception("Error while creating connetion to DB");

        MDbConnection.ConnectionString = _connectionSettings.ConnectionString;
        var res = GetIds();
    }

    public dynamic GetIds()
    {
        dynamic result;
        using (MDbConnection)
        {
            MDbConnection.Open();
            const string sql = @"Vc_sp_language";
            result = MDbConnection.Query(sql, commandType: CommandType.StoredProcedure);
            MDbConnection.Close();
        }

        return result;
    }

    public void Dispose()
    {
        if(MDbConnection != null)
            MDbConnection.Dispose();
    }
}

this is the controller code

public class HomeController : Controller
{
    private BaseDapperRepository _db;

    protected override void Initialize(RequestContext requestContext)
    {
        if (_db == null)
            _db = new BaseDapperRepository();

        base.Initialize(requestContext);
    }

    public ActionResult Index()
    {
        var rep1 = _db.GetIds();        
        return View();
    }

    protected override void Dispose(bool disposing)
    {
        if (disposing)
        {
            if (_db != null)
            {
                _db.Dispose();
                _db = null;
            }
        }
        base.Dispose(disposing);
    }
}

Note that the property ConnectionString only available in the constructor and you can easily query the database:

public BaseDapperRepository()
{
    var providerFactory = DbProviderFactories.GetFactory(_connectionSettings.ProviderName);

    MDbConnection = providerFactory.CreateConnection();
    if (MDbConnection == null)
        throw new Exception("Error while creating connetion to DB");

    MDbConnection.ConnectionString = _connectionSettings.ConnectionString;
    var res = GetIds();
}
(18 Mar '13, 15:18) vepr85

Update 3: The second issue in this thread has been fixed in CR #738144, in builds 11.0.1.2976, 12.0.1.3893, 16.0.0.1524


Update 2: I have reproduced the second issue reported in this thread and have opened CR #738144 to investigate further.


Update: This issue is now fixed in CR #735130, builds 11.0.1.2957, 12.0.1.3873, and 16.0.0.1485


I concur - this seems to be a bug in our driver, specifically with generic type arguments. I have opened this issue as CR #735130.

I will update this thread as we learn more about this behaviour.

permanent link

answered 18 Mar '13, 17:00

Jeff%20Albion's gravatar image

Jeff Albion
10.8k171175
accept rate: 25%

edited 14 May '13, 07:08

Thanks a lot! Pls. Tell me where I can see this case

(19 Mar '13, 02:57) vepr85
Replies hidden

Do you have a technical support plan with us? If so, please let me know the case number and I will associate this bug fix to it and we can let you know regarding further updates. (You can e-mail me at firstname.lastname@sap.com where firstname = jeff, lastname = albion). We can also discuss the priority of the fix and any business case you may have to fix it with priority in the context of the technical support case.

See:

http://www.sybase.com/contactus/support/ (for existing Sybase Customers)

http://www.sap.com/services-and-support/support/ (for new SAP customers)

If you do not have a support plan, this bug will be fixed as resources and time allow (since this is currently submitted underneath our non-priority 'submit a bug' queue).

Thank you for the bug submission.

(19 Mar '13, 08:03) Jeff Albion

Hi. You said that this bug will be resolved in ebf 3873, but nothing has changed (.

iAnywhere.Data.SQLAnywhere.SAConnection.CalledByEntityFramework() +427

iAnywhere.Data.SQLAnywhere.SAConnection.get_ConnectionString() +1032 Dapper.Identity..ctor(String sql, Nullable1 commandType, IDbConnection connection, Type type, Type parametersType, Type[] otherTypes) +278 Dapper.<QueryInternal>d__131.MoveNext() +767 System.Collections.Generic.List1..ctor(IEnumerable1 collection) +846 System.Linq.Enumerable.ToList(IEnumerable1 source) +133 Dapper.SqlMapper.Query(IDbConnection cnn, String sql, Object param, IDbTransaction transaction, Boolean buffered, Nullable1 commandTimeout, Nullable1 commandType) +476 Dapper.SqlMapper.Query(IDbConnection cnn, String sql, Object param, IDbTransaction transaction, Boolean buffered, Nullable1 commandTimeout, Nullable`1 commandType) +340

(17 Apr '13, 08:17) vepr85

Can you test it with some test proj?

(17 Apr '13, 08:18) vepr85
Replies hidden

Not currently, no. I don't have enough information to currently understand your reproducible environment.

  • Is this only reproducible running in an ASP.NET context? On IIS 7/8? .NET Framework 4/4.5?
  • Can you confirm that 'Dapper' you're referring to is this project here: http://code.google.com/p/dapper-dot-net/source/browse/Dapper/ ?
  • Can you provide the full Dapper project code you're using, including the .Query() call?

I've never used Dapper myself, particularly on ASP.NET, so you're going to need to provide myself some easy-to-run examples for me to set up Dapper and reproduce it.

Or you can open a technical support case and we can work with you directly to ensure your particular environment and issue is addressed.

(17 Apr '13, 10:53) Jeff Albion

It's test simple project in VS 2012 asp.net mvc 4. I wrote to dapper's developers they said that bug was in SAConnection class. Yes this link for dapper - http://code.google.com/p/dapper-dot-net/source/browse/Dapper/

I've never used Dapper myself, particularly on ASP.NET, so you're going to need to provide myself some easy-to-run examples for me to set up Dapper and reproduce it.

ok - do I need place code right here or send you a project?

(17 Apr '13, 11:38) vepr85
Replies hidden

The best thing to do is to open a technical support case and we can provide direct instructions to you on how to provide us with these files.

If the code / setup instructions are very short, you can post them here and I can try to reproduce the issue when I get a chance - someone else at SAP may be able to do the same if your instructions are clear enough.

Otherwise, you can submit a project/reproduction instructions via the 'Create Bug Report Case' through the non-priority service on Case-Express and we will take a look at the issue as time allows.

(17 Apr '13, 12:48) Jeff Albion

Ok here is my code. I use simple demo db - SQL Anywhere 12 Demo and default ASP.NET.MVC 4 app + Dapper.net 1.8.0 from nuget package,sybase 12.0.1 ebf 3873, Windows 7 Ultimate sp1. I also work with mysql with dapper - works fine, no problem any version!

You need to add reference to iAnywhere.Data.SQLAnywhere.v4.0.dll and Dapper.net

web.config:

<connectionStrings>
<add name="ApplicationServices" connectionString="DSN=SQL Anywhere 12 Demo;"    providerName="iAnywhere.Data.SQLAnywhere"/>

</connectionstrings>

HomeController:

private BaseDapperRepository _db;
protected override void Initialize(RequestContext requestContext)
    {
        if(_db == null)
            _db = new BaseDapperRepository();

        base.Initialize(requestContext);
    }
public ActionResult Index()
    {
        ViewBag.Message = "Modify this template to kick-start your ASP.NET MVC application.";

        var rep1 = _db.GetIds();

        return View();
    }

BaseDapperRepository - it is class that works with db

private readonly ConnectionStringSettings _connectionSettings = ConfigurationManager.ConnectionStrings["ApplicationServices"];

       public class BaseDapperRepository : IDisposable
{
       protected DbConnection MDbConnection;
       public BaseDapperRepository()
       {
            var providerFactory = DbProviderFactories.GetFactory(_connectionSettings.ProviderName);

            MDbConnection = providerFactory.CreateConnection();
            if(MDbConnection == null)
                throw new Exception("Error while creating connetion to DB");
            MDbConnection.ConnectionString = _connectionSettings.ConnectionString;
       }
public dynamic GetIds()// test method, returns dynamic objs
       {
           dynamic result;

           using (MDbConnection)
           {

               MDbConnection.Open();

               const string sql = @"ShowCustomers";

               result = MDbConnection.Query(sql, commandType: CommandType.StoredProcedure);

               MDbConnection.Close();
           }    
           return result;
       }
public void Dispose()
        {
           MDbConnection.Dispose();
        }

}

(18 Apr '13, 05:18) vepr85
Replies hidden

I said that I' wrote to Dapper developers, here their answer:

Principally, this sounds like a bug in that specific ADO.NET implementation. The error is coming from inside a 3rd party component. The best I can suggest is: report it to them.

We use the connection-string to provide back-end specific structural caching; we know that many sites have similar (but not always the same) structures on multiple databases. The only other thing we can do is to look more at the structure itself - I'll check if we hash that currently.

So before that build(ebf 3457) iAnywhere does not loose connection string

(18 Apr '13, 11:20) vepr85

Please write answer if you try to reproduce this bug

(19 Apr '13, 17:48) vepr85

Hi! So are you going to make changes in iAnywhere.Data.SQLAnywhere.v4.0.dll for 12 version or for 16 version of iAnywhere in some next EBF update?

(05 May '13, 06:25) vepr85
1

You may have a look at the according CR description here, as Jeff has noted:

http://search.sybase.com/kbx/changerequests?bug_id=738144

Given that, the fix is contained in builds 16.0.0.1524, 12.0.1,3893 and 11.0.1.2976 and above.

(06 May '13, 03:17) Volker Barth

Thanks, so I'm wating for the new EBF(they shuold appear in the end of may?)

(08 May '13, 16:18) vepr85

The EBF will be released when it has completed our QA process - we do not offer specific dates for when EBFs will be released. You can sign up to our EBF page to be notified when a new EBF is released, or you can open a technical support case to let us know about your particular business priority for this fix and we can work with you to notify you immediately when this EBF release is ready.

(13 May '13, 13:31) Jeff Albion

Thanks, I'll be waiting for the patch

(18 May '13, 14:42) vepr85

12.0.1.3894 just got shipped for IBM AIX, HP UX and Solaris, but not Windows... since it has been over a month since the last 12.0.1 EBF for Windows, one is "due any minute now" so stay tuned.

Alas, 16.0.0.1512 just got shipped so V16 probably won't see this fix for a while.

(18 May '13, 14:53) Breck Carter

I see that the bugfix is enabled - 3895 - http://downloads.sybase.com/swd/summary.do?client=support&baseprod=144.(SQL Anywhere - Express Bug Fix, Update of 12.0.1 to build 3895 12.0.1 28 May 2013 EBF/Patch) Does this mean that my problem is fixed too?

(03 Jun '13, 14:26) vepr85

CR #738144 is fixed in 12.0.1.3893. EBFs are cumulative, so yes, this fix is included in 12.0.1.3895.

Have you tried this EBF?

(03 Jun '13, 14:31) Jeff Albion
1

Yohooo! Everything works fine! Thanks!

(04 Jun '13, 06:35) vepr85

Glad to hear that:)

FWIW, if that answer by Jeff has helped you, you're invited to mark it as accepted - cf. How do I accept an answer to my question?...

(04 Jun '13, 07:02) Volker Barth
More comments hidden
showing 5 of 20 show all flat view

In CalledByEntityFramework() the declaringType can also be null.

private bool CalledByEntityFramework()
{
    string[] strArray = new string[] { "System.Data.Entity" };
    StackTrace trace = new StackTrace();
    for (int i = 0; i < trace.FrameCount; i++)
    {
            //The declaringType variable may be null here
        Type declaringType = trace.GetFrame(i).GetMethod().DeclaringType;
        foreach (string str in strArray)
        {
            if ((declaringType.FullName != null) && declaringType.FullName.StartsWith(str, StringComparison.InvariantCultureIgnoreCase))
            {
                return true;
            }
        }
    }
    return false;
}

The function should be change as following (added a null-check for declaringType)

private bool CalledByEntityFramework()
{
    string[] strArray = new string[] { "System.Data.Entity" };
    StackTrace trace = new StackTrace();
    for (int i = 0; i < trace.FrameCount; i++)
    {
        Type declaringType = trace.GetFrame(i).GetMethod().DeclaringType;
            if (declaringType != null) {
               foreach (string str in strArray)
                {
                  if ((declaringType.FullName != null) && declaringType.FullName.StartsWith(str, StringComparison.InvariantCultureIgnoreCase))
                  {
                    return true;
                  }
                }
            }
    }
    return false;
}
permanent link

answered 24 Apr '13, 07:54

QuickLars's gravatar image

QuickLars
3112
accept rate: 0%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×438
×76
×69
×39
×19

question asked: 18 Mar '13, 09:24

question was seen: 6,666 times

last updated: 04 Jun '13, 08:57