The data tier has references to NHibernate, and in hibernate.cfg.xml a need for NHibernate.ByteCode.LinFu is configured. The reference to NHibernate is set to copy local, and NHibernate doesn't exist in the GAC. Which otherways could interfere with the copy local. Ok, everything fine so far. Also a need for a reference to NHibernate.ByteCode.LinFu with copy local is needed, since this assembly is needed run-time. Added a reference with copy local, to get this assembly in the runtime folder. I'm not to happy with this reference, but I can leave with it. What I'd really like is NHibernate self to handle this, and get hold of its needed assemblies. But there is a dynamic reference here.
Fine by now, everything ends up in the datalayer\bin\debug folder. Ahh, but then. I add a project reference in the business layer to the data layer. And from the web application there is added a project reference to the business layer. In the Web\bin folder there are missing some dll's after compiling. Everything that NHibernate needs are there (and all other assembly include their needed assemblies), except for NHibernate.ByteCode.LinFu, LinFu.DynamicProxy and hibernate.cfg.xml.
I don't want the client to know about all the different needs my data access has. So linking in files the client itself doesn't need is not a good option for me. Adding references to assembly not needed by the client the same.
So for now I uses post build events on my data project. Copies explicit the needed files to a temporary bin folder.
mkdir "$(SolutionDir)Bin"
xcopy "$(TargetDir)*LinFu*" "$(SolutionDir)Bin" /y
xcopy "$(TargetDir)hibernate.cfg.xml" "$(SolutionDir)Bin" /y
The client copies all files from this directory in the pre build event to the web\bin folder like this:
xcopy "$(SolutionDir)Bin" "$(TargetDir)*.*" /y
This way all the missing files are copied back and forth, ending up where they are needed.

I'm experiencing a similar problem.
ReplyDeleteI have an assembly which contains business logic.
This assembly is referenced by another assembly in where I have my service layer.
This assembly (with the service layer) also has a reference to NHibernate and the LinFu bytecode provider.
Then, I have an exe application that references my Service Layer assembly.
When running the exe app, I get an exception that the LinFU assembly cannot be found.
When I have a look in the bin directory of my exe, I indeed notice that LinFu is not there, the NHibernate assembly on the other hand is copied to the bin folder of the exe ...
The Copy Local property of both the NH assembly and the LinFu assembly are set to true ... I do not understand what's going on ....
Neither NH nor LinFu are in the GAC.
Yes, I think this is the same problem. The NHibernate assembly has "real" references to everything it needs. Except for the dynamically linked assemblies like LinFu.
ReplyDeleteThe work-around with copying in post-build/pre-build should do the trick for you to though. Or adding reference to LinFu from the exe app. Which isn't a very nice solution.
Yes indeed, its a dynamic linked assembly.
ReplyDeleteHowever, the thing I do not understand, is that my service layer assembly has a 'real' reference to the LinFu assembly.
My exe application has a real reference to my service layer. So, I expect that the LinFu assembly is copied as well (since I have a 'hard' reference to it in my own servicelayer assembly).
Creating a postbuild event is not an option for me, since there are numerous apps that will use my service layer.
I see your point. I'm not to happy with using build events for this my self either, but in my case it works! Please let me know if you or anybody else finds a better solution.
ReplyDelete