【发布时间】:2020-11-18 07:37:28
【问题描述】:
如何正确地从其他具有结构的类中创建类:
message ResultDto {
bool Result = 1;
repeated string Errors = 2;
ResultModuleDto Module = 3;
}
来自
message ResultModuleDto {
string Name = 1;
string Path = 2;
repeated SectionCollectionDto SectionCollection = 3;
}
message SectionCollectionDto {
string Name = 1;
string Path = 2;
repeated HelpFileDto Files = 3;
}
message HelpFileDto {
string Name = 1;
string Path = 2;
}
我尝试像类var module = new ResultModuleDto { Name = moduleDto.Name, Path = moduleDto.Path };一样创建
但我发现了 System.Memory 异常。
【问题讨论】:
-
显示的原型没有什么异常;您能否提供完整的异常消息和理想的堆栈跟踪?这应该工作正常。另外:您使用什么工具从原型中获取 C# 模型? (至少有 2 个我能想到,所以:这很重要)。更好的是一个可运行的示例来显示您在此处所做的事情 - 再次,显示的架构非常好且正常,因此它对上下文没有帮助。
-
消息:测试方法 Help.Servers.Tests.UnitTest1.StudyRepositoryService_A3s 引发异常:System.TypeInitializationException:“ResultDto”类型的初始化程序引发异常。 ---> System.IO.FileLoadException:无法加载文件或程序集“System.Memory,版本 = 4.0.1.0,文化 = 中性,PublicKeyToken = cc7b13ffcd2ddd51”或其依赖项之一。发现程序集清单定义与程序集引用不匹配。 (来自 HRESULT 的异常:0x80131040)。
-
堆栈跟踪:FieldCodec.ForString (UInt32 tag, String defaultValue) FieldCodec.ForString (UInt32 tag) line 56 ResultDto.cctor () line 101 --- 内部异常堆栈跟踪结束 --- ResultDto.ctor()HelpServiceGrpc.GetAllModules(ModuleDto moduleDto, ServerCallContext context) line 32
d__0.MoveNext() line 25 --- 从上一个位置结束的堆栈跟踪 -
抛出异常---TaskAwaiter.ThrowForNonSuccess(任务任务)TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)ThreadOperations.ExecuteWithAbortSafety(动作动作)