# Thread safe variable management for Custom Classes

**URL:** <https://forums.powershell.org/t/thread-safe-variable-management-for-custom-classes/14659>\
**Category:** PowerShell Help\
**Created:** [July 13, 2020, 8:41am UTC](https://forums.powershell.org/t/thread-safe-variable-management-for-custom-classes/14659 "2020-07-13T08:41:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![monterey610](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/monterey610/32/1080_2.png) [@monterey610](https://forums.powershell.org/u/monterey610)\
**Post date:** [July 13, 2020, 8:41am UTC](https://forums.powershell.org/t/thread-safe-variable-management-for-custom-classes/14659/1 "2020-07-13T08:41:37Z")

</div>

Issue is I am trying to use parallelization to add a generated object which is a custom object.

&nbsp;

My custom class is

`class Foo{`

`[string]$AuditArea`  
`[string]$FooName`  
`[String]$FooId`

`Foo () {}`  
`}`

`$Records = [System.Collections.Concurrent.Concurrentbag[Foo]]::new()`

`$bar = [Foo]::New()`

`$Records.tryadd($bar)`

`MethodException: Cannot convert argument "item", with value: "", for "TryAdd" to type "Foo": "Cannot convert the "Foo" value of type "Foo" to type "Foo"."`

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:29pm UTC](https://forums.powershell.org/t/thread-safe-variable-management-for-custom-classes/14659/2 "2024-05-16T20:29:15Z")

</div>


