我正在使用版本9。我正在使用基于配置文件的配置。当我运行应用程序时,Mapper.Map ()方法将引发以下异常:
JobAssist.Services.ResumeBankMgmt.API.Application.ViewModels.ResumeBankViewModel需要具有0个args或仅可选args的构造函数。 (参数“类型”)
我不知道是什么原因造成的。
我正在使用版本9。我正在使用基于配置文件的配置。当我运行应用程序时,Mapper.Map ()方法将引发以下异常:
JobAssist.Services.ResumeBankMgmt.API.Application.ViewModels.ResumeBankViewModel需要具有0个args或仅可选args的构造函数。 (参数“类型”)
我不知道是什么原因造成的。
问题是我有一个参数的名称与我的类属性不完全相同。请参阅我将构造函数中的“类别”更改为“ resumeCategories”。
原始代码:
public class ResumeBankViewModel
{
public List<ResumeCategoryViewModel> ResumeCategories { get; set; }
public ResumeBankViewModel(int id,int jobSeekerID,List<ResumeViewModel> resumes,List<ResumeCategoryViewModel> categories)
新代码:
public class ResumeBankViewModel
{
public List<ResumeCategoryViewModel> ResumeCategories { get; set; }
public ResumeBankViewModel(int id,List<ResumeCategoryViewModel> resumeCategories)
,
假设您有权访问源代码,而您引用的源代码不在第三方程序中...
找到类ResumeBankViewModel
的定义(ViewModels \ ResumeBankViewModel.cs可能是一个不错的起点。)
并添加以下行:
public ResumeBankViewModel(){ }
如果有这样一行:
private ResumeBankViewModel() /* { etc. } */
或者这个:
internal ResumeBankViewModel() /* { etc. } */
您可以将private
/ internal
更改为public
。
您可能还希望查看已经定义的其他公共构造函数,并将一些适当的值传递给其中一个:
public ResumeBankViewModel() : this(value1,value2,value3) { }
或使其参数为可选:
public ResumeBankViewModel(object arg1 = value1,object arg2 = value2,object arg3 = value3)
所有这些可能都会导致您需要解决更多问题,但是其中一个是清除此错误的最低要求。