View Issue Details
| ID | Project | Category | View Status | Date Submitted | Last Update |
|---|---|---|---|---|---|
| 0001840 | NoesisGUI | C# SDK | public | 2020-11-19 18:01 | 2021-01-21 20:28 |
| Reporter | ai_enabled | Assigned To | sfernandez | ||
| Priority | normal | Severity | major | ||
| Status | assigned | Resolution | open | ||
| Product Version | 3.0.6 | ||||
| Summary | 0001840: NoesisGUI reloading issue: RunClassConstructor invokes static constructor to reinit dependency properties | ||||
| Description | Hi guys, I was investigating a few random issues we have and noticed NoesisGUI calling static constructors for our types even when they're already constructed. I understand why it's required (to force reconstructing the dependency properties), however, this is a very hacky solution as NoesisGUI just cannot be 100% sure that it will operate only with the UI-related code. In some cases it invoked static constructors causing reconstructing singletons and other fields that are totally not related to user controls or even UI logic. For example, imagine we have an item tooltip control that has a dependency property for the item itself. Item is a business entity so it will be never used in the UI directly, but NoesisGUI attempts to register the whole type hierarchy for it including all its public properties that may include things such as physics and audio. While it's a separate big problem in itself (how to handle that case to prevent NoesisGUI from registering certain types), it's a good demonstration when NoesisGUI should not just straight away "reconstruct" types. The side effects could be awful and very hard to debug! Here is the block of code that is causing the issue: An idea how you can resolve this issue: as you're using this solely to reconstruct the dependency/attached properties, perhaps you should cache all the dependency properties in a Dictionary<Type, RegisteredDependencyProperty[]>. When RunClassConstructor notices that the type was once constructed, it can just foreach the RegisteredDependencyProperty[] array and force their registration. Regards! | ||||
| Platform | Any | ||||
| related to | 0001897 | resolved | sfernandez | .NET 5 has broken RunClassConstructor workaround |
|
Hi, This code is a big hack that we don't like either, but it had no problems when we initially designed it for Unity, because it was only used when assemblies were unloaded and reloaded again. I think the first thing to do to improve that code is avoid calling the static constructor if the type doesn't contain any DependencyProperty field. Keeping track of previously defined DependencyProperties is not an option because the code of the classes could have changed and new dependency properties added or removed. What do you think? |
|
|
|
|
Yes, Unity unloads current assembly, compiles a new one with any changes you have made to your classes, and loads the new assembly. |
|
|
Ok, then It's the same as what we have for CryoFall live reloading—assemblies are just rebuilt and the data is re-serialized. Then my original suggestion should work fine:
As the old types are no longer used their instances will just lie down forever in the dictionary. New types will be registered as new entries in the dictionary, and have their static constructor called only once. And if you need to rebuild the type in RunClassConstructor, you will need to call re-registering of the previously registered dependency properties instead of force calling the static constructor. The only challenge here is to wrap all the dependency properties (when they're registered for the first time), so you can call their registration again when necessary for the specific type. |
|
|
Further discussion in this ticket https://www.noesisengine.com/bugs/view.php?id=1897#bugnotes |
|
| Date Modified | Username | Field | Change |
|---|---|---|---|
| 2020-11-19 18:01 | ai_enabled | New Issue | |
| 2020-11-19 19:23 | sfernandez | Assigned To | => sfernandez |
| 2020-11-19 19:23 | sfernandez | Status | new => feedback |
| 2020-11-19 19:23 | sfernandez | Note Added: 0006774 | |
| 2020-11-19 19:53 | ai_enabled | Note Added: 0006775 | |
| 2020-11-19 19:53 | ai_enabled | Status | feedback => assigned |
| 2020-11-19 20:16 | sfernandez | Status | assigned => feedback |
| 2020-11-19 20:16 | sfernandez | Note Added: 0006776 | |
| 2020-11-19 20:30 | ai_enabled | Note Added: 0006777 | |
| 2020-11-19 20:30 | ai_enabled | Status | feedback => assigned |
| 2021-01-21 18:11 | sfernandez | Relationship added | related to 0001897 |
| 2021-01-21 20:28 | ai_enabled | Note Added: 0006985 |