0

I am really confused I have written some code that is reading some records from a database. If I compile it as an Application it works fine. If I compile it as a .dll and I call the .dll from another application the code doesn't work anymore (it returns all zeroes). This code is called in the Form_onShown()

Portfolios.Add(new NPortfolio(1, "1", activeContracts));
Dictionary<string, double> p = db.GetPortfolio(1,Today);
Portfolios[0].UpdatePositions(p);

var strContracts = new List<string>();                     
strContracts.Add(pf.p_id);
strContracts.AddRange(pf.getPositions().Select(o => o.Value.ToString()).ToList());

this return my stored database values when compiled as .exe and returns all 0 when compiled as .dll!!

the NPortfolio class is defined as follows:

    public NPortfolio(int nr, string id, List<string> ac)
    {
        p_nr = nr;
        p_id = id;
        positions = new Dictionary<string, double>();
        foreach (string ticker in ac)
        {
            positions.Add(ticker, 0.00);
        }
    }

    public void UpdatePositions(Dictionary<string, double> position)
    {
        foreach (var k in this.getPositions().Keys.ToList())
        {
            if (position.ContainsKey(k))
            {
                this.positions[k] = position[k];
            }
        }
    }

    public Dictionary<string, double> getPositions()
    {
        return positions;
    }
}

Any suggestion?

R.

prre72
  • 697
  • 2
  • 12
  • 23
  • 1
    Have you run through the debugger and stepped through the methods? – Ron Beyer Oct 14 '15 at 19:06
  • I don't know how to debug a .dll, the calling application runs on a different machine without IDE – prre72 Oct 14 '15 at 19:07
  • 1
    You can create a new project, refrence the dll and paste in the code you want to test. And then run it with the debugger. That is more or less what you are asking people here. – Dietz Oct 14 '15 at 19:09
  • Is it not possible to run the code locally? Can you install a remote debugger on the other machine? – Ron Beyer Oct 14 '15 at 19:09
  • Get that application from the different machine and run it on your machine. – Thomas Weller Oct 14 '15 at 19:17

1 Answers1

0

This code should run the same in .dll and .exe.

Most likely, since your 2 environements are set up differently, that is your problem, and there again, most likely the database that is giving the input or perhaps connection data you store. (The code that you have not shown.)

How did you pinpoint that exactly the code you posted is failing?

You can try:

  • execute working .exe on failing machine
  • get failing .exe to machine where you can debug (you can start the dll - if you do that, it will ask you what .exe you want to start for debugging, or you can set it in project properties)
  • insert logging for every step that might fail and execute on failing machine. Starting with the DB connection, how many records are received, and so on. This will get pretty tedious unless you find the problem early on.
Andreas Reiff
  • 7,961
  • 10
  • 50
  • 104
  • Very strage.. I tried to run the .exe on the failing machine and i get the following message: "AppName has stopped working, - Check online... - Close the program, - Debug the program – prre72 Oct 14 '15 at 19:31
  • That doesn't say much.. something internally went wrong, probably some unhandled exception. You can add your own handler for unhandled exceptions http://stackoverflow.com/questions/3133199/net-global-exception-handler-in-console-application and then log it/show a box/whatever, that should give you the info on what goes wrong. (use ex.ToString(), that includes both Stacktrace and message, which normally is very helpful.) – Andreas Reiff Oct 14 '15 at 19:53