title: MyAssembly.XmlSerializers.dll not generated
body: <p>I am using WCF Test Client to make a request to a service, however i get the following error:</p>
  <pre><code>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&amp; 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&amp; msgData, Int32 type)
     at IDWS_WS.AuthenticateUser(String user, String password)
     at DWS_WSClient.AuthenticateUser(String user, String password)
  </code></pre>
  <p><a href="https://i.stack.imgur.com/LCagq.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/LCagq.png" alt="WCF Test Client Exception" /></a>
  I verified that i have Generate Serialization Assembly ON in the Project Properties -&gt; Build.</p>
  <p>I also activated SGEN to force the XML serialization, using this code(<a href="https://stackoverflow.com/questions/134224/generating-an-xml-serialization-assembly-as-part-of-my-build">Generating an Xml Serialization assembly as part of my build</a>) in the .csproj:</p>
  <pre><code>&lt;Target Name=&quot;AfterBuild&quot; 
          DependsOnTargets=&quot;AssignTargetPaths;Compile;ResolveKeySource&quot; 
          Inputs=&quot;$(MSBuildAllProjects);@(IntermediateAssembly)&quot; 
          Outputs=&quot;$(OutputPath)$(_SGenDllName)&quot;&gt;
  &lt;!-- Delete the file because I can't figure out how to force the SGen task. --&gt;
  &lt;Delete Files=&quot;$(TargetDir)$(TargetName).XmlSerializers.dll&quot; ContinueOnError=&quot;true&quot; /&gt;
    &lt;SGen BuildAssemblyName=&quot;$(TargetFileName)&quot; 
        BuildAssemblyPath=&quot;$(OutputPath)&quot; 
        References=&quot;@(ReferencePath)&quot; 
        ShouldGenerateSerializer=&quot;true&quot; 
        UseProxyTypes=&quot;false&quot; 
        KeyContainer=&quot;$(KeyContainerName)&quot; 
        KeyFile=&quot;$(KeyOriginatorFile)&quot; 
        DelaySign=&quot;$(DelaySign)&quot; 
        ToolPath=&quot;$(TargetFrameworkSDKToolsDirectory)&quot; 
        Platform=&quot;$(Platform)&quot;&gt;
      &lt;Output TaskParameter=&quot;SerializationAssembly&quot; 
            ItemName=&quot;SerializationAssembly&quot; /&gt;
    &lt;/SGen&gt;
  &lt;/Target&gt;
  </code></pre>
  <p>however i get the following error:</p>
  <pre><code>There was an error reflecting type 'aDoc_Client.DocumentManagementExplicitService.OTAuthentication'.
  </code></pre>
  <p><a href="https://i.stack.imgur.com/S75sG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/S75sG.png" alt="Reflecting type Exception" /></a>
  I suspect this may be the cause of the first error, however this object is an object inside a Service Reference.</p>
  <p>The Object declaration in Reference.cs is the following:</p>
  <pre><code>[System.CodeDom.Compiler.GeneratedCodeAttribute(&quot;System.Xml&quot;, &quot;4.0.30319.1015&quot;)]
  [System.SerializableAttribute()]
  [System.Diagnostics.DebuggerStepThroughAttribute()]
  [System.ComponentModel.DesignerCategoryAttribute(&quot;code&quot;)]
  [System.Xml.Serialization.XmlTypeAttribute(Namespace=&quot;urn:api.ecm.opentext.com&quot;)]
  public partial class OTAuthentication : object, System.ComponentModel.INotifyPropertyChanged {
      
      private string authenticationTokenField;
      
      /// &lt;remarks/&gt;
      [System.Xml.Serialization.XmlElementAttribute(Order=0)]
      public string AuthenticationToken {
          get {
              return this.authenticationTokenField;
          }
          set {
              this.authenticationTokenField = value;
              this.RaisePropertyChanged(&quot;AuthenticationToken&quot;);
          }
      }
      
      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));
          }
      }
  }
  </code></pre>
  <p>How can i generate MyAssembly.XmlSerializers.dll?</p>
  <p><strong>UPDATE 1:</strong></p>
  <p>After inserting a try catch in the last point of contact between my application and the service reference:</p>
  <pre><code>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;
  }
  </code></pre>
  <p>After returning a string with the exception, i get the following errors:</p>
  <pre><code>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;amp; stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean f or Int rospection,  Boolean suppressSecurityChecks)
     at System.Reflection.RuntimeAssembly.LoadWithPartialNameInternal(AssemblyName an, Evidence securityEvidence, StackCrawlMark&amp;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;amp; stackMark)
     at System.Reflection.Assembly.LoadWithPartialName(String partialName, Evidence securityEvidence)
     at System.Xml.Serialization.TempAssembly.LoadGeneratedAssembly(Type type, String defaultNamespace, XmlSerializerImplementation&amp;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;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].
  </code></pre>
  <p><strong>UPDATE 2:</strong></p>
  <p>After running SGEN tool manually as specified in <a href="https://stackoverflow.com/questions/21465441/could-not-load-myassembly-xmlserializers-dll-the-system-cannot-find-the-file-sp">Could not load MyAssembly.XmlSerializers.dll. The system cannot find the file specified</a> with visual studio command prompt i get the following errors:</p>
  <pre><code>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 &quot;sgen /?&quot;.
  </code></pre>
  <p>aDoc_Client.DocumentManagementExplicitService and aDoc_Client.AuthenticationExplicitService are service references, it appears i need to find a way to specify new namespaces for the service references.</p>
  <p><strong>UPDATE 3:</strong></p>
  <p>As crazy as it seems, without changing a single line of code, there is a case where i don't get an exception when calling the service.</p>
  <ol>
  <li>IIS Reset</li>
  <li>Make a call to the service using WCF Test Client (FAILS)</li>
  <li>Make a call to the service using WCF Test Client (FAILS)</li>
  <li>Make a call to the service using a .net application (OK)</li>
  <li>Make a call to the service using WCF Test Client (OK)</li>
  </ol>
  <p>And this repeats forever, i cant seem to understand why it only works after being first called from a .net application.</p>