IamDeveloper
IamDeveloper

Reputation: 5226

How to make internal mapping class for NHibernate?

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?

Upvotes: 2

Views: 1695

Answers (1)

WiseGuyEh
WiseGuyEh

Reputation: 19080

Perhaps try adding:

[assembly: InternalsVisibleTo("NHibernate")]

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.

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)

EDIT:

try adding:

[assembly: InternalsVisibleTo("mscorlib")]

You have have to specify the public key/version of the assembly you are using.

Upvotes: 1

Related Questions