.NET fiddle error when invoking Castle Windsor

354 Views Asked by At

I am attempt to use dotnetfiddle to demonstrate a simply Castle Windsor edge case.

When it tries to run this code:

             var container = new WindsorContainer()
                         .Register(Component.For<TestClass>()
                                     .LifeStyle.Singleton
                                     .OnDestroy(t => t.ByeBye())
                                   );

We get an error:

Run-time exception (line 42): Inheritance security rules violated while overriding member: 'Castle.MicroKernel.DefaultKernel.InitializeLifetimeService()'. Security accessibility of the overriding method must match the security accessibility of the method being overriden.

Stack Trace:

[System.TypeLoadException: Inheritance security rules violated while overriding member: 'Castle.MicroKernel.DefaultKernel.InitializeLifetimeService()'. Security accessibility of the overriding method must match the security accessibility of the method being overriden.] at Program.Main(String[] args): line 42

Is there some was we can get Castle Windsor running in .NET fiddle?

The .NET fiddle share is here: https://dotnetfiddle.net/crBGpt

1

There are 1 best solutions below

3
On

It does indeed have to do with the Medium Trust of .netFiddle. You can modify the code if you really need to run it under Medium Trust.

I would instead recommend not testing the Castle part of your code under Medium Trust but rather concentrate on the moving parts of your application, leaving the Castle behavior to its own tests (which you could run on the side on another machine)