【发布时间】:2012-02-29 20:34:23
【问题描述】:
我目前有一个在 IIS 下的 Framework 2 上运行的 .Net 远程处理应用程序。我必须将它升级到 Framework 4 才能使用一些新组件。我已经能够在框架 2 上设置并顺利运行所有内容,但是一旦我更改为框架 4,当我尝试调用远程对象的函数之一时,就会出现以下异常。
The input stream is not a valid binary format.
The starting contents (in bytes) are:
53-79-73-74-65-6D-2E-52-75-6E-74-69-6D-65-2E-52-65 ...
这个错误不是真正的错误,它是由于远程对象抛出异常,而 IIS 将异常包装在 XML 中,这会引发 BinaryFormatter 关闭。 See this for more info on the bug.
这很不幸,因为我看不到导致异常的原因,并且之前从未使用过任何 Remoting,所以我对从哪里开始调试没有太多想法。似乎在进入代码之前就抛出了异常,因为我做了相当多的日志记录,但似乎都没有触发。
基本上,我正在从遇到类似问题的人那里寻找一些线索或指点:
- 除了没有代码更改之外,还有什么可能导致异常 从 .Net 2 编译到 .Net 4?
- 如何获取返回的完整异常消息?
这是获取远程对象的代码
Dim clientProvider As BinaryClientFormatterSinkProvider = New BinaryClientFormatterSinkProvider()
Dim serverProvider As BinaryServerFormatterSinkProvider = New BinaryServerFormatterSinkProvider()
serverProvider.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full
tsChannelName = System.Guid.NewGuid().ToString()
Dim props As IDictionary = New Hashtable()
props("port") = 0
props("name") = tsChannelName
props("typeFilterLevel") = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full
props("secure") = True
props("useDefaultCredentials") = True
Dim Channel As HttpChannel = New HttpChannel(props, clientProvider, serverProvider)
ChannelServices.RegisterChannel(Channel, False)
//Get the object on the Server
Dim rtnComm As I_CMQCComm = Activator.GetObject(GetType(I_CMQCComm), server)
//Knock knock
rtnComm.IsAlive() 'Exception is thrown here
我可以根据需要提供更多信息。
【问题讨论】:
-
您是否还为 .Net 4 编译了客户端代码?
-
是的!还将 IIS 更改为在 ASP.NET 4 上运行。通过将我的 Formatter 更改为 Soap,我设法看到了确切的错误。我刚刚设法解决了这个问题,我会发布一个答案:)
标签: c# .net vb.net remoting .net-remoting