【问题标题】:Release build throws "System.IO.FileNotFoundException: Could not load file or assembly" looking for XmlSerializers assembly发布构建抛出“System.IO.FileNotFoundException:无法加载文件或程序集”寻找 XmlSerializers 程序集
【发布时间】:2012-10-15 22:04:16
【问题描述】:

让我先说我不认为这是一个重复的问题,但这可能是因为我没有完全理解这个问题。

听起来这个例外是设计使然,至少根据我读过的许多帖子。但是,这个异常会定期破坏我的应用程序。如果再次调用 Web 服务,它似乎可以工作(神奇!)。但是,我希望第一个 Web 服务调用能够正常工作。

这是正在记录的异常:

System.IO.FileNotFoundException: Could not load file or assembly 'Our.Namespace.Here.ClassName.XmlSerializers' or one of its dependencies. The system cannot find the file specified.
   at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
   at System.Reflection.RuntimeAssembly.LoadWithPartialNameInternal(AssemblyName an, Evidence securityEvidence, StackCrawlMark& stackMark)
   at System.DirectoryServices.AccountManagement.UnsafeNativeMethods.IADsPathname.Retrieve(Int32 lnFormatType)
   at System.DirectoryServices.AccountManagement.ADStoreCtx.LoadDomainInfo()
   at System.DirectoryServices.AccountManagement.ADStoreCtx.get_DnsForestName()
   at System.DirectoryServices.AccountManagement.ADStoreCtx.GetGroupsMemberOf(Principal p)
   at System.DirectoryServices.AccountManagement.Principal.GetGroupsHelper()
   at Our.Different.Namespace.ClassName.FindAccount(FindAccountRequest request, String ip, FindAccountResponse& response)

在发布模式下构建时,我没有将此 XmlSerializers 文件作为构建输出的一部分。听起来我可能可以force the file to be generated,但是,如何在不强制生成文件的情况下停止异常?

【问题讨论】:

  • 您是否尝试动态加载与正在执行的程序集不在同一文件夹中的程序集?
  • 您的构建配置是否列出了在同一平台(x86、x64、任何平台等)上构建的所有程序集?
  • 如果您引用的程序集之一是在 x86 上构建的,但调用程序集正在运行 x64(或 x64 机器上的 Any),则调用程序集将由于不兼容而无法加载引用的程序集。
  • @JoshC。 - 我不是动态加载程序集。 所有项目的平台设置为“Any CPU”。
  • 您的项目是否引用了可能有点过时的程序集?有时它们被编译为 x86。如果是这种情况,您需要将正在执行的程序集编译为 x86。

标签: c# web-services exception xmlserializer


【解决方案1】:

我收到了类似的错误消息,根本原因是 Windows 版本中的这个 AD 错误 (https://support.microsoft.com/en-us/kb/2683913),同时在 .NET 中使用 System.DirectoryServices.AccountManagement 命名空间。

【讨论】:

    【解决方案2】:

    这种情况下的问题根源是与 Active Directory 通信的网络问题。然后在尝试序列化 COM 异常期间发生 FileNotFoundException(在 IADsPathname COM 接口中)。此 FileNotFoundException 是 XmlSerializer 正常操作的一部分。它是预期的,并将在框架代码中被捕获和处理(它将导致所需的程序集生成)。忽略它并继续。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-28
      • 1970-01-01
      • 2023-02-07
      • 1970-01-01
      • 2011-08-12
      • 2012-12-28
      相关资源
      最近更新 更多