Loading User Assemblies

Loading User Assemblies

Here is how user assemblies are loaded and how paths are resolved.

Earlier we discussed the CTP file. In the CTP file we specified the full path to user assemblies. For example:

USER:C:sourceCrossTalksourceCrossTalkRightTestbinDebugCrossTalkRightTest.dll

The full path is fine and needed during the generation phase. However the generator also emits this path into the .pas files. In CTCrossTalkRightTest.pas this is generated:

initialization
  LoadAssembly(‘C:sourceCrossTalksourceCrossTalkRightTestbinDebugCrossTalkRightTest.dll’);
end.

This will work while debugging, however you are unlikely to deploy your assembly in this location on your users machines. You could change this path, however it a .pas file that is autogenerated and not intended for changes. Because of this, at runtime CrossTalk will actually try to load the assembly first from the User Path.

User Path

The User Path is the path where the application that calls CrossTalk exists. Normally this is your exe, but if you put your CrossTalk units in a DLL or a package, then the User Path will be the path where that DLL or package exists. This may or may not be the same as the exe.

So in our example the Delphi code creates an exe and it is deployed to C:Program FilesMy Appapp.exe, then CrossTalk would first look for C:Program FilesMy AppCrossTalkRightTest.dll. If CrossTalk does not find it there, then it will look in the actual path specified.

This allows for easy deployment, and debugging scenarios.

Gotcha

The one thing you need to watch out for is during debugging. If you happen to copy the assembly to the application directory for testing, remember that CrossTalk will always give it priority over your debug version even if you rebuild the debug version. We considered looking for both and loading the newer one, but this also has side effects.