RIA Services does not support entities that are decorated by NHibernate mapping attributes

nhibernatenhibernate-mappingsilverlightwcf-ria-services

I'm working on a project where entities are being decorated by NHibernate mapping attributes such as [Property] and [Class]. Unfortunately RIAServices doesn't seem to support most of these attributes, which causes a failure when RIAServices is trying to generate the Silverlight Client Code.

When I try to build a DomainService that uses an entity decorated with the [Class] or [Property] attribute, I get an ArgumentNullException with the following error message:

Error   2   The "CreateRiaClientFilesTask" task failed unexpectedly.
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.ArgumentNullException: Value cannot be null.
Parameter name: TypeName
at System.RuntimeType.PrivateGetType(String typeName, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark)
at System.Type.GetType(String typeName)
at NHibernate.Mapping.Attributes.ClassAttribute.get_NameType()
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.RuntimePropertyInfo.GetValue(Object obj, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture)
at System.Reflection.RuntimePropertyInfo.GetValue(Object obj, Object[] index)
at System.Web.DomainServices.Tools.StandardCustomAttributeBuilder.GetPropertyValues(IEnumerable`1 propertyMaps, Attribute attribute)
at System.Web.DomainServices.Tools.StandardCustomAttributeBuilder.GetAttributeDeclaration(Attribute attribute)
at System.Web.DomainServices.Tools.CustomAttributeGenerator.GenerateCustomAttributes(ClientProxyGenerator proxyGenerator, CodeTypeDeclaration referencingType, IEnumerable`1 attributes, CodeCommentStatementCollection comments)
at System.Web.DomainServices.Tools.CustomAttributeGenerator.GenerateCustomAttributes(ClientProxyGenerator proxyGenerator, CodeTypeDeclaration referencingType, IEnumerable`1 attributes, CodeAttributeDeclarationCollection outputCollection, CodeCommentStatementCollection comments)
at System.Web.DomainServices.Tools.EntityProxyGenerator.Generate()
at System.Web.DomainServices.Tools.ClientProxyGenerator.GenerateProxyClass(String& generatedCode)
at System.Web.DomainServices.Tools.CreateRiaClientFilesTask.GenerateClientProxies()
at System.Web.DomainServices.Tools.CreateRiaClientFilesTask.Execute()
at Microsoft.Build.Framework.ITask.Execute()
at Microsoft.Build.BuildEngine.TaskEngine.ExecuteInstantiatedTask(EngineProxy engineProxy, ItemBucket bucket, TaskExecutionMode howToExecuteTask, ITask task, Boolean& taskResult)  SL 

I know that using Fluent NHibernate should solve the problem because it removes the need for NHibernate dependencies, but I want to make sure first that there aren't any other solutions before moving to Fluent NHibernate. Any thoughts on solving this problem?

Best Answer

As I mentioned in the comments it sounds like the issue is with NHibernate throwing up during the code generation. If you really want to use the attributes I would suggest getting the NHibernate source code and trying to attach the VS debugger to the VS instance that is doing the code generation, might help you figure out why it is failing.

Probably a better approach would be to follow this post by Brada on using NHibernate with RIA Services or watching this screencast on NHibernate with RIA Services. Both of those places seem to have working examples of them working together, so maybe start there instead of going down the route you're going.

Related Topic