SecurityException using Ninject in photon server application

Options
Albert67
edited June 2013 in Photon Server
Hello everybody,

I'm new in Photon Server application development. I'm currently developing a photon server application and I would like to use Ninject as my injection dependency framework.

When I try to create a Ninject kernel instance as follow :

[code2=csharp]IKernel k = new StandardKernel();[/code2]

An MethodAccessExcption is thrown. The inner exception is a SecurityException.

Remarque : I try to create this kernel instance in the OnOperationRequest method inherited from PeerBase class.

I think this is a code acccess security issue, but I don't know how to fixed it.

Have you already have this error ?

Thanks for you replies,

Comments

  • We've not used Ninject with Photon yet - sorry. You will probably get better help on a forum that is dedicated to Ninject, but we can give it a try.

    Can you please post the full stacktrace / exception messages?

    Is Photon running under an Administrator account?
  • Thank you for your answer !

    Yes, Photon is running under an Administrator account.

    Is there an injection dependency framework working with photon ?

    As you requested, you will find below the full stacktrace :

    System.MethodAccessException :
    [code2=csharp]System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandle& ctor, Boolean& bNeedSecurityCheck)
    à System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean fillCache)
    à System.RuntimeType.CreateInstanceImpl(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean fillCache)
    à System.Activator.CreateInstance(Type type, Boolean nonPublic)
    à System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
    à System.Activator.CreateInstance(String assemblyName, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, Evidence securityInfo, StackCrawlMark& stackMark)
    à System.Activator.CreateInstance(String assemblyName, String typeName)
    à System.AppDomain.CreateInstanceAndUnwrap(String assemblyName, String typeName)
    à System.AppDomain.CreateInstanceAndUnwrap(String assemblyName, String typeName)
    à Ninject.Modules.AssemblyNameRetriever.GetAssemblyNames(IEnumerable`1 filenames, Predicate`1 filter)
    à Ninject.Modules.CompiledModuleLoaderPlugin.LoadModules(IEnumerable`1 filenames)
    à Ninject.Modules.ModuleLoader.LoadModules(IEnumerable`1 patterns)
    à Ninject.KernelBase.Load(IEnumerable`1 filePatterns)
    à Ninject.KernelBase..ctor(IComponentContainer components, INinjectSettings settings, INinjectModule[] modules)
    à Ninject.KernelBase..ctor(INinjectModule[] modules)
    à Ninject.StandardKernel..ctor(INinjectModule[] modules)
    à Server.NetworkPeer.OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters)
    à Photon.SocketServer.PeerBase.OnReceiveInternal(Byte[] data, SendParameters sendParameters, Int32 rtt, Int32 rttVariance, Int32 numFailures)[/code2]

    InnerException => System.SecurityException
    [code2=csharp]à System.Security.CodeAccessSecurityEngine.ThrowSecurityException(Assembly asm, PermissionSet granted, PermissionSet refused, RuntimeMethodHandle rmh, SecurityAction action, Object demand, IPermission permThatFailed)
    à System.Security.CodeAccessSecurityEngine.CheckSetHelper(PermissionSet grants, PermissionSet refused, PermissionSet demands, RuntimeMethodHandle rmh, Object assemblyOrString, SecurityAction action, Boolean throwException)
    à System.Security.PermissionSetTriple.CheckSetDemand(PermissionSet demandSet, PermissionSet& alteredDemandset, RuntimeMethodHandle rmh)
    à System.Security.PermissionListSet.CheckSetDemand(PermissionSet pset, RuntimeMethodHandle rmh)
    à System.Security.PermissionListSet.DemandFlagsOrGrantSet(Int32 flags, PermissionSet grantSet)
    à System.Security.CodeAccessSecurityEngine.ReflectionTargetDemandHelper(Int32 permission, PermissionSet targetGrant, CompressedStack securityContext)
    à System.Security.CodeAccessSecurityEngine.ReflectionTargetDemandHelper(Int32 permission, PermissionSet targetGrant)[/code2]
  • Hm, thanks - any exception messages, that could give a better hint what's going on?

    In general, any .NET library should work with Photon.
  • Unfortunately not...

    Maybe should I ask for a SSL certificate ?

    Could you tell me what is the photon code access level ? Medium Trust ? Full trust ? Is there any way to change it ?
  • I gave it a quick try and it worked for me (Photon running under .NET 4.0, tested Ninject 3.0.0.15 for .NET 3.5 and Ninject 3.0.1.10 for .NET 4.5, the builds for Full trust).

    You should definitely get an exception message if you attach a debugger to the PhotonSocketServer.exe process.

    However, it seems like it's not a general Photon issue... but here are some things to check / try out:

    - which .NET version is installed?
    - which .NET version does Photon use? (check the log file)
    - which Photon version?
    - which Ninject version?

    Please make sure that all versions are matching.

    If you have unzipped the ninject package with Windows Explorer's built-in zip functionality, Windows might consider the DLL as suspicious and block it, which looks like this:
    http://attachments.techguy.org/attachme ... locked.jpg
    You need to unblock it first: ninject-xxx.zip -> properties -> unblock; THEN unzip.

    Does the code snippet with the same reference ninject DLL work from a simple console app?
  • Thank you Nicole for your help ! I will try all this thing this evening and I will give you some feedback..
  • Hello Nicole,

    I have try to unlock de ninject zip and it works ! Thank you for your help !
  • Good to hear. Thanks for coming back and letting us know!