1
Vote

System.MethodAccessException when trying to instantiate new UnityContainer

description

code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Practices.Unity;

namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {
            var container = new UnityContainer();
        }
    }
}
Works on Win7, Win8 with Unity 3.504 or 3.505_prerelease

With Win8.1 following exception occurs:
System.MethodAccessException wurde nicht behandelt.
  HResult=-2146233072
  Message=Fehler beim Versuch der SecurityTransparent-Methode "Microsoft.Practices.ObjectBuilder2.StagedStrategyChain`1<TStageEnum>.NumberOfEnumValues()", auf die sicherheitskritische Methode "System.Linq.Enumerable.Where<System.Reflection.FieldInfo>(System.Collections.Generic.IEnumerable`1<System.Reflection.FieldInfo>, System.Func`2<System.Reflection.FieldInfo,Boolean>)" zuzugreifen.
  Source=Microsoft.Practices.Unity
  StackTrace:
       bei Microsoft.Practices.ObjectBuilder2.StagedStrategyChain`1.NumberOfEnumValues()
       bei Microsoft.Practices.ObjectBuilder2.StagedStrategyChain`1..ctor()
       bei Microsoft.Practices.ObjectBuilder2.StagedStrategyChain`1..ctor(StagedStrategyChain`1 innerChain)
       bei Microsoft.Practices.Unity.UnityContainer.InitializeBuilderState()
       bei Microsoft.Practices.Unity.UnityContainer..ctor(UnityContainer parent)
       bei Microsoft.Practices.Unity.UnityContainer..ctor()
       bei MDP.Server.Exporter.Program.Main(String[] args) in c:\coding\MDP\source\projects\MDP.Server.Exporter\Program.cs:Zeile 21.
       bei System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       bei Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       bei System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       bei System.Threading.ThreadHelper.ThreadStart()
  InnerException: 

file attachments

comments

fcarlier wrote Oct 15, 2015 at 2:47 PM

Hi,

We're troubleshooting a similar issue (same call stack) with a customer.

I'm not sure the Windows version is what causes this - we have the code running on Windows 8.1.

Did you ever get to the root cause of this?

System.MethodAccessException: Attempt by security transparent method 'Microsoft.Practices.ObjectBuilder2.StagedStrategyChain1<TStageEnum>.NumberOfEnumValues()' to access security critical method 'System.Linq.Enumerable.Where<System.Reflection.FieldInfo>(System.Collections.Generic.IEnumerable1<System.Reflection.FieldInfo>, System.Func2<System.Reflection.FieldInfo,Boolean>)' failed.
at Microsoft.Practices.ObjectBuilder2.StagedStrategyChain
1.NumberOfEnumValues()
at Microsoft.Practices.ObjectBuilder2.StagedStrategyChain`1..ctor()
at Microsoft.Practices.Unity.UnityContainer.InitializeBuilderState()
at Microsoft.Practices.Unity.UnityContainer..ctor(UnityContainer parent)
at Microsoft.Practices.Unity.UnityContainer..ctor()

fcarlier wrote Oct 15, 2015 at 2:50 PM