加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 未生成MyAssembly.XmlSerializers.dll

发布时间:2020-12-15 21:01:27 所属栏目:百科 来源:网络整理
导读:我正在使用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.Channe
我正在使用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,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,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,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,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.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall,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 [HKLMSoftwareMicrosoftFusion!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 [HKLMSoftwareMicrosoftFusion!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测试客户端版本.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读