问题描述
我做的内部类为我的映射,并把无处不在默认为lazy =假。
过了一会儿,我决定去与全懒惰,删除此设置。突然,几乎所有未能执行。除了我得到的无法执行查询... System.TypeLoadException:访问被拒绝......。
这当然是因为这一事实,即类被标记为内部,因此它们不能被nhibernate.dll访问。这就是为什么我还添加了的AssemblyInfo.cs行:
I made internal classes for my mappings and put everywhere "default-lazy=false".After a while I decided to go with full lazy and removed this setting. Suddenly almost everything fails to execute. Exception I'm getting is "Cannot execute query... System.TypeLoadException: Access is denied to...". This of course is because of the fact that classes are marked as internal and therefore they cannot be accessed by nhibernate.dll. That's why I also added to AssemblyInfo.cs lines:
[assembly: InternalsVisibleTo(InternalsVisible.ToDynamicProxyGenAssembly2)]
[assembly: InternalsVisibleTo(InternalsVisible.ToCastleCore)]
[assembly: InternalsVisibleTo("MyUnitTestsDLL")]
但它并不能帮助。我在做什么错
But it doesn't help. What am I doing wrong?
推荐答案
也许尝试加入:
[assembly: InternalsVisibleTo("NHibernate")]
如果这不工作,看TypeLoadException的堆栈跟踪和检查DDL异常被抛出从 - 添加InternalsVisibleTo属性,它是什么。
If this doesn't work, look at the stack trace of the TypeLoadException and check to see what DDL the exception is being thrown from- add a InternalsVisibleTo attribute for it.
我的猜测是NHibernate的DDL正在试图做一些更聪明的,现在延迟加载启动..也许它能够访问内部类某种原因或其他(含糊,但我不知道的NHibernate的源代码)
My guess is that the NHibernate DDL is trying to do something a bit more clever now lazy loading is enabled.. perhaps it has to have access to the internal class for some reason or another (vague but I don't know the source code of NHibernate)
编辑:
尝试加入:
[assembly: InternalsVisibleTo("mscorlib")]
您有必须指定要使用的程序集的公钥/版本。
You have have to specify the public key/version of the assembly you are using.
这篇关于如何让内部映射类NHibernate的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!