gpt4 book ai didi

c# - 未生成 MyAssembly.XmlSerializers.dll

转载 作者:数据小太阳 更新时间:2023-10-29 02:13:38 25 4
gpt4 key购买 nike

我正在使用 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我已在项目属性 -> 构建中确认我已打开生成序列化程序集。

我还激活了 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我怀疑这可能是第一个错误的原因,但是这个对象是服务引用中的一个对象。

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:

在我的应用程序和服务引用之间的最后一个接触点插入 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:

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

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. 使用 .net 应用程序调用服务(确定)
  5. 使用 WCF 测试客户端调用服务(确定)

这会一直重复下去,我似乎无法理解为什么它只有在首次从 .net 应用程序调用后才有效。

最佳答案

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

关于c# - 未生成 MyAssembly.XmlSerializers.dll,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38768061/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com