1

Recently was adding NLog into a .Net exe. Took the opportunity to recompile to .Net 4.6 from .Net 2.0. The exe calls a vendor library which uses .net 2.0. Certain method of the vendor library throws a Request Failed that indicates a securityPermission exception when the vendor library tries to call OpenMutex. Disassembling the vendor lib shows the offending code:

  [SecurityPermission(SecurityAction.PermitOnly)]
    static private void InitMutex(string path)
    {
        string name = string.Format("AMutexName");
        if (dataMutex != null)
        {
            //this.FinalizeMutex();
        }
        bool flag;
        dataMutex = new OpenMutex(false, Common.GlobalMutexName(name), out flag);

The issue appears to be with the attribute action of PermitOnly. I added the code directly into the 4.6 exe for easier testing and found if I change securityaction to almost any other value the OpenMutex calls succeeds. My question is if there is a way to grant permissions to my exe so the vendor code will succeed? The original EXE compiled under 2.0 works.

TimIam
  • 21
  • 1
  • 3
  • You "might" be out of luck. As security/permission model has changed from WF2 – T.S. Mar 31 '17 at 17:51
  • There's a way to set the security model to legacy but I have zero experience with it so I don't know if it would help: https://msdn.microsoft.com/en-us/library/dd409253.aspx – Alex Paven Mar 31 '17 at 18:03
  • Thanks for the suggestion Alex. I tried it and it does not work. If I compile back to a .net version prior to 4 the calls work. I know, as TS mentioned above the security model related to CAS changed starting with .net 4.0. Just havent found the way to ring fence the old code so its usable by new. – TimIam Mar 31 '17 at 19:11
  • Does [this question](https://stackoverflow.com/questions/2455654/what-additional-configuration-is-necessary-to-reference-a-net-2-0-mixed-mode?rq=1) help? –  Mar 31 '17 at 19:35

0 Answers0