当非特权用户使用时,NHibernate无法查询数据库

时间:2011-11-07 13:19:32

标签: c# nhibernate reflection fluent-nhibernate strongname

我正在使用Fluent NHibernate 1.2,NH 3.1和castle进行代理生成。我试图以非管理员用户身份运行应用程序(一个简单的win-forms应用程序)并查看异常: Unable to obtain public key for StrongNameKeyPair.以前(我不确定我是如何绕过这一步的),例外是Creating a proxy instance failed.

2010年的一些博客帖子表明,Castle的动态代理可能会遇到中等信任情况的问题,所以我试着用sn -m n运气,但这似乎没什么用。

是否有人熟悉此行为?

谢谢, JK

修改
生成此异常的应用程序调用是一个简单的LINQ over NHibernate会话。 这是堆栈跟踪的顶部(整个事情大约是60行):

    mscorlib.dll!System.Reflection.StrongNameKeyPair.ComputePublicKey() + 0xca bytes    
mscorlib.dll!System.Reflection.StrongNameKeyPair.PublicKey.get() + 0x15 bytes   
mscorlib.dll!System.Reflection.Emit.AssemblyBuilder.AssemblyBuilder(System.AppDomain domain = {System.AppDomain}, System.Reflection.AssemblyName name = {System.Reflection.AssemblyName}, System.Reflection.Emit.AssemblyBuilderAccess access = Run, string dir = null, System.Security.Policy.Evidence evidence = null, System.Security.PermissionSet requiredPermissions = null, System.Security.PermissionSet optionalPermissions = null, System.Security.PermissionSet refusedPermissions = null, ref System.Threading.StackCrawlMark stackMark = LookForMyCaller, System.Collections.Generic.IEnumerable<System.Reflection.Emit.CustomAttributeBuilder> unsafeAssemblyAttributes = null, System.Security.SecurityContextSource securityContextSource = CurrentAssembly) + 0x4b8 bytes  
mscorlib.dll!System.Reflection.Emit.AssemblyBuilder.InternalDefineDynamicAssembly(System.Reflection.AssemblyName name, System.Reflection.Emit.AssemblyBuilderAccess access, string dir, System.Security.Policy.Evidence evidence, System.Security.PermissionSet requiredPermissions, System.Security.PermissionSet optionalPermissions, System.Security.PermissionSet refusedPermissions, ref System.Threading.StackCrawlMark stackMark, System.Collections.Generic.IEnumerable<System.Reflection.Emit.CustomAttributeBuilder> unsafeAssemblyAttributes, System.Security.SecurityContextSource securityContextSource) + 0x7e bytes  
mscorlib.dll!System.AppDomain.InternalDefineDynamicAssembly(System.Reflection.AssemblyName name, System.Reflection.Emit.AssemblyBuilderAccess access, string dir, System.Security.Policy.Evidence evidence, System.Security.PermissionSet requiredPermissions, System.Security.PermissionSet optionalPermissions, System.Security.PermissionSet refusedPermissions, ref System.Threading.StackCrawlMark stackMark, System.Collections.Generic.IEnumerable<System.Reflection.Emit.CustomAttributeBuilder> assemblyAttributes, System.Security.SecurityContextSource securityContextSource) + 0x2c bytes  
mscorlib.dll!System.AppDomain.DefineDynamicAssembly(System.Reflection.AssemblyName name, System.Reflection.Emit.AssemblyBuilderAccess access) + 0x2b bytes  
Castle.Core.dll!Castle.DynamicProxy.ModuleScope.CreateModule(bool signStrongName = true) + 0x1fa bytes  
Castle.Core.dll!Castle.DynamicProxy.ModuleScope.ObtainDynamicModuleWithStrongName() + 0x9d bytes    
Castle.Core.dll!Castle.DynamicProxy.ModuleScope.ObtainDynamicModule(bool isStrongNamed = true) + 0x2b bytes 
Castle.Core.dll!Castle.DynamicProxy.ModuleScope.DefineType(bool inSignedModulePreferably = true, string name = "Castle.Proxies.Invocations.Entity`1_Equals", System.Reflection.TypeAttributes flags = Public | Serializable) + 0x5a bytes   
Castle.Core.dll!Castle.DynamicProxy.Generators.Emitters.ClassEmitter.CreateTypeBuilder(Castle.DynamicProxy.ModuleScope modulescope = {Castle.DynamicProxy.ModuleScope}, string name = "Castle.Proxies.Invocations.Entity`1_Equals", System.Type baseType = {Name = "InheritanceInvocation" FullName = "Castle.DynamicProxy.InheritanceInvocation"}, System.Collections.Generic.IEnumerable<System.Type> interfaces = {System.Type[0]}, System.Reflection.TypeAttributes flags = Public | Serializable, bool forceUnsigned = false) + 0x68 bytes 

1 个答案:

答案 0 :(得分:0)

非常愚蠢 - 经过一些试验和错误后,我发现Guest帐户是个问题。当该帐户在Users组中工作时,创建一个新帐户。 Guest帐户比其他帐户限制得多,但我可能认为它可以做某些不能做的事情......

我会留下它,因为我不期望这个应用程序的“访客用户”。