agracio / edge-js

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

error CS0006: Metadata file 'JobTrackerAPI5.dll' could not be found #63

Closed TannerReynolds closed 3 years ago

TannerReynolds commented 5 years ago
Error: Unable to compile C# code.
----> Errors when compiling as a CLR library:
error CS0006: Metadata file 'JobTrackerAPI5.dll' could not be found
error CS0006: Metadata file 'JobTrackerAPI5.dll' could not be found
----> Errors when compiling as a CLR async lambda expression
error CS0006: Metadata file 'JobTrackerAPI5.dll' could not be found
error CS0006: Metadata file 'JobTrackerAPI5.dll' could not be found

This is my error.

I currently have two event files listening for incoming requests, both of which reference this dll, but only one of them works. The first event fires right when the webserver fully boots, and it compiles the C# code correctly, referencing this dll without any issue, and returning the expected values. However, the 2nd event fires whenever a document is signed. Once a document is signed the server will communicate with JobTracker by use of this dll provided to interact with their API using C#. But once that event fires, I get the error above.

Here is the code for my "onConnection" event

const edge = require("edge-js");
async function connection(_this) {
    let connectionTest = edge.func({
        source: () => {/*
            #r "JobTrackerAPI5.dll"
            using System;
            using System.Threading.Tasks;
            using System.IO;
            using System.Collections.Generic;
            using System.Linq;
            using System.Text;
            using System.Threading.Tasks;
            using Moraware.JobTrackerAPI5;
            public class Startup
            {
                public async Task<object> Invoke(dynamic input)
                {
                    var newDir = Directory.GetCurrentDirectory() + @"/temp";
                    Environment.CurrentDirectory = (newDir);
                    int jobid = (int)input.id;
                    var DB = (string)input.db;
                    string jobIDString = jobid.ToString();
                    string fileName = newDir + @"/" + @"signed-approval" + jobIDString + @".pdf";
                    var JTURL = "https://" + DB + ".moraware.net/";
                    var UID = (string)input.uid;
                    var PWD = (string)input.pwd;
                    Connection conn = new Connection(JTURL + "api.aspx", UID, PWD);
                    conn.Connect();
                    var job = conn.GetJob(jobid);
                    var jobName = job.JobName;
                    conn.Disconnect();
                    return fileName;
                }
            }
        */},
        references: ["JobTrackerAPI5.dll"]
    });
    connectionTest({id: _this.c.moraware.testJobID, uid: _this.c.moraware.uid, pwd: _this.c.moraware.pwd, db: _this.c.moraware.db}, (error, result) => {
        error 
            ? _this.log.error(`Error while making initial connection to https://${_this.c.moraware.db}.moraware.net:\n${error}`)
            : _this.log.success(`Successfully made initial connection to https://${_this.c.moraware.db}.moraware.net:\n${result}`)
    })
}

module.exports = connection

And here is the code for my "onSignature" event

const edge = require("edge-js");
const s = require("snekfetch")
async function approvalSigned(_this, jobID, dl) {
    let uploadToMoraware = edge.func({
        source: () => {/*
            #r "JobTrackerAPI5.dll"
            using System;
            using System.Threading.Tasks;
            using System.IO;
            using System.Collections.Generic;
            using System.Linq;
            using System.Text;
            using System.Threading.Tasks;
            using Moraware.JobTrackerAPI5;
            public class Startup
            {
                public async Task<object> Invoke(dynamic input)
                {
                    var newDir = Directory.GetCurrentDirectory() + @"\temp";
                    Environment.CurrentDirectory = (newDir);
                    int jobid = (int)input.id;
                    var DB = (string)input.db;
                    string jobIDString = jobid.ToString();
                    string filePath = newDir + @"/" + @"signed-approval" + jobIDString + @".pdf";
                    var JTURL = "https://" + DB + ".moraware.net/";
                    var UID = (string)input.uid;
                    var PWD = (string)input.pwd;
                    Connection conn = new Connection(JTURL + "api.aspx", UID, PWD);
                    conn.Connect();
                    var jf = new JobFile(jobid, "signed-approval.pdf");
                    var fi = new FileInfo(filePath);
                    conn.UploadJobFile(jf, fi, false);
                    conn.Disconnect();
                    return jobIDString;
                }
            }
        */},
        references: [`JobTrackerAPI5.dll`]
    });

    s.get(dl).then(r => {
        fs.writeFile(`${__dirname}/../../temp/signed-approval${jobID}.pdf`, r.body, err => {
            uploadToMoraware({id: jobID, uid: _this.c.moraware.uid, pwd: _this.c.moraware.pwd, db: _this.c.moraware.db}, (error, result) => {
                error 
                    ? _this.log.error(error)
                    : _this.log.success(result)
                fs.unlink(`${__dirname}/../../temp/signed-approval${jobID}.pdf`, err => {
                    err
                        ? _this.log.error(err)
                        : _this.log.success(`Successfully Deleted File: signed-approval${jobID}.pdf`)
                })
            });
        })
    })
}

module.exports = approvalSigned

Connection is called right when the server boots

async startServer() {
    this.events.connection(this)
    if(this.c.secure) {
        let privateKey = fs.readFileSync("key.pem");
        let certificate = fs.readFileSync("cert.pem");
        https.createServer({
            key: privateKey,
            cert: certificate
        }, this.app).listen(this.c.securePort);
        this.log.success(`Secure server listening on port ${this.c.securePort}`)
    } else {
        this.app.listen(this.c.port, () => {
            this.log.success(`Server listening on port ${this.c.port}`)
        })
    }
  }

and the signature is called whenever we get a signature.

const formidable = require("formidable")
const HelloParser = require(`${__dirname}/../../util/HelloParser.js`)
async function signature(req, res) {
    // Send Hellosign response
    res.statusCode = 200
    res.setHeader("Content-Type", "text/text")
    res.send("Hello API Event Received") // Has to be exactly this or callback URL will get reset
    res.end()

    let form = new formidable.IncomingForm()
    form.parse(req, (err, fields, files) => {
        let helloEvent = JSON.parse(fields.json)
        let parser = new HelloParser(helloEvent.signature_request.message)
        if(helloEvent.event.event_type === "signature_request_sent") {
            // This event will be finished last, after ApprovalSigned is confirmed working & uploading
        } else if(helloEvent.event.event_type === "signature_request_all_signed") {
            let mJobID = parser.morawareJobID()
            let dl = helloEvent.signature_request.files_url
            this.events.approvalSigned(this, mJobID, dl) // Send this, the job ID needed for uploading, and the download link to the approvalSigned function
            this.log.success("Document Signed!")
        } else return this.log.verbose(helloEvent.event.event_type)
    })
}
module.exports = signature
TannerReynolds commented 5 years ago

Fixed this.

For some reason, just using #r "JobTrackerAPI5.dll" works on my connection event, but not for the approvalSigned event. I had to create the reference using the entire file path. it is very odd that I have to use this method in one but not the other, similarly setup event.

RSS1102 commented 1 year ago

I also got this error when embedding c # inline in js :

Unable to compile C# code.\n----> Errors when compiling as a CLR library:\nerror CS0006: 未能找到元数据文件“fedm-cs-net5.0.dll”\n----> Errors when compiling as a CLR async lambda expression

I also create a reference from the project root path,get dll:

 references: [ '/src/dll/fedm-service-cs-net5.0.dll' ]