Description
Target name(s)
ALL
Firmware version
No response
Was working before? On which version?
No response
Device capabilities
No response
Description
In the nanoframework, we can load an assembly using the System.Reflection.Assembly.Load(byte[] rawAssembly)
method. We have noticed that sometimes this fails for no apparent reason. After analysis, it turned out that the problem occurs only for assemblies that require a static constructor thread to run.
In general, the whole mechanism works like this:
- Calculation and setting the timeout to 40ms
- Create a static constructor thread
- Exiting the method and waiting for timeout.
- Since the constructors thread has the highest priority, only it will be executed, after which the scheduler will find that there has been a timeout and will enter the load method again, where it will find that the assembly has been loaded and everything works as it should.
This is a happy path. However, it turns out that creating a static constructor thread allocates memory, and it may happen that it is necessary to run the Garbage Collector. It can takes a lot of time and when we get to WaitEvents, the timeout is over and the partially loaded assembly is destroyed. Unfortunately, the constructor thread is already created and after exiting the load method, it starts to be executed and then various strange things happen with HardFaults at the forefront :)
How to reproduce
No response
Expected behaviour
No response
Screenshots
No response
Aditional information
No response