使用 REST 入门工具包时出现 ASP.net 错误消息
我已经使用 REST 入门套件编写了一些代码,它在我的开发计算机上运行良好。但是,当我将其上传到我们的服务器时,页面会显示以下错误消息......
CS1684:警告错误:对类型“System.Runtime.Serialization.Json.DataContractJsonSerializer”的引用声称它是在“c:\WINNT\ assembly\GAC_MSIL\System.ServiceModel.Web\3.5.0.0__31bf3856ad364e35\System”中定义的.ServiceModel.Web.dll',但找不到
我已经逐行删除了代码,并且似乎以下代码行触发了错误......
HttpContent newOrganizationContent = HttpContentExtensions.CreateXmlSerializable(newOrganizationXml);
真的不知道如何修复它。我认为这可能是因为它需要更新版本的框架才能运行,但是在 IIS 中查看它说它正在运行版本 2.0.50727,我认为这是最新版本,因为它说即使我们使用框架 3.5 也
很困惑,有什么想法吗?
乔恩
I've written some code using the REST starter kit and it works fine on my development machine. However, when I upload it to our server the page gives me the following error message...
CS1684: Warning as Error: Reference to type 'System.Runtime.Serialization.Json.DataContractJsonSerializer' claims it is defined in 'c:\WINNT\assembly\GAC_MSIL\System.ServiceModel.Web\3.5.0.0__31bf3856ad364e35\System.ServiceModel.Web.dll', but it could not be found
I've removed code line by line and it appears that the following line of code is triggering the error...
HttpContent newOrganizationContent = HttpContentExtensions.CreateXmlSerializable(newOrganizationXml);
Really haven't got a clue how to fix it. I assumed it might be because it needs a newer version of the framework to run, but looking in IIS it says it's running version 2.0.50727 which I think is the lates version because it says that even when we're using framework 3.5
Very confused, any ideas?
Jon
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
起初我认为这可能是因为您要部署到的服务器没有安装 .NET Framework 3.5SP1,而仅安装了 .NET 3.5RTM。
但是,在检查 .NET 3.5 RTM
System.ServiceModel.Web.dll
程序集时,我发现System.Runtime.Serialization.Json.DataContractJsonSerializer
实际上已定义。编译器警告 CS1684 表明存在
System.服务器 GAC 中的 ServiceModel.Web.dll
程序集,但没有 System.Runtime.Serialization.Json。 DataContractJsonSerializer 定义。所以我要检查的事情是:
检查部署服务器是否至少运行 .NET 3.5 RTM,并且 Beta 版或候选版本未在使用或尚未遗留。
在 Visual Studio 2008 中,确保在项目属性中选择 .NET 3.5 的“目标框架”。
要确定问题是否与服务器的框架安装有关,您可以做的最后一项检查是启动一个简单的应用程序来直接使用
DataContractJsonSerializer
。 MSDN 文档页面上有该类的示例:作为最后的手段,如果服务器在您的控制之下,那么我会卸载 .NET Framework 3.5,然后从以下位置重新安装:
更新:
根据您的评论:
如果您运行的是 3.5 测试版,那么
DataContractJsonSerializer
可能不在System.ServiceModel.Web.dll
程序集。我似乎记得在 CTP、测试版和候选发布版期间,该领域发生了最新的重大变化。我依稀记得
DataContractJsonSerializer
是由于 JSON 的日益普及和社区压力而后来添加/更改的内容之一。我的记忆有点模糊,但还是很清晰。要替换 DLL,您需要从 GAC 取消注册当前版本,然后使用
GACUTIL.exe
工具注册 RTM 版本。我不建议混合 RTM 和 beta 位,你会让自己面临不可预测的行为。At first I thought this was possibly because the server you're deploying to didn't have .NET Framework 3.5SP1 installed and only .NET 3.5RTM.
However, upon checking a .NET 3.5 RTM
System.ServiceModel.Web.dll
assembly I see that theSystem.Runtime.Serialization.Json.DataContractJsonSerializer
is actually defined.The compiler warning CS1684 suggests that there is a
System.ServiceModel.Web.dll
assembly in the server's GAC, but one that doesn't have theSystem.Runtime.Serialization.Json. DataContractJsonSerializer
defined.So things I would check:
Check that the deployment server is running at least .NET 3.5 RTM and that a beta or release candidate isn't in use or hasn't been left over.
In Visual Studio 2008 make sure you select a "Target Framework" of .NET 3.5 in the project properties.
One final check you could do to see if the problem lies with the server's framework install is to knock up a simple application to consume the
DataContractJsonSerializer
directly. There's an example on the MSDN documentation page for the class:As a last resort, if the server is under your control then I'd uninstall .NET Framework 3.5 and then re-install from:
Update:
As per your comments:
If you're running a beta of 3.5 then chances are that
DataContractJsonSerializer
isn't in theSystem.ServiceModel.Web.dll
assembly.I seem to remember back around the CTP, betas and release candidates there were late breaking changes in this area. I vaguely remember the
DataContractJsonSerializer
was one of these late additions/changes due to the increased popularity of JSON and community pressure. My memory is a bit vague but it rings a bell.To replace the DLL you need to unregister the current version from the GAC then register the RTM one using the
GACUTIL.exe
tool. I wouldn't advise mixing RTM and beta bits, you're leaving yourself open to unpredictable behavour.