NHibernate: Custom type is not serializable


Since I acquired a NHibernateProfiler license, an initialization warning message draw my attention, the text seemed quite easy to solve:

WARN: custom type is not Serializable: MyLibrary.MyCustomDataType

My first solution was adding [Serializable] attribute to the custom type, but that didn’t make the trick. As it was only a warning, I did not investigate further at that moment.

NHibernate Logo

But the other day, debugging data access code I saw the warning again and the easiest solution was going to the source NHibernate code to find this:

TypeFactory.InjectParameters(userType, parameters);
if (!userType.ReturnedClass.IsSerializable)
{
    LogManager.GetLogger(typeof(CustomType)).Warn("custom type is not Serializable: " + userTypeClass);
}

As seen in this code, the message is unclear, because the class that must be serializable is the ReturnedClass, not the custom UserType itself.

So, to solve the warning I just needed to add [Serializable] to the class returned by my custom UserType instead than the type itself.

Related Posts

Bye bye Kurobox

A deserved farewell to a device that has worked flawlessly for so many years

DIY Arduino Christmas tree lights

A detailed explanation of my home made light switcher made with Arduino and a relay shield

Back to blogging

My statement on getting back to blogging. Will this go anywhere?

Lessons learned optimizing MySQL

A summary of some things I discovered while trying to optimize the performance of a production MySQL server.

Simple Mini Profiler Glimpse plugin

I just created my first Glimpse plugin, integration between Mininprofiler and Glimpse.

Carbon Copy Cloner saved my day

Just a gratitude post because this piece of software was extremely useful when others don't. And it was my birthday.

Troubleshooting MSDTC, RPC and NServiceBus issues

MSDTC is rare and can cause many headaches. This is the process I followed to track down the problems I was having

Using fail2ban with nginx in Debian

fail2ban helps you fight spam and bots but comes with an Apache sample. I converted it to handle Nginx information.

How msiinv saved my day

mssinv is a tool to manage MSI installed packages and I used it to track a problem with a package partially installed, that had to be removed with this tool

Install ASP.NET MVC 3 Manually

Due to some strange problems in my PC, I had to install this package manually and this is applicable to many other installers