vb.net - "Value can not be null" on singleton instantiation -
i have singleton class attempting instantiate , giving exception "value cannot null"
im declaring reference in main form like:
dim devices deviceundertestbindinglist
then instantiating in form.load:
devices = deviceundertestbindinglist.getinstance
the deviceundertestbindinglist class follows:
imports system.componentmodel public class deviceundertestbindinglist ' deviceundertest 1 of other regular classes... inherits system.componentmodel.bindinglist(of deviceundertest) private shared singleinstance deviceundertestbindinglist private shared instancelock object private shared listlock object private sub new() mybase.new() end sub public shared readonly property getinstance deviceundertestbindinglist ' ensures 1 instance of list created. if singleinstance nothing synclock (instancelock) if singleinstance nothing singleinstance = new deviceundertestbindinglist end if end synclock end if return singleinstance end end property end class
i've used same pattern before no problems, of sudden causing exception, why?
please note: vb.net q! have read lot of c# q's deal similar problems did not understand them enough.
the problem cannot synclock
on null variable. can synclock
on valid instance of object. need change line:
private shared instancelock object
to this:
private shared instancelock new object()
Comments
Post a Comment