Problem with Nhibernate.Bytecode.Castle in MSBuild (TFS)

ぃ、小莉子 提交于 2019-12-03 16:15:29

If I recall how the bytecode assemblies work, you don't actually make a useful reference to them. That is you don't specifically use one of their classes in your code. As a result, the "smart" reference copying causes these to not be pulled in. (I might be making this up, sorry).

To deal with this you can: a) make the appropriate bytecode assembly a Copy Always content reference (meh) or b) create a silly little class (private static) that references any single class in your actual bytecode assembly (meh+1).

I'm sure there is another alternative regarding forcing the reference to be honored, but those two should be the easiest, 20 second solutions.

Had same problem, had to add reference in the class that did the Fluently.Configure.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NHibernate;
using FluentNHibernate.Cfg;
using FluentNHibernate.Automapping;
using FluentNHibernate.Conventions.Helpers;
using FluentNHibernate.Conventions;
using FluentNHibernate.Conventions.AcceptanceCriteria;
using FluentNHibernate.Conventions.Inspections;
using FluentNHibernate.Conventions.Instances;
using FluentNHibernate.MappingModel;
using FluentNHibernate;
**using NHibernate.ByteCode.Castle;**

namespace CESP_NotifyLib
{
    class SessionFactoryController
    {

        public SessionFactoryController()
        {

        }

        public ISessionFactory GiveFactory()
        {
            return CreateSessionFactory();
        }

        **private static void ReferByteCode(){

            //Just to make sure the ByteCodeCastle is loaded
            ProxyFactory fake = new ProxyFactory();
        }**

        private static ISessionFactory CreateSessionFactory()
        {
            ReferByteCode();

            var cfg = new NotifyFluentNhibernateConfiguration();

            return Fluently.Configure()
              .Database(
               FluentNHibernate.Cfg.Db.MsSqlConfiguration.MsSql2005
                    .ConnectionString("Server=[MYSERVERIPADRESS]\\DBSERVER;Database=NotifyTest;User ID=NHibernateTester;Password=[MYPASSWORD];Trusted_Connection=False;")
              )

              .Mappings(m => {
                  m.AutoMappings
                    .Add(AutoMap.AssemblyOf<SubscriptionManagerRP>(cfg));

              } )

              .BuildSessionFactory();
        }



    }
}

A couple of helpful hints.

You can put a DeploymentItem attribute on your test class. This will copy over the DLL's you need. You would also have to reference the DLL's in the projects references.

    [TestClass]
[DeploymentItem("NHibernate.ByteCode.LinFu.dll")]
[DeploymentItem("NHibernate.ByteCode.LinFu.xml")]
public class Accounts

You can find missing DLL's by comparing the /[myapp]/bin/debug folder to the /TestResults/[TestRunDate] folder.

I am using VS 2012. This is for MSTest.

Adding the reference to NHibernate.ByteCode.Castle.dll fixed this issue for me.

From Fluent NHibernate wiki: ProxyFactory configuration missing

The database configuration inside CreateSessionFactory is missing the ProxyFactoryFactory invocation. Since issue 154 is a wontfix, a line

.ProxyFactoryFactory("NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle") will be need to be added to database configuration call. Mine looks like this:

return Fluently.Configure()
    .Database(SQLiteConfiguration.Standard.UsingFile("firstProject.db")
    .ProxyFactoryFactory("NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle"))

Actually, the 'ReferByteCode' method is needed, only a reference doesn't help. Its a hack worthy of McGyver, but it works.

Guys if You having this issue I suggest You to download other package of Castle. In my case problem was that in package I`ve downloaded there was really not implemented Interface (IProxyFactory or something like that) so I have deleted NHibernate.ByteCode.Castle and NHibernate.ByteCode.Search and installed NHibarnate.Castle package which solve my all-day problem. I am using NuGet Package Manager!

and remember Fusion Log is You`re friend!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!