Exception when creating PosExplorer object of Microsoft PointOfService during NUnit Test

245 views Asked by At

I tried to test a driver of a POS written in C# that needs .NET 3.5. I'm using NUnit for VS17 because I have a console application code written in C# with some functional test of the driver.

It works good but when I try to call the same method from NUnit it raises an exception.

This is the working code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FiscalReceipt.Library;

namespace FiscalReceiptMain
{
    class Program
    {
        [STAThread]
        static void Main(string[] args)
        {
            Console.WriteLine("Setting [STAThread] ");
            FiscalReceipt.Library.FiscalReceipt mc = new FiscalReceipt.Library.FiscalReceipt();
            int output = mc.testFiscalReceiptClass();
            Console.WriteLine("Number of exception = {0}", output);
            System.Environment.Exit(0);
        }
    }
}

The issue is of course inside testFiscalReceiptClass:

namespace FiscalReceipt.Library
{
    public class FiscalReceipt
    {
        private PosExplorer posExplorer;
        private PosCommon posCommonFP;

        // Exception counter
        public static int NumExceptions = 0;
        public FiscalReceipt()
        {
            posExplorer = null;
            posCommonFP = null;
        }

        // Method to test the original FiscalReceiptClass
        public int testFiscalReceiptClass()
        {
            try
            {
                // Console.WriteLine("Initializing PosExplorer ");
                posExplorer = new PosExplorer();
            }
            catch (Exception e)
            {
                // ...    
            }
        }
    }
}

If I create posExplorer object from the console application there is no issue but when i try to debug NUnit it raises an exception:

{"The 'Microsoft.PointOfService.Management.Explorer' type initializer threw an exception."} InnerException {"This method explicitly uses security policies from obsolete code access in the .NET Framework. To enable security policy from code access for compatibility purposes, use the NetFx40_LegacySecurityPolicy configuration option. For more information, see http://go.microsoft.com/fwlink/?LinkID=155570. "} System.Exception { System.NotSupportedException}

enter image description here

It seems that Nunit is a 64-bit library that's incompatible with my DLL. I spent over 24 works hours to try many solution but I'm locked now.

Suggestions?

0

There are 0 answers