Page 1 of 1

Building and Using a dll

PostPosted: Thu Feb 14, 2008 7:04 pm
by khjklujn
I ran into a bit of difficulty trying to build a dll that could be used by referencing it with the -r: option.

I created a file to be used as a dll called Test1.cobra
namespace Bob
class Julie
pass

class George
pass


Then I created a file to use Julie and George called Test2.cobra
use Bob

class Program
def main is shared
print Julie()
print George()


When built together using the -files: option, everything worked as expected.

The way I got them to build independently was:

    copy Cobra.Lang.dll to the local directory
    cobra -t:lib -ert:no Test1.cobra
    cobra -r:Test1.dll Test2.cobra

Building Test1 without -ert:no resulted in redefinition of CobraImp and Tracer errors when I built Test2.

Building Test1 without -ert:no and Test2 with -ert:no resulted in:

error: COBRA INTERNAL ERROR / ArgumentException / An element with the same key already exists in the dictionary.An element with the same key already exists in the dictionary.An element with the same key already exists in the dictionary.An element with the same key already exists in the dictionary.

Re: Building and Using a dll

PostPosted: Thu Feb 14, 2008 11:48 pm
by Charles
I'll have to look into the internal error.

Also, when Cobra embeds the run-time, it needs to put a unique id on the Cobra.Lang namespace to avoid collisions.

Finally, I think that down the road, we'll slap Cobra.Lang.dll in the GAC and -ert will default to "no" with a default -r:Cobra.Lang.

Thanks for the report.

Re: Building and Using a dll

PostPosted: Fri Feb 15, 2008 2:04 pm
by khjklujn
Okay, one more issue. Using the same Test1.cobra from the previous example and changing Test2.cobra to:
class Program
def main is shared
print Bob.Julie()
print Bob.George()

results in an intermediate file with syntax errors:
Code: Select all
CobraImp.PrintLine(CobraImp.ToString((Bob.new Julie())));
CobraImp.PrintLine(CobraImp.ToString((Bob.new George())));

Re: Building and Using a dll

PostPosted: Fri Feb 15, 2008 8:27 pm
by Charles
Confirmed and will fix in the next release.

Re: Building and Using a dll

PostPosted: Fri Feb 15, 2008 11:29 pm
by Charles
Well one workaround is to contain the classes in two namespaces. It's only the "one parent namespace" case that breaks. The Cobra test cases for qualified types had two which is why this bug escaped me. I'm adding the "one" and "three" cases now. Only "one" is broken.