locked
TypeLoadException: "Inheritance security rules violated by type" error when loading logger from network share RRS feed

  • Question

  • This may turn out to be a more general .NET 4 problem, but since I run into it using MSBuild I figured I'll start here..

    We have alot of custom targets files, task assemblies and a custom logger, all of which is placed on a network share mapped to a drive letter and included in the Local Intranet zone.  When I try to execute a build using MSBuild 4.0 I get a TypeLoadException when MSBuild tries to load our custom XMLlogger.

    System.TypeLoadException: Inheritance security rules violated by type: 'ABB.Robotics.MSBuild.Loggers.XmlLogger'. Derived types must either match the security accessibility of the base type or be less accessible.

    Everything works fine if the assemblies are placed on a local harddrive instead so it seems I'm getting slapped by some part of the .NET security model here. The logger in question is developed against .NET 4.0, inherits from Microsoft.Build.Utilities.Logger and implements INodeLogger.

    For previous versions of the .NET framework we have set Full Trust to the Local Intranet zone on our development machines to avoid CAS problems and the same network share setup works fine using MSBuild 3.5 (and a 3.5 version of the logger).

    I'm not an expert on .NET security, and trying to research the error message mostly seems to lead into the world of ASP.Net and setups that doesn't match my situation. If anyone could offer some advice on how to resolve this, or how to debug the problem further I'd be grateful.

    Finally, the full stacktrace of the exception:

    MSBUILD : error MSB1025: An internal failure occurred while running MSBuild.
    System.TypeLoadException: Inheritance security rules violated by type: 'ABB.Robotics.MSBuild.Loggers.XmlLogger'. Derived types must either match the security accessibility of the base type or be less accessible.
       at System.Reflection.RuntimeAssembly.GetExportedTypes(RuntimeAssembly assembly, ObjectHandleOnStack retTypes)
       at System.Reflection.RuntimeAssembly.GetExportedTypes()
       at Microsoft.Build.Shared.TypeLoader.AssemblyInfoToLoadedTypes.ScanAssemblyForPublicTypes()
       at Microsoft.Build.Shared.TypeLoader.AssemblyInfoToLoadedTypes.GetLoadedTypeByTypeName(String typeName)
       at Microsoft.Build.Shared.TypeLoader.GetLoadedType(Object cacheLock, Object loadInfoToTypeLock, ConcurrentDictionary`2 cache, String typeName, AssemblyLoadInfo assembly)
       at Microsoft.Build.Shared.TypeLoader.Load(String typeName, AssemblyLoadInfo assembly)
       at Microsoft.Build.Logging.LoggerDescription.CreateLogger(Boolean forwardingLogger)
       at Microsoft.Build.CommandLine.MSBuildApp.CreateAndConfigureLogger(LoggerDescription loggerDescription, LoggerVerbosity verbosity, String unquotedParameter)
       at Microsoft.Build.CommandLine.MSBuildApp.ProcessLoggerSwitch(String[] parameters, LoggerVerbosity verbosity)
       at Microsoft.Build.CommandLine.MSBuildApp.ProcessLoggingSwitches(String[] loggerSwitchParameters, String[] distributedLoggerSwitchParameters, String[] verbositySwitchParameters, Boolean noConsoleLogger, Boolean distributedFileLogger, String[] fileLoggerParameters, String[] consoleLoggerParameters, String[][] groupedFileLoggerParameters, List`1& distributedLoggerRecords, LoggerVerbosity& verbosity, Boolean& detailedSummary, Int32 cpuCount)
       at Microsoft.Build.CommandLine.MSBuildApp.ProcessCommandLineSwitches(CommandLineSwitches commandLineSwitches, String& projectFile, String[]& targets, String& toolsVersion, Dictionary`2& globalProperties, ILogger[]& loggers, LoggerVerbosity& verbosity, List`1& distributedLoggerRecords, Boolean& needToValidateProject, String& schemaFile, Int32& cpuCount, Boolean& enableNodeReuse, TextWriter& preprocessWriter, Boolean& debugger, Boolean& detailedSummary)
       at Microsoft.Build.CommandLine.MSBuildApp.Execute(String commandLine)


    Johan Nyvaller - Build responsible ABB Robotics
    Thursday, January 20, 2011 10:48 AM

Answers

  • It seems I almost answered my own question...

    It's apparently the CAS that again causes problems - I had the impression that this was no longer an issue with .NET 4.0 but apparenly MSBuild still uses it.

    Solution in my case was to grant Full Trust to Local Intranet for .NET 4.0 also using caspol.exe

    caspol.exe -cg 1.2 FullTrust

     


    Johan Nyvaller - Build responsible ABB Robotics
    • Marked as answer by Johan Nyvaller Thursday, January 20, 2011 1:43 PM
    Thursday, January 20, 2011 1:42 PM