Compiling DLLs cross-referencing each other

This forum is meant for questions and discussions about the X# language and tools
Post Reply
alex_schmitt
Posts: 85
Joined: Wed Jan 23, 2019 7:54 pm
Location: Germany

Compiling DLLs cross-referencing each other

Post by alex_schmitt »

Hey all,

I am conducting my first attempts in migrating our project from VO and XS.

One thing I stumbled across was the following:

Assuming you have project A that uses a CLASS from project B and project B a CLASS from project A.
In VO it was possible to mutually reference between the two in the respective "Application Options" in the libraries tab.
  • If you would compile say project A it would compile everything except the part where project B is referenced (as this is not yet compiled).
  • So going back to project B and compiling project B it would compile everything except the part where project A is referenced.
  • So compiling project A would now succeed.
  • And finally, project B can be compiled.
Compiling project A in XS the compiler is looking for the DLL from project B, which is of course not there - and vice versa.

What would be the best practice to resolve this?

Best,
Alex
User avatar
SHirsch
Posts: 286
Joined: Tue Jan 30, 2018 8:23 am
Location: Germany

Compiling DLLs cross-referencing each other

Post by SHirsch »

Hello Alex,

you may extract all classes that are used in both projects to a new base library. Then you can compile your base lib and then set a reference in project A and project B to your new base lib.

Regards
Stefan
alex_schmitt
Posts: 85
Joined: Wed Jan 23, 2019 7:54 pm
Location: Germany

Compiling DLLs cross-referencing each other

Post by alex_schmitt »

Hey Stefan,

Thanks! I was fearing this step ;) But apparently now away around this. Apparently this is the cleanest way anyhow, even for VO.

Best,
Alex
User avatar
robert
Posts: 4522
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Compiling DLLs cross-referencing each other

Post by robert »

Alex,
You can also declare an interface for one of the classes and declare that interface in the other classlibrary.
Assume Class A and Class B, ClassLibrary A has Class A and ClassLibrary B has class B
You declare InterfaceB in classLibrary A and set a reference from ClassLibrary B to ClassLibrary A and add the "IMPLEMENTS InterfaceB" to the declaration of class B.
Inside ClassLibrary A you then replace the name ClassB with InterfaceB and it should work.

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
alex_schmitt
Posts: 85
Joined: Wed Jan 23, 2019 7:54 pm
Location: Germany

Compiling DLLs cross-referencing each other

Post by alex_schmitt »

Thanks Robert!

While digging deeper I found a lot of inter-project dependencies and the most straightforward way would likely be to place everything into one library. There's only 2-3 EXEs making use of it so that should still be valid.
I'll give it a try. Everything else seems to depict major refactoring.

Best,
Alex
User avatar
wriedmann
Posts: 3755
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

Compiling DLLs cross-referencing each other

Post by wriedmann »

Hi Alex,
you can also do something different: define the objects "as object" and use CreateInstance() to create the objects. This was you can prepare your code on the VO side before migration.
Is is not the cleanest method, but IMHO the most simple one, and the only one that let you have the same code on both the VO and the X# side.
Wolfgang
P.S. IMHO VO should never have admit these circular references. I have seen a project with many circular referenced applications that takes several hours (!) to compile in VO.
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
alex_schmitt
Posts: 85
Joined: Wed Jan 23, 2019 7:54 pm
Location: Germany

Compiling DLLs cross-referencing each other

Post by alex_schmitt »

Thanks, Wolfgang.

I could finally manage by merging all applications into one and it looks like I am on a good track with this.

I agree the circular references are not best practice at all, but as it worked and was convenient, I just used this ;)

Best,
Alex
User avatar
wriedmann
Posts: 3755
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

Compiling DLLs cross-referencing each other

Post by wriedmann »

Hi Alex,
merging into one application for sure is the easiest and safest option.
But when you are done with the migration you should think about splitting it up again in a different manner to make compilation times shorter.
Unlike VO (where only "dead" entities are compiled) the X# compiler (like the C# compiler) compiles the entire application every time.
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
alex_schmitt
Posts: 85
Joined: Wed Jan 23, 2019 7:54 pm
Location: Germany

Compiling DLLs cross-referencing each other

Post by alex_schmitt »

That's definitively a good hint, Wolfgang. I already see the differences in compile times :)
Post Reply