lazily-initialized类型没有公共的无参数构造函数。 [英] The lazily-initialized type does not have a public, parameterless constructor.
问题描述
大家好,
i有一个界面说如
hi all,
i have an interface say as
IInconsistencyReportSupport
。
class InconsistencyReportSupport实现接口IInconsistencyReportSupport。
接口具有方法ProcessInconsObjects和字典属性DictObjectAndDomains
我编写了单元测试来测试
.
class InconsistencyReportSupport implements interface IInconsistencyReportSupport.
the interface has the method ProcessInconsObjects and a dictionary property "DictObjectAndDomains"
I have written unittests to test the "
DictObjectAndDomains
。在单元测试中内部
".Inside the unittests
Public ReadOnly Property IRServiceSupport() As IInconsistencyReportSupport
Get
If mobjIRServiceSupport Is Nothing OrElse mobjIRServiceSupport.Value Is Nothing Then
mobjIRServiceSupport = New Lazy(Of IInconsistencyReportSupport)
End If
Return mobjIRServiceSupport.Value
End Get
End Property
在我的unittest中
In my unittest
Public Sub ExcludeSpecifiedCDWPropertiesCrossConfigTest()
IRServiceSupport.DictObjectAndDomains= pdictobjects
end sub
但是错误的是错误:
but is failing with erro:
Assert.Fail failed. System.MissingMemberException: The lazily-initialized type does not have a public, parameterless constructor.
at System.Lazy`1.CreateValue()
at System.Lazy`1.LazyInitValue()
at System.Lazy`1.get_Value()
请建议我如何验证字典
我尝试过:
i已尝试为该类添加默认构造函数,即使有相同的问题。建议如何继续进行
please suggest how can i validate the dictionary
What I have tried:
i have tried adding a default constructor for the class even have the same issue.pls suggest how to proceed further
推荐答案
Get
If mobjIRServiceSupport Is Nothing Then
mobjIRServiceSupport = New Lazy(Of IInconsistencyReportSupport)(Function() New InconsistencyReportSupport)
End If
Return mobjIRServiceSupport.Value
End Get
通过在属性中添加类类型来解决问题
fixed the issue by adding class type in the property
这篇关于lazily-initialized类型没有公共的无参数构造函数。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!