Unable to execute dll remotely

0

I am quite new to C# application development.

I have made a C# console application which I execute like this

dotenet.exe <dll_name>

This works fine when executed on the system. But I need to call this remotely. I am doing that through Powershell Invoke Command. But I am getting this error.

System.Runtime.InteropServices.COMException: Retrieving the COM class factory for component with CLSID {D66FBAAE-4150-402F-8581-75D1652D696A} failed due to the following error: 80080005 Server execution failed (Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE)). at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor)
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) at System.Activator.CreateInstance(Type type, Boolean nonPublic) at System.Activator.CreateInstance(Type type)

Please note that I have tried many possible solutions on the net:

  • Tried changing target for C# app to x86, this doesn't work as the references to the app are x64

Details about the environments:

  • Remote is x64
  • Client is x64

EDIT

Please find the source code of the dll. This is used for file conversion to a format.

using System.Runtime.InteropServices;
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System;
using System.IO;
using System.Linq;

public class SolidWorkFileConverter
{
    private SldWorks swApplication;
    public SolidWorkFileConverter(SldWorks swApp)
    {
        swApplication = swApp;
    }

    public void ToPdf(string searchPath, string logFileName)
    {
        var logFileDestionation = System.IO.Path.Combine(searchPath, logFileName);
        var currentDate = DateTime.Now;
        var partFiles = System.IO.Directory.EnumerateFiles(searchPath, "*.sldprt", SearchOption.AllDirectories)
                                              .Where(file => !file.Contains("~$"));
        foreach (var drawingFile in partFiles)
        {
            ToStep(drawingFile);
        }
        WriteToLog(logFileDestionation, currentDate);
    }

    public void ToStep(string partFile)
    {
        string destinationDirectory = Path.GetDirectoryName(partFile);
        destinationDirectory = destinationDirectory + "\\output\\";
        string destinationFile = Path.GetFileName(partFile);

        string destinationFileName = ComposeDestinationFileName(Path.Combine(destinationDirectory, destinationFile));
        CreateDestinationDirectory(destinationFileName);


        int state = 0;
        bool status;
        int warningState = 0;
        ModelDoc2 swDoc = (ModelDoc2)(swApplication.OpenDoc6(partFile, 3, 0, "", ref state, ref warningState));
        int warnings = 0;
        int errors = 0;
        PartDoc swPart = (PartDoc)swApplication.OpenDoc6(partFile, (int)swDocumentTypes_e.swDocPART, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref errors, ref warnings);
        ModelDoc2 swModel = (ModelDoc2)swPart;
        ModelDocExtension swModelDocExt = (ModelDocExtension)swModel.Extension;


        status = swModelDocExt.SaveAs(destinationFileName, 0, (int)swSaveAsOptions_e.swSaveAsOptions_Silent, null, ref errors, ref warnings);

        swDoc = null;
        swApplication.CloseAllDocuments(true);
    }

    private string ComposeDestinationFileName(string sourceFileName)
    {
        return sourceFileName.Replace("PARTS", "STEP").Replace("SLDPRT", "STEP");
    }

    private void CreateDestinationDirectory(string destinationFileName)
    {
        string directoryName = System.IO.Path.GetDirectoryName(destinationFileName);
        System.IO.Directory.CreateDirectory(directoryName);
    }

    private void WriteToLog(string logFileDestination, DateTime currentDate)
    {
        System.IO.File.WriteAllText(logFileDestination, currentDate.ToShortDateString());
    }
}


static class Program
{
    static void Main(string[] args)
    {
        string username = "";
        for (int i = 0; i < args.Length; i++)
        {
            if (args[i] == "-user")
            {
                username = args[i + 1];
            }
        }
        string searchPath = "some path"
        string logFileName = System.IO.Path.Combine(searchPath, "UpdatedPDFs.txt");

        //SldWorks swApp = new SldWorks();
        SldWorks swApp = Activator.CreateInstance(Type.GetTypeFromProgID("SldWorks.Application")) as SldWorks;

        SolidWorkFileConverter converter = new SolidWorkFileConverter(swApp);
        converter.ToPdf(searchPath, logFileName);
    }
}

Edit 2

The powershell command used for remote invocation

Invoke-Command -ComputerName mycomputer -ScriptBlock { & dotnet.exe convert.dll } -credential  mydomain\administrator
c#
.net
powershell
asked on Stack Overflow Nov 22, 2017 by Keval Doshi • edited Nov 24, 2017 by Keval Doshi

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0