Search code examples
.net-4.0pos-for-.net

Microsoft POS for .NET and .NET 4.0 hangs when debugging


I'm trying to use the POS for .NET library in a .NET 4.0 application and I'm running into some problems. The first was the 'CAS policy' exception that a lot of people seem to encounter. So I've added the NetFx40_LegacySecurityPolicy=true entry to my app.config file as Microsoft recommends.

A problem I'm seeing now though, is when I have the debugger attached and I try to construct a new PosExplorer, the constructor hangs. If the debugger is detached when I created it, everything seems to be fine (and I can re-attach at this point and everything works).

Does anybody have an idea as to what could be causing this behavior, and hopefully what I could do to correct it?


Solution

  • I started debugging into the PoS library using Reflector Pro and discovered it was getting stuck in this method:

    private static ServiceObjectCollection ScanFolder(string path, Dictionary<string, string> posAssemblies)
    {
      Logger.Info("AssemblyLoader", "Scanning folder " + path + " for SO assemblies.");
      ServiceObjectCollection serviceobjects = new ServiceObjectCollection();
      DirectoryInfo info = new DirectoryInfo(path);
      Logger.Info("AssemblyLoader", "Enumerating files in " + path);
      foreach (FileInfo info2 in info.GetFiles())
      {
        LoadFile(info2, posAssemblies, serviceobjects);
      }
      Logger.Info("AssemblyLoader", "Leaving ScanFolder.");
      return serviceobjects;
    }
    

    Where it is trying to load every assembly in the working directory to scan for PoS objects... it was hanging while trying to load the old Managed DirectX library that our application also uses.

    Applying the fix from this question: Managed DirectX running from .Net Framework 4.0 app dont hunt solved the problem. We already use this trick to use MDX with .NET 4 however I didn't have the app.config setting applied in this case because I was writing a stand-alone application to get familiar with PoS... didn't anticipate that I would be trying to load DirectX :)