ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

c# – 未生成MyAssembly.XmlSerializers.dll

2019-07-11 08:08:11  阅读:370  来源: 互联网

标签:c xml wcf xmlserializer sgen


我正在使用WCF测试客户端向服务发出请求,但是我收到以下错误:

Could not load file or assembly 'aDoc_Client.XmlSerializers' or one of its dependencies. The system cannot find the file specified.

Server stack trace: 
   at System.ServiceModel.Channels.ServiceChannel.ThrowIfFaultUnderstood(Message reply, MessageFault fault, String action, MessageVersion version, FaultConverter faultConverter)
   at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
   at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs)
   at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
   at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]: 
   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
   at IDWS_WS.AuthenticateUser(String user, String password)
   at DWS_WSClient.AuthenticateUser(String user, String password)

WCF Test Client Exception
我确认我已在项目属性中生成序列化程序集 – >建立.

我还使用.csproj中的代码(Generating an Xml Serialization assembly as part of my build)激活了SGEN来强制XML序列化:

<Target Name="AfterBuild" 
        DependsOnTargets="AssignTargetPaths;Compile;ResolveKeySource" 
        Inputs="$(MSBuildAllProjects);@(IntermediateAssembly)" 
        Outputs="$(OutputPath)$(_SGenDllName)">
<!-- Delete the file because I can't figure out how to force the SGen task. -->
<Delete Files="$(TargetDir)$(TargetName).XmlSerializers.dll" ContinueOnError="true" />
  <SGen BuildAssemblyName="$(TargetFileName)" 
      BuildAssemblyPath="$(OutputPath)" 
      References="@(ReferencePath)" 
      ShouldGenerateSerializer="true" 
      UseProxyTypes="false" 
      KeyContainer="$(KeyContainerName)" 
      KeyFile="$(KeyOriginatorFile)" 
      DelaySign="$(DelaySign)" 
      ToolPath="$(TargetFrameworkSDKToolsDirectory)" 
      Platform="$(Platform)">
    <Output TaskParameter="SerializationAssembly" 
          ItemName="SerializationAssembly" />
  </SGen>
</Target>

但是我得到以下错误:

There was an error reflecting type 'aDoc_Client.DocumentManagementExplicitService.OTAuthentication'.

Reflecting type Exception
我怀疑这可能是第一个错误的原因,但是此对象是服务引用中的对象.

Reference.cs中的Object声明如下:

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.1015")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="urn:api.ecm.opentext.com")]
public partial class OTAuthentication : object, System.ComponentModel.INotifyPropertyChanged {

    private string authenticationTokenField;

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(Order=0)]
    public string AuthenticationToken {
        get {
            return this.authenticationTokenField;
        }
        set {
            this.authenticationTokenField = value;
            this.RaisePropertyChanged("AuthenticationToken");
        }
    }

    public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;

    protected void RaisePropertyChanged(string propertyName) {
        System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
        if ((propertyChanged != null)) {
            propertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
        }
    }
}

我怎样才能生成MyAssembly.XmlSerializers.dll?

更新1:

在我的应用程序和服务引用之间的最后一个联系点插入try catch之后:

public string AuthenticateUser(string userName, string userPassword) {
    string output = string.Empty;

    try
       {
           output = base.Channel.AuthenticateUser(userName, userPassword);
       }
    catch(Exception ex)
       {
           output = ex.ToString();
       }

    return output;
}

返回带有异常的字符串后,我收到以下错误:

System.IO.FileNotFoundException: Could not load file or assembly 'aDoc_Client.XmlSerializers' or one of its dependencies. The system cannot find the file specified.
File name: 'aDoc_Client.XmlSerializers'

