agracio / edge-js

Run .NET and Node.js code in-process on Windows, macOS, and Linux
MIT License
618 stars 93 forks source link

cant call methods that use other packges #178

Closed binibakshi closed 4 months ago

binibakshi commented 1 year ago

when I perform simple methods ( return DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); etc..) it works fine but when I used methods that require other packages they failed in the example below Ping works fine but GetCertificate fails

I have tried different types of operations so far what I found is that it cant use packages that I installed via Nuget or external assemblies I download your demo project from here https://github.com/agracio/electron-edge-js-quick-start

@corylulu @vsilvar @andyrooger i would really appreciate your help if I missing something here p.s. this is really cool project thank you very much for it

using System.Security.Cryptography.X509Certificates; using System; using System.Threading.Tasks; using ExternalLibrary; using Newtonsoft.Json;

namespace QuickStart.Core { class ExternalMethods { private readonly Library _library = new Library();

    public async Task<object> GetPersonInfo(dynamic input)
    {
        return await Task.Run(() =>JsonConvert.SerializeObject(_library.GetPerson(), Formatting.Indented));
    }

    public async Task<object> Ping(dynamic input)
    {
        return "pong2";
    }

    public async Task<object> GetCertificate(dynamic input)
    {
        X509Certificate2 cert = null;
        X509Store store = new X509Store(StoreName.My, StoreLocation.CurrentUser);

        store.Open(OpenFlags.OpenExistingOnly);
        foreach (X509Certificate2 certificate in store.Certificates)
        {
            var certIssuer = certificate.GetIssuerName().Split(',');

            foreach (string issuer in certIssuer)
            {
                var issuerType = issuer.Split('=')[0].Trim();
                var issuerValue = issuer.Split('=')[1].Trim();

                if (issuerType == "O" && issuerValue == "PersonalID Ltd.")
                {
                    cert = certificate;
                    break;
                }
            }

            if (cert != null) break;
        }

        if (cert == null)
        {
            throw new Exception("No certificate found");
        }
        return cert;
    }
}

}

andyrooger commented 1 year ago

@binibakshi I don't think I'll be much help, sorry. All my experience with this library has been running JS from C# rather than the other way around, and in fact we've recently switched over to a different library entirely.

I would guess some kind of exception details might help others though... message, stack traces etc?