SubSonic 抛出“System.IndexOutOfRangeException”当处于 Visual Studio 调试模式时

发布于 2024-12-09 07:29:01 字数 1678 浏览 2 评论 0原文

我最近继承了我现在拥有的产品的代码集,该产品使用 Subsonic 2.1.0 来执行其数据访问。

当我进入调试所述代码集时,我在 Visual Studio 2010 的“输出”窗口中得到的所有内容如下(对于尝试加载的每个对象的几乎每一列)

A first chance exception of type 'System.IndexOutOfRangeException' occurred in System.Data.dll

:在 Subsonic 中,它位于 SubSonic.RecordBase 类中,看起来像这样:

/// <summary>
    /// Loads the object with the current reader's values. Assumes the reader is already moved to
    /// first position in recordset (aka has been "Read()")
    /// </summary>
    /// <param name="dataReader">The data reader.</param>
    public virtual void Load(IDataReader dataReader)
    {
        foreach(TableSchema.TableColumn col in BaseSchema.Columns)
        {
            try
            {
                SetColumnValue(col.ColumnName, dataReader[col.ColumnName]);
            }
            catch(Exception)
            {
                // turning off the Exception for now
                // to support partial loads

                // throw new Exception("Unable to set column value for " + col.ColumnName + ": " + x.Message);
            }
        }

        SetLoadState();
        MarkClean();
    }

其中有问题的行是:

 SetColumnValue(col.ColumnName, dataReader[col.ColumnName]);

col.ColumnName 此时与 dataReader 中的任何内容都不匹配。这几乎就像它正在使用旧的/之前的 dataReader 来尝试从中提取数据。

我希望其他人也遇到过这个问题,因为我对 Subsonic 还很陌生,并且过去只使用 Hibernate 进行 ORM。

这种情况发生在我的旧机器和我刚刚构建的新机器上,它们都运行 Windows 7 Professional x64,并使用 Visual Studio 2010 Professional 作为 IDE。

我浏览了论坛、谷歌和许多其他网站,但尚未发现其他人遇到此问题。

如果需要更多信息,请告诉我,我很乐意发帖!

提前致谢!

  • 贾斯汀

I recently inherited the code set for a Product I now own which uses Subsonic 2.1.0 to perform its data-access.

When I go in to debug said code set, all that I get in the Output window of Visual Studio 2010 is the following (for pretty much every column of every object trying to be loaded):

A first chance exception of type 'System.IndexOutOfRangeException' occurred in System.Data.dll

This is the block of code where it is blowing up in Subsonic, which is located in the SubSonic.RecordBase class, which looks like so:

/// <summary>
    /// Loads the object with the current reader's values. Assumes the reader is already moved to
    /// first position in recordset (aka has been "Read()")
    /// </summary>
    /// <param name="dataReader">The data reader.</param>
    public virtual void Load(IDataReader dataReader)
    {
        foreach(TableSchema.TableColumn col in BaseSchema.Columns)
        {
            try
            {
                SetColumnValue(col.ColumnName, dataReader[col.ColumnName]);
            }
            catch(Exception)
            {
                // turning off the Exception for now
                // to support partial loads

                // throw new Exception("Unable to set column value for " + col.ColumnName + ": " + x.Message);
            }
        }

        SetLoadState();
        MarkClean();
    }

The offending line in there is:

 SetColumnValue(col.ColumnName, dataReader[col.ColumnName]);

col.ColumnName doesn't match anything in the dataReader at this point. It's almost like it's using an old/prior dataReader to attempt to pull data from.

I'm hoping someone else has encountered this issue, as I'm still fairly new to Subsonic and have only used Hibernate in the past for an ORM.

This happens on both my older machine and a new one I just built, both running Windows 7 Professional x64 w/ Visual Studio 2010 Professional as the IDE.

I've gone through the forums, Google, and many other sites out there, but have yet to find anyone else encountering this issue.

If more information is required, please let me know and I'll be happy to post!

Thanks in advance!

  • Justin

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

執念 2024-12-16 07:29:01

在花了一段时间研究这个问题之后,我意识到,当仅从数据库检索某些字段并将其映射到数据对象本身时,为了“部分加载”数据对象,它故意抛出这些异常。 (例如,如果无法正确映射列的数据,则只是抑制异常本身并恢复。

不确定这是否最初是 SubSonic 代码的一部分,还是我之前的人引入的内容。

再次感谢!

贾斯汀

After spending a while longer looking into this issue, I've realized that it's intentionally throwing these Exceptions for the sake of "partially loading" a data object when only certain fields are being retrieved from the database and mapped to the data object itself. (e.g. just supresses the Exceptions itself and resumes if it can't map a column's data properly.

Not sure if this was originally part of the SubSonic code or something that was introduced by those before me.

Thanks again!

Justin

望喜 2024-12-16 07:29:01

自上次创建 SubSonic 对象以来,数据库架构似乎已发生更改。

It looks like the DB Schema may have changed since the SubSonic objects where last created.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文