来自 Intranet 共享的 Springframework .NET 4.0 控制台应用程序



我最近迁移了一个.NET 3.5控制台应用程序,该应用程序使用spring和hiberate到.NET 4.0。 此应用程序在 .net 3.5 下的网络共享和 .net 4.0 下的本地驱动器上运行良好,但是一旦我将其迁移到 .net 4.0,在从网络共享启动时出现以下错误:

    Unhandled Exception: System.TypeInitializationException: The type initializer for 'Spring.Context.Support.ContextRegistry' threw an exception. 
    ---> Common.Logging.ConfigurationException: Failed obtaining configuration for Common.Logging from configuration section 'common/logging'. 
    ---> System.Configuration.ConfigurationErrorsException: An error occurred creating the configuration section handler for common/logging: That assembly does not allow partially trusted callers. (Z:ToolsSaaSDataPosterSaaSDataPoster.exe.Config line 6) 
    ---> System.Security.SecurityException: That assembly does not allow partially trusted callers.
       at System.Security.CodeAccessSecurityEngine.ThrowSecurityException(RuntimeAssembly asm, PermissionSet granted, PermissionSet refused, RuntimeMethodHandleInternal rmh, SecurityAction action, Object demand, IPermission permThatFailed)
       at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
       at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache)
       at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean skipCheckThis, Boolean fillCache)
       at System.Activator.CreateInstance(Type type, Boolean nonPublic)
       at System.Configuration.TypeUtil.CreateInstanceWithReflectionPermission(Type type)
       at System.Configuration.RuntimeConfigurationRecord.RuntimeConfigurationFactory.Init(RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord)
       at System.Configuration.RuntimeConfigurationRecord.RuntimeConfigurationFactory.InitWithRestrictedPermissions(RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord)
       at System.Configuration.RuntimeConfigurationRecord.CreateSectionFactory(FactoryRecord factoryRecord)
       at System.Configuration.BaseConfigurationRecord.FindAndEnsureFactoryRecord(String configKey, Boolean& isRootDeclaredHere)
       --- End of inner exception stack trace ---
       at System.Configuration.BaseConfigurationRecord.FindAndEnsureFactoryRecord(String configKey, Boolean& isRootDeclaredHere)
       at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
       at System.Configuration.BaseConfigurationRecord.GetSection(String configKey)
       at System.Configuration.ConfigurationManager.GetSection(String sectionName)
       at Common.Logging.LogManager.<>c__DisplayClass3.<BuildLoggerFactoryAdapter>b__0()
       at Common.Logging.Configuration.ArgUtils.<>c__DisplayClass13.<Guard>b__12()
       at Common.Logging.Configuration.ArgUtils.Guard[T](Function`1 function, String messageFormat, Object[] args)
       --- End of inner exception stack trace ---
       at Common.Logging.Configuration.ArgUtils.Guard[T](Function`1 function, String messageFormat, Object[] args)
       at Common.Logging.LogManager.BuildLoggerFactoryAdapter()
       at Common.Logging.LogManager.get_Adapter()
       at Common.Logging.LogManager.GetLogger(Type type)
       at Spring.Context.Support.ContextRegistry..cctor() in c:_prjspring-        nettrunksrcSpringSpring.CoreContextSupportContextRegistry.cs:line 60
       --- End of inner exception stack trace ---
       at Spring.Context.Support.ContextRegistry.GetContext()

我尝试添加<NetFx40_LegacySecurityPolicy enabled="true" />并使用CasPol.exe为内部网区域提供完全信任(当应用程序为 .net 2.0 时,这有效)。

我也在使用为 .net 4.0 编译的 spring.net 二进制文件。

我的程序集也都有一个强名称。 我不确定这是帮助还是伤害。

我的执行程序集的 IsFullTrusted 属性也返回 true。

有没有人在春天,净4.0和网络共享方面有任何运气?

以下是caspol -m -lg的输出:

32 位:

    Code Groups:
    1.  All code: Nothing
       1.1.  Zone - MyComputer: FullTrust
          1.1.1.  StrongName - 002400000480000094000000060200000024000052534131000400000100010007D1FA57C4AED9F0A32E84AA0FAEFD0DE9E8FD6AEC8F87FB03766C834C99921EB23BE79AD9D5DCC1DD9AD236132102900B723CF980957FC4E177108FC607774F29E8320E92EA05ECE4E821C0A5EFE8F1645C4C0C93C1AB99285D622CAA652C1DFAD63D745D6F2DE5F17E5EAF0FC4963D261C8A12436518206DC093344D5AD293: FullTrust
          1.1.2.  StrongName - 00000000000000000400000000000000: FullTrust
       1.2.  Zone - Intranet: FullTrust
          1.2.1.  All code: Same site Web
          1.2.2.  All code: Same directory FileIO - 'Read, PathDiscovery'
       1.3.  Zone - Internet: Internet
          1.3.1.  All code: Same site Web
       1.4.  Zone - Untrusted: Nothing
       1.5.  Zone - Trusted: Internet
          1.5.1.  All code: Same site Web

64 位:

    Code Groups:
    1.  All code: Nothing
       1.1.  Zone - MyComputer: FullTrust
          1.1.1.  StrongName - 002400000480000094000000060200000024000052534131000400000100010007D1FA57C4AED9F0A32E84AA0FAEFD0DE9E8FD6AEC8F87FB03766C834C99921EB23BE79AD9D5DCC1DD9AD236132102900B723CF980957FC4E177108FC607774F29E8320E92EA05ECE4E821C0A5EFE8F1645C4C0C93C1AB99285D622CAA652C1DFAD63D745D6F2DE5F17E5EAF0FC4963D261C8A12436518206DC093344D5AD293: FullTrust
          1.1.2.  StrongName - 00000000000000000400000000000000: FullTrust
       1.2.  Zone - Intranet: FullTrust
          1.2.1.  All code: Same site Web
          1.2.2.  All code: Same directory FileIO - 'Read, PathDiscovery'
       1.3.  Zone - Internet: Internet
          1.3.1.  All code: Same site Web
       1.4.  Zone - Untrusted: Nothing
       1.5.  Zone - Trusted: Internet
          1.5.1.  All code: Same site Web

我通过将 AllowPartlyTrustedCallersAttribute 添加到包含用于反序列化配置部分的类型的程序集来部分解决此问题。

相关内容

最新更新