fbpx
Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC: Dynamically loading XSharp assemblies

Dynamically loading XSharp assemblies 2 years 4 months ago #1035

  ArneOrtlinghaus's Avatar Topic Author ArneOrtlinghaus Away Posts: 126
When trying to load XSharp assemblies with the command VulcanLoadLibrary I received error messages. When substituting this by the function below it works, at least for assemblies without the automatically called init procedures.

But I have seen that it is better to call all initialization manually in the program.
I have seen that runtime errors in the init procedures are very hard to identify, whereas when calling them in the program the runtime errors are displayed with reasonable messages on the screen.

function xsLoadLibrary(libPath as string) as System.Reflection.Assembly
local pdll as System.Reflection.Assembly
pdll := System.Reflection.Assembly.LoadFrom(libPath)
return pdll

Please Log in or Create an account to join the conversation.

Dynamically loading XSharp assemblies 2 years 4 months ago #1039

  Chris's Avatar Chris Offline Posts: 1149
Hi Arne,

Thanks for reporting this, it is a bug (well, compatibility issue) in the compiler, as it generates assemblies with slightly different layout than VulcanLoadLibrary() expects. Should be easy enough to fix.

Chris
XSharp Development Team
chris(at)xsharp.eu

Please Log in or Create an account to join the conversation.

Dynamically loading XSharp assemblies 2 years 4 months ago #1040

  wriedmann's Avatar wriedmann Offline Posts: 1549
Hi Arne,

use Reflection! Since X# currently does not need initializations like the Vulcan runtime, you should be able to do it.

I'm doing this regularly:
foreach cDLLName as string in oDLLs
  cFullPath := Path.Combine( cPath, cDLLName )                           
  oAssembly := Assembly.LoadFrom( cFullPath )
  oClasses := Utility.AssemblyClasses( oAssembly, "ProdConfigBase.IConfiguration" )
  foreach cClassName as string in oClasses
    oConfiguration := ( IConfiguration ) oAssembly:CreateInstance( cClassName )
    if oConfiguration != null
      ++nLoaded
      oConfiguration:Initialize( oWindow, ProgSettings.Language )
      if oConfiguration:LastException != null
        MessageBox.Show( string.Format( e"Error loading configuration DLL {0}\n\n{1}\n\n{2}", cDLLName, oConfiguration:LastException:Message, oConfiguration:LastException:StackTrace ) )  
      endif
      ProgSettings.ProduktConfigurations:Add( oConfiguration )
    endif
  next
next

Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
This email address is being protected from spambots. You need JavaScript enabled to view it.
www.riedmann.it - docs.xsharp.it

Please Log in or Create an account to join the conversation.

  • Page:
  • 1