webservice 运行时出现 无法生成临时类 类型 n 在未被引用的程序集中定义 错误

错误信息:
System.InvalidOperationException: 无法生成临时类(result=1)。
error CS0012: 类型“Common.DataBase.TableBase”在未被引用的程序集中定义。必须添加对程序集“Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null”的引用。

   在 System.Xml.Serialization.Compiler.Compile(Assembly parent, String ns, XmlSerializerCompilerParameters xmlParameters, Evidence evidence)
   在 System.Xml.Serialization.TempAssembly.GenerateAssembly(XmlMapping[] xmlMappings, Type[] types, String defaultNamespace, Evidence evidence, XmlSerializerCompilerParameters parameters, Assembly assembly, Hashtable assemblies)
   在 System.Xml.Serialization.TempAssembly..ctor(XmlMapping[] xmlMappings, Type[] types, String defaultNamespace, String location, Evidence evidence)
   在 System.Xml.Serialization.XmlSerializer.FromMappings(XmlMapping[] mappings, Evidence evidence)
   在 System.Web.Services.Protocols.XmlReturn.GetInitializers(LogicalMethodInfo[] methodInfos)
   在 System.Web.Services.Protocols.XmlReturnWriter.GetInitializers(LogicalMethodInfo[] methodInfos)
   在 System.Web.Services.Protocols.MimeFormatter.GetInitializers(Type type, LogicalMethodInfo[] methodInfos)
   在 System.Web.Services.Protocols.HttpServerType..ctor(Type type)
   在 System.Web.Services.Protocols.HttpServerProtocol.Initialize()
   在 System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing)

出错的代码:
[webmethod]
public void a()
{


_r.Test<DB.Set_CustomerType>();
}
原因分析:
DB.Set_CustomerType 继承自 Common.DataBase.TableBase,这个超类中提供了返回 ArrayList 值
的公共方法。webservice 检测到有 <DB.Set_CustomerType> 这样的新类型时,就会生成对应的临时类,
意义就好像 webmethod 返回一个自定义类型 a,就会运行期生成 a 一样,为了调用方可以容易的使用值。
这个生成的类最好不要包含非序列化对象,这就会造成错误。
其实这个原因早就遇到过,只是向返回值、参数 位置使用的类型比较能引起注意,而内部的这样一个泛型不
容易引起注意。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值