Server stack trace: 
   at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark&amp; stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean f or Int rospection,  Boolean suppressSecurityChecks)
   at System.Reflection.RuntimeAssembly.LoadWithPartialNameInternal(AssemblyName an, Evidence securityEvidence, StackCrawlMark&amp; stackMark)
   at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
   at Microsoft.Win32.Fusion.ReadCache(ArrayList alAssems, String name, UInt32 nFlag)
   at System.Reflection.RuntimeAssembly.EnumerateCache(AssemblyName partialName)
   at System.Reflection.RuntimeAssembly.LoadWithPartialNameInternal(AssemblyName an, Evidence securityEvidence, StackCrawlMark&amp; stackMark)
   at System.Reflection.Assembly.LoadWithPartialName(String partialName, Evidence securityEvidence)
   at System.Xml.Serialization.TempAssembly.LoadGeneratedAssembly(Type type, String defaultNamespace, XmlSerializerImplementation&amp; contract)
   at System.Xml.Serialization.XmlSerializer.FromMappings(XmlMapping[] mappings, Type type)
   at System.ServiceModel.Description.XmlSerializerOperationBehavior.Reflector.SerializerGenerationContext.GenerateSerializers()
   at System.ServiceModel.Description.XmlSerializerOperationBehavior.Reflector.SerializerGenerationContext.GetSerializer(Int32 handle)
   at System.ServiceModel.Dispatcher.XmlSerializerOperationFormatter.SerializeBody(XmlDictionaryWriter writer, MessageVersion version, String action, MessageDescription messageDescription, Object returnValue, Object[] parameters, Boolean isReq uest)
   at System.ServiceModel.Dispatcher.OperationFormatter.OperationFormatterMessage.OperationFormatterBodyWriter.OnWriteBodyContents(XmlDictionaryWriter writer)
   at System.ServiceModel.Channels.Message.OnWriteMessage(XmlDictionaryWriter writer)
   at System.ServiceModel.Channels.BufferedMessageWriter.WriteMessage(Message message, BufferManager bufferManager, Int32 initialOffset, Int32 maxSizeQuota)
   at System.ServiceModel.Channels.TextMessageEncoderFactory.TextMessageEncoder.WriteMessage(Message message, Int32 maxMessageSize, BufferManager bufferManager, Int32 messageOffset)
   at System.ServiceModel.Channels.HttpOutput.SerializeBufferedMessage(Message message)
   at System.ServiceModel.Channels.HttpOutput.Send(TimeSpan timeout)
   at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.SendRequest(Message message, TimeSpan timeout)
   at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
   at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]: 
   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&amp; msgData, Int32 type)
   at aDoc_Client.AuthenticationExplicitService.Authentication.AuthenticateUser(String userName, String userPassword)
   at aDoc_Client.AuthenticationExplicitService.AuthenticationClient.AuthenticateUser(String userName, String userPassword)

WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].

更新2:

使用visual studio命令提示符在Could not load MyAssembly.XmlSerializers.dll. The system cannot find the file specified中手动运行SGEN工具后,我收到以下错误:

Error: There was an error reflecting type
          'aDoc_Client.DocumentManagementExplicitService.OTAuthentication'.
  - Types 'aDoc_Client.DocumentManagementExplicitService.OTAuthentication' 
      and 'aDoc_Client.AuthenticationExplicitService.OTAuthentication' 
both use the XML type name, 'OTAuthentication', from namespace 'urn:api.ecm.opentext.com'. 
Use XML attributes to specify a unique XML name and/or namespace for the type.

If you would like more help, please type "sgen /?".

aDoc_Client.DocumentManagementExplicitService和aDoc_Client.AuthenticationExplicitService是服务引用,我需要找到一种方法来为服务引用指定新的命名空间.

更新3:

看起来很疯狂,如果不改变单行代码,有一种情况是我在调用服务时没有异常.

> IIS重置
>使用WCF测试客户端(FAILS)调用服务
>使用WCF测试客户端(FAILS)调用服务
>使用.net应用程序调用服务(OK)
>使用WCF测试客户端调用服务(OK)

这永远重复,我似乎无法理解为什么它只能在从.net应用程序首次调用后才能工作.

解决方法:

问题是WCF测试客户端版本.

标签:c,xml,wcf,xmlserializer,sgen
来源: https://codeday.me/bug/20190711/1430195.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有