Symptom

When you use .NET DataStore in SnapDevelop, you may see this error when running your project: KeyNotFoundException: DataWindow 'XXX' not found.

Cause

In order to use .NET DataStore in a C# project, you need to invoke a method to parse the corresponding DataWindows before using them. 

In SnapDevelop, if you create a ASP.Net Core Web API project, there will be an app.UseDataWindow() in StartUp.cs by default, it will parse all DataWindows when starting up.

If you create a different type of project (e.g.: Console App, Class Library) which is not ASP.Net Core Web API project, you need to add the code yourself to parse the DataWindows.

Resolution

Before initiating a DataStore object, call the DataObjectFactory.LoadDataWindowLazy() method or the DataObjectFactory. LoadDataWindow() method to parse the DataWindows registered in .pbw files.

  • The DataObjectFactory.LoadDataWindowLazy() method only parses each DataWindow when used.
  • The DataObjectFactory.LoadDataWindow() method parses all DataWindows at one time.

Notes:

  • For any type of project, make sure that you use the Generate Model function in PowerBuilder to merge your DataWindows to the Web API project.
  • Check whether the DataWindow has been registered in .pbwconfig files (it has been changed from .pbw to .pbwconfig since PB2019 beta 3).
  • If you right click on the .pbwconfig or the .srd file and select 'properties' you should see 'Copy if newer' option in 'Copy to directory' category.
4
1