2016-08-04 116 views
4

我使用WCF測試客戶做出服務的請求,但是我得到以下錯誤:MyAssembly.XmlSerializers.dll不會產生

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 我覈實,我已經生成序列化大會在項目屬性 - >生成。

我也被激活SGEN迫使XML序列化,在.csproj的使用此代碼(Generating an Xml Serialization assembly as part of my build):

<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 我懷疑這可能是第一個錯誤的原因,但是這個對象是Service Reference中的一個對象。

在Reference.cs的對象聲明如下:

[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:

在我的應用程序和服務的參考之間的接觸的最後一點插入一個嘗試捕捉後:

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:

Could not load MyAssembly.XmlSerializers.dll. The system cannot find the file specified與Visual Studio命令提示符指定手動運行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:

作爲,因爲它似乎,不改變一行代碼的瘋狂,有時調用服務時,我沒有得到一個異常的情況。

  1. 重置IIS
  2. 使用WCF測試客戶端(失敗)
  3. 使用WCF測試客戶端(失敗),使該服務電話撥打到服務的調用
  4. 使用不得對服務的調用一個 。網絡應用程序(OK)
  5. 使用WCF測試客戶端(OK)

不得對服務的調用而這種不斷重複的,我似乎無法理解爲什麼只後被首先從.NET應用程序調用工作。

+0

什麼是異常的完整'ToString()'輸出,包括異常類型,消息,追溯和內部異常?那裏可能會更詳細地解釋這個問題。 – dbc

+0

@dbc帖子已更新。 – BrunoMartinsPro

回答