Symptom

When running PowerBuilder applications in PowerBuilder IDE, it always fails to call some .NET Assembly methods.

If you run in debug mode, you can see that an exception is caused by a failure to load a higher version of the .NET assembly.

System.IO.FileLoadException: An exception of type 'System.IO.FileLoadException' occurred in ClassLibrary1.dll but was not handled in user code: 'Could not load file or assembly 'System.Configuration.ConfigurationManager, Version=7.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. Could not find or load a specific file. (0x80131621)'
Inner exceptions found, see $exception in variables window for more details.
Innermost exception: System.IO.FileLoadException

Environment

PowerBuilder 2022 R3 and later

Cause

PowerBuilder 2022 R3 IDE only supports loading .NET 6 and lower versions of assembly by default.

If your .NET library is .NET 6, but it references one or more assemblies of a higher version of .NET (such as .NET 7/8), these assemblies will not be loaded as expected.

Resolution 1

Modify your .NET library project to reference a .NET 6 version assembly.

Resolution 2

Modify all .runtimeconfig configurations loaded when PowerBuilder IDE is running:

a) Modify three .runtimeconfig files under the PowerBuilder IDE folder (e.g.: C:\Program Files (x86)\Appeon\PowerBuilder 22.0\IDE))

Add "rollForward":"LatestMajor" to support loading the latest local .NET major version.

  • pbdevproxy.runtimeconfig.json
{
  "runtimeOptions": {
    "tfm": "net6.0",
    "frameworks": [
      {
        "name": "Microsoft.NETCore.App",
        "version": "6.0.0"
      },
      {
        "name": "Microsoft.WindowsDesktop.App",
        "version": "6.0.0"
      }
    ],
    // Enable rollForward
    "rollForward":"LatestMajor",
    "configProperties": {
      "System.Reflection.Metadata.MetadataUpdater.IsSupported": false
    }
  }
}
  • mainviewinterop.runtimeconfig.json
{
  "runtimeOptions": {
    "tfm": "net6.0",
    "frameworks": [
      {
        "name": "Microsoft.NETCore.App",
        "version": "6.0.0"
      },
      {
        "name": "Microsoft.WindowsDesktop.App",
        "version": "6.0.0"
      }
    ],
    // Enable rollForward
    "rollForward":"LatestMajor",
    "configProperties": {
      "System.Reflection.Metadata.MetadataUpdater.IsSupported": false
    }
 }
}
  • PBInvokeDotNET.runtimeconfig.json
{
  "runtimeOptions": {
    "tfm": "net6.0",
    "frameworks": [
      {
        "name": "Microsoft.NETCore.App",
        "version": "6.0.0"
      },
      {
        "name": "Microsoft.WindowsDesktop.App",
        "version": "6.0.0"
      }
    ],
    // Enable rollForward
    "rollForward":"LatestMajor",
    "configProperties": {
      "System.Reflection.Metadata.MetadataUpdater.IsSupported": false
    }
  }
}

b) Modify the pbdotnetinvoker.runtimeconfig.json configuration file (including files under the X64 folder) under the PowerBuilder runtime package to support .NET rollForward.

E.g.: C:\Program Files (x86)\Appeon\Common\PowerBuilder\Runtime 22.2.0.3289\pbdotnetinvoker.runtimeconfig.json

{
  "runtimeOptions": {
    "tfm": "net6.0",
    "frameworks": [
      {
        "name": "Microsoft.NETCore.App",
        "version": "6.0.0"
      },
      {
        "name": "Microsoft.WindowsDesktop.App",
        "version": "6.0.0"
      }
    ],
    // Enable rollForward
    "rollForward":"LatestMajor"
  }
}

c) Restart your PowerBuilder IDE.

2
2