Here is my basic situation. I'm trying to use NHibernate to get information from a database, create some objects based off the mappings, serialize, them, and the move the serialized object on to a flash component. No build errors are going off, but when I return the 'serialized' object it keeps returning null. Upon inserting some breakpoints and stepping through, I realized where everything was going south.

I put my break point in here:

var tasks = (List<CSH_Task>)persistanceManager.RetrieveAll<CSH_Task>(SessionAction.BeginAndEnd);

And it goes into my PersistanceManager class, successfully passing my CSH_Task:

public IList<T> RetrieveAll<T>(SessionAction sessionAction)
    {
        /* Note that NHibernate guarantees that two object references will point to the
         * same object only if the references are set in the same session. For example,
         * Order #123 under the Customer object Able Inc and Order #123 in the Orders
         * list will point to the same object only if we load Customers and Orders in 
         * the same session. If we load them in different sessions, then changes that
         * we make to Able Inc's Order #123 will not be reflected in Order #123 in the
         * Orders list, since the references point to different objects. That's why we
         * maintain a session as a member variable, instead of as a local variable. */

        // Open a new session if specified
        if ((sessionAction == SessionAction.Begin) || (sessionAction == SessionAction.BeginAndEnd))
        {
            m_Session = m_SessionFactory.OpenSession();
        }

        // Retrieve all objects of the type passed in
        ICriteria targetObjects = m_Session.CreateCriteria(typeof(T));
        IList<T> itemList = targetObjects.List<T>();

        // Close the session if specified
        if ((sessionAction == SessionAction.End) || (sessionAction == SessionAction.BeginAndEnd))
        {
            m_Session.Close();
            m_Session.Dispose();
        }

        // Set return value
        return itemList;
    }

Which is straight from an older example of NHibernate(I'm extremely new to it) And it drops me into a "No Source Available" Page, which lists this

Call stack location:

Iesi.Collections.DLL!Iesi.Collections.Generic.HashedSet.HashedSet() Line 18

Source file information:

Locating source for 'd:\CSharp\NH\NH_Hg\nhibernate\src\Iesi.Collections\Generic\HashedSet.cs'. Checksum: MD5 {d3 1c 6c 95 94 c0 cb d4 b5 8d 8c 42 c5 4a 37 b2}

The file 'd:\CSharp\NH\NH_Hg\nhibernate\src\Iesi.Collections\Generic\HashedSet.cs' does not exist.

Looking in script documents for 'd:\CSharp\NH\NH_Hg\nhibernate\src\Iesi.Collections\Generic\HashedSet.cs'...

Looking in the projects for 'd:\CSharp\NH\NH_Hg\nhibernate\src\Iesi.Collections\Generic\HashedSet.cs'.

The file was not found in a project.

Looking in directory 'C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\crt\src\'...

Looking in directory 'C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\atlmfc\src\mfc\'...

Looking in directory 'C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\atlmfc\src\atl\'...

Looking in directory 'C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\atlmfc\include\'... Looking in directory 'C:\Users\tackiean\Desktop\'...

Looking in directory 'E:\SmartMC\NHibernate\Required_Bins\'...

Source was found at 'E:\SmartMC\NHibernate\Required_Bins\HashedSet.cs'.

Determining whether the checksum matches for the following locations:

1:E:\SmartMC\NHibernate\Required_Bins\HashedSet.cs Checksum: MD5 {40 1b 39 7e 8f 4a 3f 6 11 41 88 70 9e 8f 8 f1} Checksum doesn't match.

The debug source files settings for the active solution indicate that the debugger will not ask the user to find the file: d:\CSharp\NH\NH_Hg\nhibernate\src\Iesi.Collections\Generic\HashedSet.cs.

The debugger could not locate the source file 'd:\CSharp\NH\NH_Hg\nhibernate\src\Iesi.Collections\Generic\HashedSet.cs'.

If I keep stepping through it returns to my code, then back here listing a virtually identical message about DictionarySet.cs

I am not the one who downloaded NHibernate for this project on this machine in the first place, but I would have imagined that if HashedSet.cs/DictionarySet.cs were required for it to work, they would have been included by default no? I've spent the last about 7 hours today looking for answer to this, but am coming up empty. I have never seen an error like this before. I think its just looking for a file that NHibernate needs, and can't find, but is something else going on here? Any help would be sorely appreciated. I hope this an appropriate location/formatted legibly; I've never asked a question on here before so I hope it's not completely inappropriate.

有帮助吗?

解决方案

HashedSet and DictionarySet are part of Iesi.Collections, a collection library included with NHibernate. The binary package of NHibernate usually includes the .pdb files, that contain the debug information of the assemblies. When the debugger wants to open the source files, it can't find them on your machine, because the included source paths are that of the package maintainers.

If you wish to, you can download the NHibernate sources at GitHub and compile the assemblies by yourself. Then the debugger will automatically find the source files, when an exception occurs (do not move the source files after compilation).

You should modify your RetrieveAll method a bit, because you have to always open a session and close it somewhere. Normally, you do something like:

using (ISession sess = factory.OpenSession())
using (ITransaction tx = sess.BeginTransaction())
{
    try
    {
        var crit = sess.CreateCriteria<T>();
        var list = crit.List<T>();

        // Do something with list

        tx.Commit();
    }
    catch (Exception)
    {
        tx.Rollback();
    }
}

If you want to return the queried list to the caller, the session will be closed. So make sure, that there are no uninitalized lazy loading proxies left in your queried list. You may read the lazy/eager loading section in the NHibernate documentation. Hope, I could help a bit with your problem.

其他提示

The messages you see are your debugger trying to find the source code since you are stepping through it. The lack of that source code on your machine does not effect NHibernate runtime.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top