1

我正在开发一个项目,其中实体由 NHibernate 映射属性(例如 [Property] 和 [Class])进行修饰。不幸的是,RIAServices 似乎不支持大多数这些属性,这会在 RIAServices 尝试生成 Silverlight 客户端代码时导致失败。

当我尝试构建使用用 [Class] 或 [Property] 属性装饰的实体的 DomainService 时,我收到带有以下错误消息的 ArgumentNullException:

错误 2 “CreateRiaClientFilesTask”任务意外失败。
System.Reflection.TargetInvocationException:调用的目标已引发异常。---> System.ArgumentNullException:值不能为空。
参数名称:TypeName
在 System.RuntimeType.PrivateGetType (字符串类型名称,布尔 throwOnError,布尔 ignoreCase,布尔反射,StackCrawlMark 和 stackMark)
在 System.Type.GetType(字符串类型名称)
在 NHibernate.Mapping.Attributes.ClassAttribute.get_NameType()
--- 内部异常堆栈跟踪结束 ---
在 System.RuntimeMethodHandle._InvokeMethodFast(对象目标,Object[] 参数,SignatureStruct& sig,MethodAttributes methodAttributes,RuntimeTypeHandle typeOwner)
在 System.RuntimeMethodHandle.InvokeMethodFast(对象目标,对象 [] 参数,签名 sig,MethodAttributes 方法属性,RuntimeTypeHandle typeOwner)
在 System.Reflection.RuntimeMethodInfo.Invoke(Object obj,BindingFlags invokeAttr,Binder binder,Object[] 参数,CultureInfo 文化,布尔型 skipVisibilityChecks)
在 System.Reflection.RuntimeMethodInfo.Invoke(Object obj,BindingFlags invokeAttr,Binder binder,Object[] 参数,CultureInfo 文化)
在 System.Reflection.RuntimePropertyInfo.GetValue(Object obj,BindingFlags invokeAttr,Binder binder,Object[] index,CultureInfo 文化)
在 System.Reflection.RuntimePropertyInfo.GetValue(对象 obj,对象 [] 索引)
在 System.Web.DomainServices.Tools.StandardCustomAttributeBuilder.GetPropertyValues(IEnumerable`1 propertyMaps,属性属性)
在 System.Web.DomainServices.Tools.StandardCustomAttributeBuilder.GetAttributeDeclaration(属性属性)
在 System.Web.DomainServices.Tools.CustomAttributeGenerator.GenerateCustomAttributes(ClientProxyGenerator proxyGenerator,CodeTypeDeclaration referencingType,IEnumerable`1 属性,CodeCommentStatementCollection 注释)
在 System.Web.DomainServices.Tools.CustomAttributeGenerator.GenerateCustomAttributes(ClientProxyGenerator proxyGenerator,CodeTypeDeclaration referencingType,IEnumerable`1 属性,CodeAttributeDeclarationCollection outputCollection,CodeCommentStatementCollection 注释)
在 System.Web.DomainServices.Tools.EntityProxyGenerator.Generate()
在 System.Web.DomainServices.Tools.ClientProxyGenerator.GenerateProxyClass(字符串和生成代码)
在 System.Web.DomainServices.Tools.CreateRiaClientFilesTask.GenerateClientProxies()
在 System.Web.DomainServices.Tools.CreateRiaClientFilesTask.Execute()
在 Microsoft.Build.Framework.ITask.Execute()
在 Microsoft.Build.BuildEngine.TaskEngine.ExecuteInstantiatedTask(EngineProxy engineProxy, ItemBucket bucket, TaskExecutionMode howToExecuteTask, ITask task, Boolean& taskResult) SL

我知道使用 Fluent NHibernate 应该可以解决问题,因为它消除了对 NHibernate 依赖项的需求,但我想首先确保在迁移到 Fluent NHibernate 之前没有任何其他解决方案。关于解决这个问题的任何想法?

4

3 回答 3

2

正如我在评论中提到的,听起来问题在于 NHibernate 在代码生成期间抛出。如果您真的想使用这些属性,我建议您获取 NHibernate 源代码并尝试将 VS 调试器附加到正在生成代码的 VS 实例上,这可能会帮助您找出失败的原因。

可能更好的方法是遵循Brada 的这篇关于使用 NHibernate 和 RIA 服务的帖子或者观看关于 NHibernate 与 RIA 服务的截屏视频。这两个地方似乎都有他们一起工作的工作例子,所以也许从那里开始,而不是沿着你要去的路线走。

于 2009-10-22T23:32:39.183 回答
0

我们有同样的问题。解决方案:去掉属性,只使用 XML 进行映射。

于 2010-01-06T05:55:03.970 回答
0

您可以将预处理器指令添加到您的实体,以便在为 silverlight 编译时缺少属性。

#if SILVERLIGHT
//nothing
#else
[class]
#endif
public class entity{
}
于 2009-10-30T03:35:25.693 回答