MVC 反序列化错误
好的。这是我公司的客户门户,它是一个 MVC 2 项目。我们有一个后端 SAP 系统,门户可以从中提取数据。但它并不直接访问 SAP,而是向 VB 应用程序发送一个 xml 请求,该应用程序获取数据并将其以 xml 响应形式发回。有一个接口 IRequest
,所有各种请求都实现该接口,示例为 CustomerNumberRequest
、CompanyNameRequest
等。这些都实现了方法 ToXml
顾名思义,它只是构建要发送的 xml。所有现有请求都工作正常。 (首先我要说的是,我继承了这个项目,而编写该项目的人已经不在我们身边了)我现在正尝试发送请求以从 SAP 获取代表组。我基本上逐字复制了其他请求之一,进行了必要的调整以发送适当的请求。但它一直失败并出现我不明白的错误消息:
格式化程序抛出异常 尝试反序列化消息: 尝试时出现错误 反序列化参数 http://tempuri.org/:request。这 InnerException 消息是 'The 解串器无法将类型加载到 反序列化,因为类型 'XXXXX.CustomerPortal.Domain.RepGroupRequest' 在程序集中找不到 'XXXXX.CustomerPortal.Domain, 版本=1.0.0.0,文化=中立, PublicKeyToken=null'。检查是否 被序列化的类型具有相同的 合同的类型是 反序列化并且相同的程序集是 用过的。'。请参阅内部异常 更多详细信息。
此错误发生在 _communicationService.ProcessRequest(request);
(如下所示)它不会进入 ProcessRequest
方法,它只是尝试创建一个 NetDataContractSerializer
> 这里:
public override XmlObjectSerializer CreateSerializer(Type type, XmlDictionaryString name, XmlDictionaryString ns, IList<Type> knownTypes)
{
return new NetDataContractSerializer();
}
然后它就死了。这些是被调用的方法:
private void PopulateRepGroups()
{
List<string> repGroups = new List<string>();
RepGroupRequest request = new RepGroupRequest();
foreach (RepGroup repGroup in _repService.GetRepGroups(request))
repGroups.Add(repGroup.RepGroupName);
ViewData["RepGroups"] = new SelectList(repGroups);
}
public List<RepGroup> GetRepGroups(RepGroupRequest request)
{
string response = _communicationService.ProcessRequest(request);
return RepGroupResponseFactory.GetRepGroupResponse(response);
}
谁能告诉我这个错误消息告诉我什么?它说找不到类型,但类型应该是 IRequest(这就是当 CreateSerializer
被点击时它所说的),这是在整个过程中使用的。我显然迷路了,请帮忙!
Okay. This is my company's customer portal, it's an MVC 2 project. We have a back end SAP system that the portal draws data from. But it does not directly hit SAP, it sends an xml request to a VB app that gets the data and sends it back in an xml response. There is an interface IRequest
that all the various requests implement examples would be CustomerNumberRequest
, CompanyNameRequest
, etc. These all implement the method ToXml
which as the name suggests simply builds xml to send. All of the existing requests work fine. (Let me preface this by saying that I inherited this project and the guy who wrote it is no longer with us) I am now trying to send a request to get the Rep Groups from SAP. I basically copied one of the other requests verbatim, making the necessary tweaks to send the appropriate request. But it keeps failing with error messages that I don't understand:
The formatter threw an exception while
trying to deserialize the message:
There was an error while trying to
deserialize parameter
http://tempuri.org/:request. The
InnerException message was 'The
deserializer cannot load the type to
deserialize because type
'XXXXX.CustomerPortal.Domain.RepGroupRequest'
could not be found in assembly
'XXXXX.CustomerPortal.Domain,
Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null'. Check that the
type being serialized has the same
contract as the type being
deserialized and the same assembly is
used.'. Please see InnerException for
more details.
This error happens right at _communicationService.ProcessRequest(request);
(shown below) It does not enter the ProcessRequest
method it just tries to create a NetDataContractSerializer
here:
public override XmlObjectSerializer CreateSerializer(Type type, XmlDictionaryString name, XmlDictionaryString ns, IList<Type> knownTypes)
{
return new NetDataContractSerializer();
}
and then it dies. These are the methods being called:
private void PopulateRepGroups()
{
List<string> repGroups = new List<string>();
RepGroupRequest request = new RepGroupRequest();
foreach (RepGroup repGroup in _repService.GetRepGroups(request))
repGroups.Add(repGroup.RepGroupName);
ViewData["RepGroups"] = new SelectList(repGroups);
}
public List<RepGroup> GetRepGroups(RepGroupRequest request)
{
string response = _communicationService.ProcessRequest(request);
return RepGroupResponseFactory.GetRepGroupResponse(response);
}
Can anybody tell me what this error message is telling me? It says the type cannot be found but the type should be IRequest (that's what it says when the CreateSerializer
is hit) which is used all over this. I'm clearly lost, please help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
引用你的异常
集 检查 CustomerPortal.Domain.RepGroupRequest 所在两端的库版本,以确保它们是完全相同的版本。
Quoting your exception
Check the version of the library on both ends that CustomerPortal.Domain.RepGroupRequest resides in to make sure they are the same version exactly.