I've installed NHibernate.3.3.2.4000 via Nuget into my MVC3 project, configured it without a proxyfactory.factory_class:
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="dialect">NHibernate.Dialect.MsSql2008Dialect, NHibernate</property>
<property name="connection.connection_string_name">db</property>
<property name="adonet.batch_size">50</property>
<property name="current_session_context_class">web</property>
<property name="query.substitutions">true 1, false 0, yes 'Y', no 'N'</property>
<mapping assembly="TheWorkshop.DomainModel" />
</session-factory>
</hibernate-configuration>
but like this I'm getting the following error:
The following types may not be used as proxies:
TheWorkshop.DomainModel.Contact: method set_DateAdded should be 'public/protected virtual' or 'protected internal virtual'
Where the DateAdded property privately sets the DateAdded value
public virtual DateTime DateAdded
{
get { return _dateAdded; }
private set { _dateAdded = DateTime.Now; }
}
I don't particularly want to make the setter public, the idea is that the DateAdded is automatically set.
I have seen posts that suggest I could set the proxyfactory.factory_class to
<property name="proxyfactory.factory_class">
NHibernate.ByteCode.Castle.ProxyFactoryFactory,
NHibernate.ByteCode.Castle
</property>
but the Nuget install didn't bring down any references to NHibernate.ByteCode.Castle, when I tried to Install-Package NHibernate.Castle it failed with
Install failed. Rolling back...
Install-Package : Already referencing a newer version of 'NHibernate'.
At line:1 char:16
+ Install-Package <<<< NHibernate.Castle
+ CategoryInfo : NotSpecified: (:) [Install-Package], InvalidOperationException
+ FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PowerShell.Commands.InstallPackageCommand
So I guess I could down version NHibernate, but that seems wrong...
What should I do, a similar question NuGet: NHibernate, Castle.Core 3.0 and where is ProxyFactoryFactory? says I don't need to configure the proxyfactory.factory_class in newer versions
The last versions of NHibernate do not require configuring a proxy factory.
An internal one is used by default and the old adapters are not part of the project anymore.
You don't necessarily need Castle.Core unless you use the Castle.Core proxy factory like you did in the second part. NHibernate comes with it's own proxy factory by default which is what you had the first time, so I won't comment on the Castle.Core part (and I don't think it works with latest nhibernate anyway)
You can solve your error by telling nhibernate that you don't want to lazy load the class (which is enabled by default). How you do this will vary based on how you did your mapping.
You can get rid of the error by making the setter protected instead of private.
I don't think your setter is actually working like you think it is. unless you are actually setting that property with a value, it will never get the current date/time, in which case you might as well just set it with DateTime.Now rather than what you have. Also, when nhibernate loads that, you'll be getting the current date rather than the actual date/time it was created. You should be setting the value in the constructor, not hijacking the setter like you are.
Related
Before v2:
RouteTable.Routes.MapHubs();
In v2, MapHubs does not exist anymore. The wiki says to add a Startup class and a Configuration method and a call to app.MapHubs().
namespace MyAssembly
{
public class Startup
{
public void Configuration(IAppBuilder app)
{
//Before v2
//RouteTable.Routes.MapHubs();
app.MapHubs();
}
}
}
But the method is never called, no error occurs, and ... no hub are setup.
I suppose there is some code to add to global.asax.cs
What is the secret ?
Try defining [assembly : OwinStartup(typeof(MyAssembly.Startup))] to see if your Startup class is being picked up.
EDIT: removed lines not relevant.
Solution !
<appSettings>
<add key="owin:AppStartup" value="MyNameSpace.Startup, MyNameSpace" />
</appSettings>
plus update both MVC4 (not to prerelease, but to latest stable version) and SignalR/owin nugets.
plus fix bugs in js client :
if disconnectTimeout=999000 then it is disabled. Must be set server-side with: GlobalHost.Configuration.DisconnectTimeout = TimeSpan.FromSeconds(999);
note: server side can not set a value < 6 (signalr throws an exception if DisconnectTimeout < 6). So use this magic number.
webSockets: set connection.socket = null in sockettransport, otherwise the call to start fails after a (manual) call to stop
serverSentEvents: prevent error caused by a reconnection attempt when the window is unloading
chrome fails with exception if signalr hub url not available (temporarily) : Instead of giving up try the next available protocol / try to reconnect.
I was able to get the 2.0 beta working by
Removing all references to the older version of SignalR, ie nuget uninstall of the library and double checking /bin
Installed SignalR 2.0.0-beta2 via Package Manager Console Install-Package Microsoft.AspNet.SignalR -Pre
Following the steps in the 1.x to 2.0 migration outlined here
And most importantly changing the project config to use Local IIS Web server instead of Visual Studio Developer Server (Cassini).
More info in the question/answer I posted here
In web.config there must be a fully qualified name of the class, e.g.
<appSettings>
<add key="owin:AppStartup" value="**My.Name.Space.Startup**, **AssemblyName**" />
</appSettings>
I had a problem when I put namespace instead of assembly name, but with the fully qualified name it works without any other changes to web.config!
UPDATE: I also followed the steps from the link: http://www.asp.net/vnext/overview/latest/release-notes#TOC13, i.e. removed a NuGet package "Microsoft.AspNet.SignalR.Owin"
I am having this annoying error while running my Nhibernate project. It was running okey and all of a sudden it just start asking for a file in this path "d:\CSharp\NH\NH\nhibernate\src\NHibernate\Bytecode\AbstractBytecodeProvider.cs" and when cancel, it throws an exception saying it says
Unable to load type 'NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle' during configuration of proxy factory class.
Possible causes are:
- The NHibernate.Bytecode provider assembly was not deployed.
- The typeName used to initialize the 'proxyfactory.factory_class' property of the session-factory section is not well formed.
Solution:
Confirm that your deployment folder contains one of the following assemblies:
NHibernate.ByteCode.LinFu.dll
NHibernate.ByteCode.Castle.dll
It is become frustrating for me... need help please -:)
Make sure that you have following dlls copied to the output folder and loaded by your process:
NHibernate.ByteCode.Castle.dll
Castle.Core.dll
NHibernate.dll
Iesi.Collections.dll
log4net.dll
And your NHibernate configuration has this line:
<property name="proxyfactory.factory_class">
NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle
</property>
As an option, you can try to upgrade to latest version of NHibernate - 3.2. They have a built in proxy generator so it should be simpler for you. You will not need these additional dlls. Just remove the config line above if you use NHibernate 3.2.
If for some reasons you can not upgrade to 3.2 you may consider using different byte code providers. NHibernate supports 3 of them out of the box. Try LinFu or Spring:
NHibernate.ByteCode.Castle.ProxyFactoryFactory
NHibernate.ByteCode.LinFu.ProxyFactoryFactory
NHibernate.ByteCode.Spring.ProxyFactoryFactor
Upgrade to the latest version and you will not need an external proxyfactory anymore.
I'm trying to implement NHibernate into my Web App. I encounter an error which saying :
Method 'IsInstrumented' in type 'NHibernate.ByteCode.Castle.ProxyFactoryFactory'
from assembly 'NHibernate.ByteCode.Castle, Version=2.1.2.4000, Culture=neutral,
PublicKeyToken=aa95f207798dfdb4' does not have an implementation.
Does anyone know how to resolve this issue?
Make sure that you have following dlls copied to the output folder and loaded by w3wp.exe (if you use IIS):
NHibernate.ByteCode.Castle.dll
Castle.Core.dll
NHibernate.dll
Iesi.Collections.dll
log4net.dll
And your NHibernate configuration has this line:
<property name="proxyfactory.factory_class">
NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle
</property>
As an option, you can try to upgrade to latest version of NHibernate - 3.2. They have a built in proxy generator so it should be simpler for you. You will not need these additional dlls. Just remove the config line above if you use NHibernate 3.2.
If for some reasons you can not upgrade to 3.2 you may consider using different byte code providers. NHibernate supports 3 of them out of the box. Try LinFu or Spring:
NHibernate.ByteCode.Castle.ProxyFactoryFactory
NHibernate.ByteCode.LinFu.ProxyFactoryFactory
NHibernate.ByteCode.Spring.ProxyFactoryFactor
When I upgraded my NHibernate from 2 to 3, my SQLite tem database showed a error:
Could not find any resources appropriate for the specified culture or the neutral culture. Make sure "System.Data.SQLite.SR.resources" was correctly embedded or linked into assembly "System.Data.SQLite" at compile time, or that all the satellite assemblies required are loadable and fully signed.
The project using SQL Server work fine, but the test project using SQLite show this error.
Any solution?
My CFG:
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="show_sql">true</property>
<property name='proxyfactory.factory_class'>NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>
<property name="dialect">NHibernate.Dialect.SQLiteDialect</property>
<property name="connection.driver_class">NHibernate.Driver.SQLite20Driver</property>`
Tks[]
Patrick Coelho
Probably, you found a solution already. But I ran into the same problem. This setting (using Fluent Nh config) solved it for me:
.Database(SQLiteConfiguration.Standard.InMemory().Raw("hbm2ddl.keywords", "none").ShowSql())
It's the 'raw' thing that does the magic. I got it from this post: NHibernate on SQLite 3.0 – a workaround for “Could not find any resources appropriate for the specified culture or the neutral culture”
Up until recently I had a working service using NHibernate 2.0. I have upgraded to 2.1, but now try to instantiate the ItemManager:
IItemManager manager = Container.Instance.Resolve<IItemManager>();
I get an exception:
Castle.MicroKernel.ComponentNotFoundException was unhandled by user code
Message="No component for supporting the service Distribution.WMS.OrderManagement.Business.Contracts.IItemManager was found"
The mapping in my windsor config looks like this:
<component
id="item.manager"
service="Distribution.WMS.OrderManagement.Business.Contracts.IItemManager, Distribution.WMS.OrderManagement.Business.Contracts"
type="Distribution.WMS.OrderManagement.Business.Managers.ItemManager, Distribution.WMS.OrderManagement.Business.Managers"
lifestyle="transient">
<parameters>
<repository>${som.item.repository}</repository>
</parameters>
</component>
IItemManager is in the namespace: Distribution.WMS.OrderManagement.Business.Contracts
Am I missing something simple or is there something else I must do after upgrading?
I found my answer, not an upgrade related issue. This project depends on a common library that I had to update the NHibernate reference in. Since the last time I got latest someone decided to change where the windsor config file was located so when I got latest and updated my reference it was no longer able to find my config.