dotnet / iot

This repo includes .NET Core implementations for various IoT boards, chips, displays and PCBs.
MIT License
2.12k stars 574 forks source link

fix exception when disposing Ft232h device with SPI manager initialized #2270

Closed jb1685 closed 5 months ago

jb1685 commented 5 months ago

Summary of problem: When I initialize the Ft232h as a SPI device and then dispose of it, an InvalidOperationException error is thrown because we are disposing of the same elements from the list that we are iterating over.

Resolution: Make a copy of the "_managers" list by using "ToList" so that the iteration continues as we dispose from the target list

Example:

image

Path: /Users/joshbender/DocumentsLocal/Github/iot/src/devices/Ft232H/samples/Program.cs

image


Path: /Users/joshbender/DocumentsLocal/Github/iot/src/devices/Board/Board.cs

Microsoft Reviewers: Open in CodeFlow
jb1685 commented 5 months ago

@dotnet-policy-service agree

pgrawehr commented 5 months ago

/azp run dotnet.iot

azure-pipelines[bot] commented 5 months ago
Azure Pipelines successfully started running 1 pipeline(s).