Data8 / DataverseClient

WS-Trust compatible version of the Microsoft Dataverse client for .NET Core
MIT License
34 stars 16 forks source link

Could not load type 'System.Web.UI.WebResourceAttribute' #32

Open yogster opened 1 year ago

yogster commented 1 year ago

Hello, and thanks for your hard work creating this package.

I'm trying to use this package in a .Net 7 application, and I'm getting the following exception when calling Execute from a unit test:

System.TypeLoadException : Could not load type 'System.Web.UI.WebResourceAttribute' from assembly 'System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.

Stack trace below.

My understanding is that this package should work with .Net 6 and above... So why is it trying to use a .Net Framework 4.x assembly? What am I doing wrong? Cheers!

Stack Trace: 

ModuleHandle.ResolveTypeHandle(Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext)
RuntimeModule.ResolveType(Int32 metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
CustomAttribute.FilterCustomAttributeRecord(MetadataToken caCtorToken, MetadataImport& scope, RuntimeModule decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, ListBuilder`1& derivedAttributes, RuntimeType& attributeType, IRuntimeMethodInfo& ctorWithParameters, Boolean& isVarArg)
CustomAttribute.AddCustomAttributes(ListBuilder`1& attributes, RuntimeModule decoratedModule, Int32 decoratedMetadataToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, ListBuilder`1 derivedAttributes)
CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType)
CustomAttribute.GetCustomAttributes(RuntimeAssembly assembly, RuntimeType caType)
RuntimeAssembly.GetCustomAttributes(Type attributeType, Boolean inherit)
KnownTypesProvider.GetProxyTypesAttribute(Assembly assembly)
KnownTypesProvider.get_KnownAssemblies()
KnownTypesProvider.LoadKnownOrganizationRequestResponseTypes()
KnownTypesProvider.get_KnownOrganizationRequestResponseTypes()
KnownTypesResolver.ResolveName(String typeName, String typeNamespace, Type declaredType, DataContractResolver knownTypeResolver)
XmlObjectSerializerContext.ResolveDataContractFromKnownTypes(String typeName, String typeNs, DataContract memberTypeContract, Type declaredType)
XmlObjectSerializerContext.IsKnownType(DataContract dataContract, Type declaredType)
XmlObjectSerializerContext.IsKnownType(DataContract dataContract, Dictionary`2 knownDataContracts, Type declaredType)
KnownTypeDataContractResolver.TryResolveType(Type type, Type declaredType, DataContractResolver knownTypeResolver, XmlDictionaryString& typeName, XmlDictionaryString& typeNamespace)
KnownTypesResolver.TryResolveType(Type type, Type declaredType, DataContractResolver knownTypeResolver, XmlDictionaryString& typeName, XmlDictionaryString& typeNamespace)
XmlObjectSerializerWriteContext.ResolveType(Type objectType, Type declaredType, XmlDictionaryString& typeName, XmlDictionaryString& typeNamespace)
XmlObjectSerializerWriteContext.WriteTypeInfo(XmlWriterDelegator writer, DataContract contract, DataContract declaredContract)
XmlObjectSerializerWriteContext.SerializeWithXsiTypeAtTopLevel(DataContract dataContract, XmlWriterDelegator xmlWriter, Object obj, RuntimeTypeHandle originalDeclaredTypeHandle, Type graphType)
DataContractSerializer.InternalWriteObjectContent(XmlWriterDelegator writer, Object graph, DataContractResolver dataContractResolver)
DataContractSerializer.InternalWriteObject(XmlWriterDelegator writer, Object graph, DataContractResolver dataContractResolver)
XmlObjectSerializer.WriteObjectHandleExceptions(XmlWriterDelegator writer, Object graph, DataContractResolver dataContractResolver)
XmlObjectSerializer.WriteObject(XmlDictionaryWriter writer, Object graph)
DataContractSerializerOperationFormatter.SerializeParameterPart(XmlDictionaryWriter writer, PartInfo part, Object graph)
DataContractSerializerOperationFormatter.SerializeParameter(XmlDictionaryWriter writer, PartInfo part, Object graph)
DataContractSerializerOperationFormatter.SerializeParameters(XmlDictionaryWriter writer, PartInfo[] parts, Object[] parameters)
DataContractSerializerOperationFormatter.SerializeBody(XmlDictionaryWriter writer, MessageVersion version, String action, MessageDescription messageDescription, Object returnValue, Object[] parameters, Boolean isRequest)
OperationFormatter.SerializeBodyContents(XmlDictionaryWriter writer, MessageVersion version, Object[] parameters, Object returnValue, Boolean isRequest)
OperationFormatterBodyWriter.OnWriteBodyContents(XmlDictionaryWriter writer)
BodyWriter.WriteBodyContents(XmlDictionaryWriter writer)
BodyWriterMessage.OnWriteBodyContents(XmlDictionaryWriter writer)
SecurityAppliedMessage.OnWriteBodyContents(XmlDictionaryWriter writer)
SecurityAppliedMessage.OnWriteMessage(XmlDictionaryWriter writer)
Message.WriteMessage(XmlDictionaryWriter writer)
BufferedMessageWriter.WriteMessage(Message message, BufferManager bufferManager, Int32 initialOffset, Int32 maxSizeQuota)
TextMessageEncoder.WriteMessageAsync(Message message, Int32 maxMessageSize, BufferManager bufferManager, Int32 messageOffset)
TextMessageEncoder.WriteMessage(Message message, Int32 maxMessageSize, BufferManager bufferManager, Int32 messageOffset)
MessageEncoder.WriteMessage(Message message, Int32 maxMessageSize, BufferManager bufferManager)
BufferedMessageContent.EnsureMessageEncoded()
BufferedMessageContent.TryComputeLength(Int64& length)
HttpContent.GetComputedOrBufferLength()
HttpContentHeaders.get_ContentLength()
SocketsHttpHandler.ValidateAndNormalizeRequest(HttpRequestMessage request)
SocketsHttpHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
HttpClientHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
HttpMessageInvoker.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
HttpClient.<SendAsync>g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken)
HttpClientChannelAsyncRequest.SendRequestAsync(Message message, TimeoutHelper timeoutHelper)
RequestChannel.RequestAsync(Message message, TimeSpan timeout)
RequestChannel.RequestAsyncInternal(Message message, TimeSpan timeout)
TaskHelpers.ToApmEnd[TResult](IAsyncResult iar)
RequestChannel.EndRequest(IAsyncResult result)
TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization)
--- End of stack trace from previous location ---
SecurityRequestChannel.RequestAsync(Message message, TimeSpan timeout)
SecurityRequestChannel.RequestAsyncInternal(Message message, TimeSpan timeout)
SecurityRequestChannel.Request(Message message, TimeSpan timeout)
RequestChannelBinder.Request(Message message, TimeSpan timeout)
ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs)
ServiceChannelProxy.InvokeService(MethodCall methodCall, ProxyOperationRuntime operation)
ServiceChannelProxy.Invoke(MethodInfo targetMethod, Object[] args)
generatedProxy_1.Execute(OrganizationRequest)
ClaimsBasedAuthClient.Execute(OrganizationRequest request)
OnPremiseClient.Execute(OrganizationRequest request)
[Stack frames referencing our code removed here]
MarkMpn commented 1 year ago

From the stack trace it looks like the KnownTypesResolver is trying to find the details for an early-bound assembly, and as part of that it's found a loaded assembly which has a WebResourceAttribute on it which it's then failing to load. We can't see from this stack trace what that assembly is, but you might be able to find this in the debugger.