0

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

Andrew Shepherd
  • 44,254
  • 30
  • 139
  • 205
  • Here is a similar problem: it seems to do with running it under `Medium trust`: http://stackoverflow.com/questions/7199238/medium-trust-share-webhosting-site-with-castle-windsor?rq=1 – Andrew Shepherd Nov 10 '14 at 04:08

1 Answers1

0

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)

Community
  • 1
  • 1
samy
  • 14,832
  • 2
  • 54
  • 82
  • In .NET Fiddle you include the libraries as a Nuget package, and write a snippet of code against that. Modifying the library code isn't an option for this exercise, unless I create a new fork of Windsor and expose it as a package somehow. Pity. :-( – Andrew Shepherd Nov 12 '14 at 23:33
  • I am aware of that; if you _need_ to use a Castle Windsor in Medium Trust you will have to change code. If not just test your component outside of Castle in .net fiddle – samy Nov 13 '14 at 00:11
  • As another option you can make a pull request to Castle with Medium Trust support, but not sure that they will accept it. We can update Security settings on the fly with Mono Cecil for imported NuGet assembly and allow it to be executed in Medium Trust, but if assembly uses something that require FullTrust, then it won't help. So unfortunately some packages cannot be executed on .Net Fiddle – Sergey Litvinov Apr 11 '15 at 14:21