'The type initializer for 'Google.OrTools.ConstraintSolver.operations_research_constraint_solverPINVOKE' threw an exception

I have a google routing web service. it works in a local run project. but when I upload it on the host I get this error message:

The type initializer for 'Google.OrTools.ConstraintSolver.operations_research_constraint_solverPINVOKE' threw an exception.

notes

1-I use vs 2019 2- I set enable-32-bit-application to false in my Plesk host panel 3- I build my project in 64 bit 4- I installed google.ortool by the package manager download

my code is :

static List<int> PrintSolution(in RoutingModel routing, in RoutingIndexManager manager, in Assignment solution, ref bool HasErr, ref string ErrMsg)
{
    List<int> orderIndex = new List<int>();
    try
    {     
        long routeDistance = 0;
        var index = routing.Start(0);
        while (routing.IsEnd(index) == false)
        {           
            orderIndex.Add((int)index);
            var previousIndex = index;
            index = solution.Value(routing.NextVar(index));
            routeDistance += routing.GetArcCostForVehicle(previousIndex, index, 0);
        }     
    }
    catch (Exception e)
    {
        HasErr = true;
        ErrMsg = "GetIndexOrderLocations " + e.Message;
        orderIndex = null;
    }

    return orderIndex;
}

public static List<int> GetIndexOrderLocations(/String[] args/long[,] DistanceMatrix, ref bool HasErr, ref string ErrMsg)
{
    RoutingModel routing = null;
    RoutingIndexManager manager = null;
    Assignment solution = null;
    List<int> Result = new List<int>();
    try
    {
        // Instantiate the data problem.
        DataModel data = new DataModel();

        // Create Routing Index Manager
        manager = new RoutingIndexManager(/ data./ DistanceMatrix.GetLength(0), data.VehicleNumber, data.Depot);

        // Create Routing Model.
        routing = new RoutingModel(manager);

        int transitCallbackIndex = routing.RegisterTransitCallback((long fromIndex, long toIndex) => {
            // Convert from routing variable Index to distance matrix NodeIndex.
            var fromNode = manager.IndexToNode(fromIndex);
            var toNode = manager.IndexToNode(toIndex);
            return/* data.*/DistanceMatrix[fromNode, toNode];
        });

        // Define cost of each arc.
        routing.SetArcCostEvaluatorOfAllVehicles(transitCallbackIndex);

        // Setting first solution heuristic.
        RoutingSearchParameters searchParameters =
            operations_research_constraint_solver.DefaultRoutingSearchParameters();
        searchParameters.FirstSolutionStrategy = FirstSolutionStrategy.Types.Value.PathCheapestArc;

        // Solve the problem.
        solution = routing.SolveWithParameters(searchParameters);

        if (routing == null || manager == null || solution == null)
            return null;

        Result = PrintSolution(routing, manager, solution, ref HasErr, ref ErrMsg);

    }
    catch (Exception e)
    {
        HasErr = true;
        ErrMsg = "GetIndexOrderLocations " + e.Message;
    }

    // Print solution on console.
    return Result;
}

Why I get this error?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source