我已經接收到錯誤嘗試使用在AutoMapper定製解析器,其拋出體REF錯誤
{「對象引用不設置爲一個對象的一個實例。」}
時試圖用一個自定義的解析器(強迫任何返回NULL使用值的默認設置),像這樣:
public class AnswersResolver : IValueResolver<SurveyMonkey.Containers.Question, Question, QuestionAnswers>
{
public QuestionAnswers Resolve(SurveyMonkey.Containers.Question source, Question destination, QuestionAnswers destMember, ResolutionContext context)
{
if (source.Answers != null)
{
QuestionAnswers q = Mapper.Map<QuestionAnswers>(source.Answers);
return q;
}
else
{
QuestionAnswers q = new QuestionAnswers
{
Id = source.Id * 100000,
Choices = {},
Cols = { new Column { Choices = { } } },
Other = new OtherAnswer { Text = "NO ANSWER" },
Rows = { new Row { Text = "NO ANSWER" } }
};
Choice c = new Choice { Description = "No ANSWER REQUIRED", Position = 0, Items = { }, QuestionAnswersId = q.Id.GetValueOrDefault(), QuestionAnswers = q };
q.Choices.Add(c);
q.Cols[0].Choices.Add(c);
q.Cols[0].QuestionAnswers = q;
q.Cols[0].QuestionAnswersId = q.Id.GetValueOrDefault();
q.Rows[0].QuestionAnswers = q;
q.Rows[0].QuestionAnswersId = q.Id.GetValueOrDefault();
return q;
}
}
}
當我把一個破發點我成功地循環反覆幾次,一其中包含的問題,並且包含頁面包含(部分)相同的問題對象 - d的誤差是在Automapper.map命令調查拋出。
編輯:如請求
AutoMapper.AutoMapperMappingException錯誤消息是未處理的HResult = -2146233088 消息=錯誤映射類型。
映射類型: 調查 - >調查 SurveyMonkey.Containers.Survey - > SurveyMonkeyAPIv3.Survey
類型地圖配置: 調查 - >調查 SurveyMonkey.Containers.Survey - > SurveyMonkeyAPIv3.Survey
性能: 問題 來源=匿名託管的DynamicMethods程序集 StackTrace: at lambda_method(Closure,Object,Object,ResolutionContext) 在SurveyMonkeyAPIv3.Program.DefinedSurveyCalls(SurveyContext調查,字符串APIKey,字符串令牌,Int64的[] ValidSurveys)在C:\ Surveymonkeytake2 \ SurveyMonkeyAPIv3 \ Program.cs的:線77 在SurveyMonkeyAPIv3.Program.Main(字串[] args)用C :\ Surveymonkeytake2 \ SurveyMonkeyAPIv3 \ Program.cs:line 41 at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly,String [] args) at System.AppDomain.ExecuteAssembly(String assemblyFile,Evidence assemblySecurity,String [] args) at Microsoft System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext,ContextCallback callback,Object state,Boolean preserveSyncCtx)在System.Threading.ThreadHelper.ThreadStart_Context(對象狀態) 在S上的.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() 在System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback回調,對象狀態) (在System.Threading.ThreadHelper.ThreadStart())上執行ystem.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback callback,Object state,Boolean preserveSyncCtx) 的InnerException: 的HResult = -2146233088 消息=錯誤映射類型。
映射類型: 問題 - >問題 SurveyMonkey.Containers.Question - > SurveyMonkeyAPIv3.Question
類型地圖配置: 問題 - >問題 SurveyMonkey.Containers.Question - > SurveyMonkeyAPIv3。問題
性質: 問答 源=匿名託管DynamicMethods大會 堆棧跟蹤: 在lambda_method(封閉,對象,對象,ResolutionContext) 的InnerException: 的HResult = -2147467261 消息=對象未設置爲的一個實例參考一個東西。 源= SurveyMonkeyAPIv3 堆棧跟蹤: 在SurveyMonkeyAPIv3.AnswersResolver.Resolve(問題源,問題目的地,QuestionAnswers destMember,ResolutionContext上下文)在C:\ Surveymonkeytake2 \ SurveyMonkeyAPIv3 \的Program.cs:線854 在lambda_method(封閉,對象,對象,ResolutionContext) 的InnerException:
有,去年內部異常
發佈實際的錯誤消息/堆棧跟蹤 –