2

I've been at this for days now and I just do not understand why this error is occurring. It's a FileLoadException for log4net v1.2.10.0, but it occurs during a XRM SDK linq query. I use log4net v1.2.12.0 in the application, and I expected a bindingRedirect to fix this but it doesn't. (The v1.2.10.0 log4net is required by a library that I use)

It looks like the XRM sdk somehow tries to serialize/deserialize assemblies. I'm not sure why it does this, I reckon the post may be relevant.

Inner Exception is null

Exception Message:

Could not load file or assembly 'log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821' or one of its dependencies.
The located assembly's manifest definition does not match the assembly reference.     
(Exception from HRESULT: 0x80131040)":"log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821

Server stack trace:

at System.ModuleHandle.ResolveType(RuntimeModule module, Int32 typeToken, IntPtr* typeInstArgs, Int32 typeInstCount, IntPtr* methodInstArgs, Int32 methodInstCount, ObjectHandleOnStack type)
at System.ModuleHandle.ResolveTypeHandleInternal(RuntimeModule module, Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext)
at System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
at System.Reflection.CustomAttribute.FilterCustomAttributeRecord(CustomAttributeRecord caRecord, MetadataImport scope, Assembly& lastAptcaOkAssembly, RuntimeModule decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, Object[] attributes, IList derivedAttributes, RuntimeType& attributeType, IRuntimeMethodInfo& ctor, Boolean& ctorHasParameters, Boolean& isVarArg)
at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes, Boolean isDecoratedTargetSecurityTransparent)
at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeAssembly assembly, RuntimeType caType)
at System.Reflection.RuntimeAssembly.GetCustomAttributes(Type attributeType, Boolean inherit)
at Microsoft.Xrm.Sdk.KnownTypesProvider.GetProxyTypesAttribute(Assembly assembly)
at Microsoft.Xrm.Sdk.KnownTypesProvider.RegisterAssembly(Assembly assembly)
at Microsoft.Xrm.Sdk.KnownTypesProvider.get_KnownAssemblies()
at Microsoft.Xrm.Sdk.KnownTypesProvider.get_KnownOrganizationRequestResponseTypes()
at Microsoft.Xrm.Sdk.KnownTypesResolver.ResolveName(String typeName, String typeNamespace, Type declaredType, DataContractResolver knownTypeResolver)
at System.Runtime.Serialization.XmlObjectSerializerContext.ResolveDataContractFromDataContractResolver(XmlQualifiedName typeName, Type declaredType)
at System.Runtime.Serialization.XmlObjectSerializerContext.ResolveDataContractFromKnownTypes(String typeName, String typeNs, DataContract memberTypeContract, Type declaredType)
at System.Runtime.Serialization.XmlObjectSerializerContext.IsKnownType(DataContract dataContract, Type declaredType)
at System.Runtime.Serialization.XmlObjectSerializerContext.IsKnownType(DataContract dataContract, Dictionary`2 knownDataContracts, Type declaredType)
at System.Runtime.Serialization.KnownTypeDataContractResolver.TryResolveType(Type type, Type declaredType, DataContractResolver knownTypeResolver, XmlDictionaryString& typeName, XmlDictionaryString& typeNamespace)
at Microsoft.Xrm.Sdk.KnownTypesResolver.TryResolveType(Type type, Type declaredType, DataContractResolver knownTypeResolver, XmlDictionaryString& typeName, XmlDictionaryString& typeNamespace)
at System.Runtime.Serialization.XmlObjectSerializerWriteContext.ResolveType(Type objectType, Type declaredType, XmlDictionaryString& typeName, XmlDictionaryString& typeNamespace)
at System.Runtime.Serialization.XmlObjectSerializerWriteContext.WriteResolvedTypeInfo(XmlWriterDelegator writer, Type objectType, Type declaredType)
at System.Runtime.Serialization.XmlObjectSerializerWriteContext.WriteTypeInfo(XmlWriterDelegator writer, DataContract contract, DataContract declaredContract)
at System.Runtime.Serialization.XmlObjectSerializerWriteContext.SerializeWithXsiTypeAtTopLevel(DataContract dataContract, XmlWriterDelegator xmlWriter, Object obj, RuntimeTypeHandle originalDeclaredTypeHandle, Type graphType)
at System.Runtime.Serialization.DataContractSerializer.InternalWriteObjectContent(XmlWriterDelegator writer, Object graph, DataContractResolver dataContractResolver)
at System.Runtime.Serialization.DataContractSerializer.InternalWriteObject(XmlWriterDelegator writer, Object graph, DataContractResolver dataContractResolver)
at System.Runtime.Serialization.XmlObjectSerializer.WriteObjectHandleExceptions(XmlWriterDelegator writer, Object graph, DataContractResolver dataContractResolver)
at System.Runtime.Serialization.XmlObjectSerializer.WriteObject(XmlDictionaryWriter writer, Object graph)
at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.SerializeParameterPart(XmlDictionaryWriter writer, PartInfo part, Object graph)
at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.SerializeParameter(XmlDictionaryWriter writer, PartInfo part, Object graph)
at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.SerializeParameters(XmlDictionaryWriter writer, PartInfo[] parts, Object[] parameters)
at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.SerializeBody(XmlDictionaryWriter writer, MessageVersion version, String action, MessageDescription messageDescription, Object returnValue, Object[] parameters, Boolean isRequest)
at System.ServiceModel.Dispatcher.OperationFormatter.SerializeBodyContents(XmlDictionaryWriter writer, MessageVersion version, Object[] parameters, Object returnValue, Boolean isRequest)
at System.ServiceModel.Dispatcher.OperationFormatter.OperationFormatterMessage.OperationFormatterBodyWriter.OnWriteBodyContents(XmlDictionaryWriter writer)
at System.ServiceModel.Channels.BodyWriterMessage.OnWriteBodyContents(XmlDictionaryWriter writer)
at System.ServiceModel.Security.SecurityAppliedMessage.OnWriteBodyContents(XmlDictionaryWriter writer)
at System.ServiceModel.Security.SecurityAppliedMessage.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.SecurityChannelFactory`1.SecurityRequestChannel.Request(Message message, TimeSpan timeout)
at System.ServiceModel.Dispatcher.RequestChannelBinder.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& msgData, Int32 type)
at Microsoft.Xrm.Sdk.IOrganizationService.Execute(OrganizationRequest request)
at Microsoft.Xrm.Sdk.Client.OrganizationServiceProxy.ExecuteCore(OrganizationRequest request)
at Microsoft.Xrm.Sdk.Client.OrganizationServiceProxy.Execute(OrganizationRequest request)
at Microsoft.Xrm.Sdk.Client.OrganizationServiceContext.Execute(OrganizationRequest request)
at Microsoft.Xrm.Sdk.Linq.QueryProvider.RetrieveEntityCollection(OrganizationRequest request, NavigationSource source)
at Microsoft.Xrm.Sdk.Linq.QueryProvider.Execute(QueryExpression qe, Boolean throwIfSequenceIsEmpty, Boolean throwIfSequenceNotSingle, Projection projection, NavigationSource source, List`1 linkLookups, String& pagingCookie, Boolean& moreRecords)
at Microsoft.Xrm.Sdk.Linq.QueryProvider.Execute[TElement](QueryExpression qe, Boolean throwIfSequenceIsEmpty, Boolean throwIfSequenceNotSingle, Projection projection, NavigationSource source, List`1 linkLookups)
at Microsoft.Xrm.Sdk.Linq.QueryProvider.Execute[TElement](Expression expression)
at Microsoft.Xrm.Sdk.Linq.QueryProvider.GetEnumerator[TElement](Expression expression)
at Microsoft.Xrm.Sdk.Linq.Query`1.GetEnumerator()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at ClassLibrary.Class1.Method1() in C:\Users\Greg.tarr\Documents\Visual Studio 2010\Projects\RestService\ClassLibrary\Class1.cs:line 36
Community
  • 1
  • 1
Greg Tarr
  • 496
  • 3
  • 5
  • 19
  • Thanks @Ela for formatting improvements – Greg Tarr Oct 03 '13 at 23:09
  • Is this as a part of a plugin, or a separate client exe? – Daryl Oct 04 '13 at 00:36
  • No, separate client EXE. Only seems to be a problem when part of web site or rest service; a standard console app works fine – Greg Tarr Oct 04 '13 at 08:13
  • Do you have an inner exception and how do you know it is log4net that it is not loading? I don't think XRM is actually serializing/de-serializing assemblies, rather data is being serialized as part of the rest service and when it is being de-serialized it is try to resolve the type by examining and loading assemblies at runtime. – sgmoore Oct 04 '13 at 14:41
  • InnerException is null, main text is "Could not load file or assembly 'log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)":"log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821" – Greg Tarr Oct 04 '13 at 16:31
  • Have you tried deleting the log4net.dll from the solution's bin directory(s), adding it back though Visual Studio's Add Reference command, and recompiling? Sounds like you have an assembly version (guid) listed in the solution file that is different than the assembly version getting deployed with the final application. – Nicknow Oct 04 '13 at 19:46
  • 2
    Have you run fuslogvw.exe? Also, this could be a x64/x86 issue. If log4net.dll is compiled for x64 and the website is running in 32-bit mode (or vice-versa), then it would not be able to load the dll regardless of the binding redirect. – sgmoore Oct 05 '13 at 09:36
  • @Nicknow to do that I would have to remove the reference through VS otherwise it will complain that its already added? None of my project/solution files have any version numbers or guids for log4net – Greg Tarr Oct 07 '13 at 10:39
  • @sgmoore yes I have used it extensively, although I keep seeing "Calling assembly : (Unknown)" which doesn't help. I have seen posts on the internet about x64/x86 - this is the "Enable 32-Bit Applications" setting on the app pool in IIS? What about if you are running through Visual Studio? – Greg Tarr Oct 07 '13 at 10:47
  • @GregT Correct, you have to remove/add in VS and then rebuild. – Nicknow Oct 07 '13 at 13:50
  • @nicknow tried that, same error unfortunately. – Greg Tarr Oct 07 '13 at 14:07
  • You're aware that log4net comes in with 2 different key signatures, right? 1b44e1d426115821 is the old key, I believe, which is what it appears to be looking for. Are you using the newkey version by chance? – Pete Oct 10 '13 at 13:25
  • Yes I have tried both keys 1b44e1d426115821 and 669e0ddf0bb1aa2a in the bindingRedirect, neither stop the error – Greg Tarr Oct 11 '13 at 10:03
  • It might be helpful to list the full Exception message, and not just the stack trace... – Daryl Oct 11 '13 at 12:04
  • @Daryl it is in the 5th comment down – Greg Tarr Oct 11 '13 at 13:27
  • after 7 years, do you remember what was the real issue, and did it ever get solved? :) I'm facing a similar issue. – OfirD Jan 17 '21 at 10:49
  • 1
    @OfirD I'm sorry I cannot remember. We had loads of issues with log4net. I'm pretty sure I did actually fix this one but have no idea what we did. My advice would just be to keep going until it works! I know that's not very helpful. – Greg Tarr Jan 24 '21 at 13:40

1 Answers1

1

This is possibly caused by an incorrect / outdated reference to log4net in the project (when using an updated version), references are compiled into the assembly and a load is then attempted. Taken from here

Also make sure your PublicKeyToken is correct.

If you've updated through NuGet the token can be incorrect / not update ... as per this SO post

Community
  • 1
  • 1
Paul Zahra
  • 9,522
  • 8
  • 54
  • 76
  • It's not due to NuGet because the issue can be reproduced without that, although that was the context in which the issue was originally noticed. It isn't to do with publickeytokens as the fusion logs indicate the build number is wrong. Using the oldkey version of log4net as suggested in your linked post also does not resolve the issue. – Greg Tarr Oct 14 '13 at 13:03
  • Also, how can you account for the fact that the error only occurs in a CRM/XRM sdk call, and not otherwise? – Greg Tarr Oct 14 '13 at 13:05
  • Hmm, it's the update procedure of NuGet that can screw the key... it is strange for sure, I'm wondering if there is some log4net version conflict in action http://stackoverflow.com/questions/10417344/yet-another-issue-about-log4net-1-2-11-conflicts ... some dependency is screwing you over i bet – Paul Zahra Oct 14 '13 at 13:55
  • I'm sure it is, just a question of what the issue is and how to fix it. I've tried different public key tokens, different versions of log4net, but nothing so far has fixed the problem – Greg Tarr Oct 14 '13 at 14:18
  • Try something like http://drewnoakes.com/code/dependency-analyser/ to help gain a visual overview of the dependencies, I'm afraid your going to have to drill into your solution and check for all dependencies and dependencies of 3rd party stuff... or just change to a different logger :D – Paul Zahra Oct 14 '13 at 15:31
  • that is only for .NET 3.5, can you recommend anything else or do I have to downgrade my assemblies? – Greg Tarr Oct 14 '13 at 15:42
  • Are you using VS Ultimate? that has http://msdn.microsoft.com/en-us/library/dd409453%28v=vs.100%29.aspx – Paul Zahra Oct 15 '13 at 08:15
  • Using VS Premium. Not sure dependency walker will help as the issue cannot be replicated when built as an EXE file (as explained above, only when a web site), and the dependencies are loaded dynamically – Greg Tarr Oct 15 '13 at 10:00
  • It might help... "Dependency Walker handles all types of module dependencies, including implicit, explicit (dynamic / runtime), forwarded, delay-loaded, and injected." – Paul Zahra Oct 15 '13 at 11:44
  • But then..."When you first open a module in Dependency Walker, it only shows implicit, forwarded, and delay-load dependencies. Many dependencies are loaded dynamically and will not be detected until you profile the application from within Dependency Walker" and "For profiling to work, the module you open in Dependency Walker has to be an executable file (usually ends with .EXE)" – Greg Tarr Oct 15 '13 at 12:43
  • Ah... well I'm out of suggestions I'm afraid, I would be tempted to ditch log4net and go with another option, if error logging is your only issue then I'd recommend you go with elmah! else go with nlog – Paul Zahra Oct 15 '13 at 13:11