无法找到程序集“client, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null 问题解决总结

本文讨论了在使用C/S结构编写聊天程序时遇到的对象序列化与反序列化问题,通过创建DLL类库使服务器和客户端程序统一命名空间,成功解决了类不一致导致的对象反序列化错误。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

      最近在写一个小的聊天程序,用的是C/S结构,服务器程序一个解决方案,客户端程序一个解决方案。

      但是昨天在将对象序列化和反序列化上出现了问题,我写了一个MyMessage类和一个Serializer类,分别写在服务器程序和客户端程序中了。这两个单独测试都没有问题,可是客户端程序在发送消息给服务器程序时,服务器程序在反序列化对象是总是提示:"无法找到程序集“client, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null ”。找了N久也不知道问题出在哪儿,后来在网上搜别人的帖子,发现不是我一个遇到了这种问题。但是有很多人也说不清楚到底是什么原因导致了上述错误 。

     后来终于找到了一个帖子,终于明白错误原因是四个类分处于服务器命名空间下和客户端命名空间下,命名空间的不一致也就是类的不一致导致了对象在反序列化时出现错误。

     解决办法就是写一DLL类库,然后让服务器程序和客户端程序都引用这一个类库,这就解决了类不一致的问题!那么对象在反序列化时就不会出错了!问题KO了!

     怕我自己会忘记,也为了让其他对此感兴趣的朋友遇到与我相同的问题能很快解决,作文以记之!

     本人菜鸟一只,如果我理解的有什么不对的地方,还请高手指点一二!

<?xml version="1.0" encoding="utf-8"?> <!-- 有关如何配置 ASP.NET 应用程序的详细信息,请访问 https://go.microsoft.com/fwlink/?LinkId=169433 --> <configuration> <connectionStrings> <add name="DB-NetShopsConnectionString" connectionString="Data Source=.\MSSQLSERVER2012;Initial Catalog=DB-NetShops;User ID=sa;Password=your_password;Integrated Security=False" providerName="System.Data.SqlClient" /> </connectionStrings> <system.web> <!-- 添加全局cookie设置 --> <httpCookies httpOnlyCookies="true" /> <compilation debug="true" targetFramework="4.7.2" /> <httpRuntime targetFramework="4.7.2" maxRequestLength="20480" executionTimeout="300" requestValidationMode="4.7.2" /> <!-- 移除httpOnlyCookies属性 --> <sessionState mode="InProc" timeout="20" /> <authentication mode="Forms"> <!-- 移除httpOnlyCookies属性 --> <forms loginUrl="~/WebForm1.aspx" defaultUrl="~/WebForm2.aspx" timeout="20" /> </authentication> <globalization culture="zh-CN" uiCulture="zh-CN" requestEncoding="utf-8" responseEncoding="utf-8" /> <customErrors mode="RemoteOnly" defaultRedirect="~/Error.aspx"> <error statusCode="404" redirect="~/404.aspx" /> <error statusCode="500" redirect="~/500.aspx" /> </customErrors> <pages masterPageFile="~/Site.master"> <controls> <add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/> </controls> </pages> </system.web> <system.webServer> <httpProtocol> <customHeaders> <add name="X-Content-Type-Options" value="nosniff" /> <add name="X-Frame-Options" value="SAMEORIGIN" /> <add name="X-Xss-Protection" value="1; mode=block" /> </customHeaders> </httpProtocol> <staticContent> <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="7.00:00:00" /> </staticContent> <security> <requestFiltering> <requestLimits maxAllowedContentLength="20971520" /> </requestFiltering> </security> </system.webServer> <system.codedom> <compilers> <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701" /> </compilers> </system.codedom> </configuration> 添加母版页代码设置,生成完整webconfig代码
最新发布
06-12
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值