Skip to content

Problem with loading assemblies #1330

Open
@MateuszKlatecki

Description

@MateuszKlatecki

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:

  1. Calculation and setting the timeout to 40ms
  2. Create a static constructor thread
  3. Exiting the method and waiting for timeout.
  4. 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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions