VS2010中的多目标:.NET 4 vs 2/3.5序列化问题 [英] multi targeting in VS2010: .NET 4 vs 2/3.5 serialization issue

查看:71
本文介绍了VS2010中的多目标:.NET 4 vs 2/3.5序列化问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,
在我们的团队中,我们开发了客户端/服务器应用程序,其中数据(自定义poco类)被序列化,压缩并通过WCF在服务器和客户端之间发送.
数据对象总是放在我们的自定义IList< T>中.在进行序列化之前(BinaryFormatter).因此,列表本身将被序列化/反序列化.
实际上,我们有2种IList< T>的实现:
a)"PocoList< T>"它实现了IListSource和IList< T>.序列化在此类中完成.
b)"PocoBindingList< T>"它实现了IBindingList,IList和IList< T>.主要思想是将此列表与客户端中的控件绑定.
因此,所有pocos和这些列表都是在两个解决方案共享的共同"项目中实现的.

Hello,
in our team, we develop a  client/server application where the data (custom poco classes) get serialized and compressed and sent via WCF between server and client.
The data objects are always put in our custom IList<T> before beeing serialized (BinaryFormatter). Tthus, the list itself is going to be serialized/deserialized.
We have actually 2 implementations of IList<T>:
a)'PocoList<T>' which implements IListSource and IList<T>. The serialization is done in this class.
b)'PocoBindingList<T>' which implements IBindingList, IList and IList<T>. The main idea is to bind this list with the controls in the client.
So all pocos and these lists are implemented in a 'common' project shared by both solutions.

只要我们在服务器中使用.NET 3.5,在客户端中使用2.0,就可以了.
昨天,我们将Server项目从.NET 3.5升级到了.NET4.客户端解决方案仍然针对.NET 2.0.两种解决方案都在VS2010中进行.

As long as we were using .NET 3.5 in server and 2.0 in client, it went fine.
Yesterday, we upgraded the Server projects from .NET 3.5 to .NET 4. The client solution is still targeted to .NET 2.0. We are working in VS2010 in both solutions.

现在,我在客户端收到BinaryFormatter的Deserialize方法中发生的以下异常:
  var serializer = new BinaryFormatter();
  object deserializedObject = serializer.Deserialize(dataStream);

Now I get in client the following exception which occurs in the Deserialize method of the BinaryFormatter:
 var serializer = new BinaryFormatter();
 object deserializedObject = serializer.Deserialize(dataStream);

"消息:
调用的目标已引发异常.

"Message:
Exception has been thrown by the target of an invocation.

Stacktrace:
  在System.RuntimeMethodHandle._SerializationInvoke处(对象目标,SignatureStruct& declaringTypeSig,SerializationInfo信息,StreamingContext上下文)
  在System.Reflection.RuntimeConstructorInfo.SerializationInvoke(对象目标,SerializationInfo信息,StreamingContext上下文)处
  在System.Runtime.Serialization.ObjectManager.CompleteISerializableObject(对象obj,SerializationInfo信息,StreamingContext上下文)下
  在System.Runtime.Serialization.ObjectManager.FixupSpecialObject(ObjectHolder持有人)处
  在System.Runtime.Serialization.ObjectManager.DoFixups()处
  在System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize处(HeaderHandler处理程序,__ BinaryParser serParser,布尔值fCheck,布尔值isCrossAppDomain,IMethodCallMessage methodCallMessage)
  在System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize处(Stream serializationStream,HeaderHandler处理程序,布尔fCheck,布尔isCrossAppDomain,IMethodCallMessage methodCallMessage)
  在System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream)
处   在E:\ Src_Eric \ Prosim \ Operation \ Prosim.Operation.Common \ Poco \ Base \ PocoList.cs:line 559中的Prosim.Operation.Common.Poco.PocoList`1.DecompressAndDeserialize(Byte [] compressedStream)   在Prosim.Operation.PresentationService.Editor.DataSupplier.DataSupplierBase`2.OnDataLoaded(IAsyncResult result)中的E:\ Src_Eric \ Prosim \ Operation \ Prosim.Operation.PresentationService \ Editor \ DataSupplier \ DataSupplierBase.cs:第170行

Stacktrace:
   at System.RuntimeMethodHandle._SerializationInvoke(Object target, SignatureStruct& declaringTypeSig, SerializationInfo info, StreamingContext context)
   at System.Reflection.RuntimeConstructorInfo.SerializationInvoke(Object target, SerializationInfo info, StreamingContext context)
   at System.Runtime.Serialization.ObjectManager.CompleteISerializableObject(Object obj, SerializationInfo info, StreamingContext context)
   at System.Runtime.Serialization.ObjectManager.FixupSpecialObject(ObjectHolder holder)
   at System.Runtime.Serialization.ObjectManager.DoFixups()
   at System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler handler, __BinaryParser serParser, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
   at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream, HeaderHandler handler, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
   at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream)
   at Prosim.Operation.Common.Poco.PocoList`1.DecompressAndDeserialize(Byte[] compressedStream) in E:\Src_Eric\Prosim\Operation\Prosim.Operation.Common\Poco\Base\PocoList.cs:line 559
   at Prosim.Operation.PresentationService.Editor.DataSupplier.DataSupplierBase`2.OnDataLoaded(IAsyncResult result) in E:\Src_Eric\Prosim\Operation\Prosim.Operation.PresentationService\Editor\DataSupplier\DataSupplierBase.cs:line 170

类型:
System.Reflection.TargetInvocationException

Type:
System.Reflection.TargetInvocationException

内部异常:

消息:
无法加载文件或程序集'System,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089'或其依赖项之一. Das System kann die angegebene Datei nicht finden.

Message:
Could not load file or assembly 'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. Das System kann die angegebene Datei nicht finden.

Stacktrace:
  在System.Reflection.Assembly._nLoad中(AssemblyName文件名,字符串codeBase,证据assemblySecurity,程序集locationHint,StackCrawlMark& stackMark,布尔throwOnFileNotFound,布尔值用于自省)
  在System.Reflection.Assembly.nLoad中(AssemblyName文件名,字符串codeBase,证据assemblySecurity,程序集locationHint,StackCrawlMark& stackMark,布尔型throwOnFileNotFound,布尔型用于自省)
   at System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef,证据assemblySecurity,StackCrawlMark& stackMark,用于自省的布尔值)
  在System.Reflection.Assembly.InternalLoad处(字符串assemblyString,证据assemblySecurity,StackCrawlMark& stackMark,用于自省的布尔值)
  在System.Reflection.Assembly.Load(String assemblyString)
  在System.Reflection.MemberInfoSerializationHolder..ctor(SerializationInfo信息,StreamingContext上下文)中

Stacktrace:
   at System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection)
   at System.Reflection.Assembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection)
   at System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
   at System.Reflection.Assembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
   at System.Reflection.Assembly.Load(String assemblyString)
   at System.Reflection.MemberInfoSerializationHolder..ctor(SerializationInfo info, StreamingContext context)

类型:
System.IO.FileNotFoundException"

Type:
System.IO.FileNotFoundException"

如果仅将客户端中的可执行文件目标为4,它将再次正常运行.但是在2.0或3.5中却没有,并且计划不很快在公司中推出.NET 4:我们控制服务器,但不是所有客户...

If I target only the executable in client to 4, it goes fine again. But in 2.0 or 3.5, it does not, and .NET 4 is not planed to be rolled out than soon in the company: we control our server but not all clients...


问题:当可执行文件(启动项目)以.NET 4为目标时,将DLL定向为.NET 2.0有什么影响?我们常见的MSIL代码是使用旧的2.0框架还是4框架来解释的?


QUESTION: what it the impact of targeting a DLL to .NET 2.0 when the executable (StartUp project) is target to .NET 4? Are the MSIL code in our common interpreted with the old 2.0 framework or 4 framework ?

我以前在dll在3.5中且启动项目指向4的服务器中遇到了类似的问题:尽管在我们的3.5 DAL中仍然有EF1.0,但我还是从EntityFramework4获得了异常! VS2010中的多目标问题中的另一个问题:将平台工具集"设置为"vc90"时,将CLI/C ++项目的目标框架自动修复为3.5很好!当前,它保留4个无法编译.我们必须编辑项目属性 在文本编辑器中!

I got previously similar problems in server where the dll were in 3.5 and startup project point in 4: I got exception from EntityFramework4 altough we had still EF1.0 in our 3.5 DAL!
Further issue in multi targeting problems in VS2010: it would be good to fix the target framework of the CLI/C++ project automatically to 3.5 when the 'Platform toolset' to 'vc90'! Currently, it stays 4 which cannot compiled. We had to edit the project properties in a text editor!


那么,VS2010中的多重定位如何工作?当我阅读此博客时,这并不像我那么简单:
http://weblogs.asp.net/scottgu/archive/2009/08/27/multi-targeting-support-vs-2010-and-net-4-series.aspx


So how works the multi targeting in VS2010? It is not simple as I though when I read this blog:
http://weblogs.asp.net/scottgu/archive/2009/08/27/multi-targeting-support-vs-2010-and-net-4-series.aspx

 

 

推荐答案

哪个版本是通用"版本?项目(由两个解决方案共享)正在运行?只要该项目使用的是2.0(客户端和服务器都使用的最低版本),序列化就不会引起问题.

Which version is the "common" project (shared by both solutions) running on? As long as that project is using 2.0 (the lowest version used by both the client and the server), the serialization shouldn't raise problems.

您可以向我们展示序列化的内容吗?它应该包含明确触发4.0 System.dll加载的内容

Can you show us the serialized content? It should contain something that's explicitly triggering the load of that 4.0 System.dll


这篇关于VS2010中的多目标:.NET 4 vs 2/3.5序列化问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