0

I run async Task which uses code from referenced DLL. In this case I cat error message that this referenced DLL can not be found.

Message: Unable to find assembly 'Newtonsoft.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'.

    StackTrace:    at System.Runtime.Serialization.Formatters.Binary.BinaryAssemblyInfo.GetAssembly()
   at System.Runtime.Serialization.Formatters.Binary.ObjectReader.GetType(BinaryAssemblyInfo assemblyInfo, String name)
   at System.Runtime.Serialization.Formatters.Binary.ObjectMap..ctor(String objectName, String[] memberNames, BinaryTypeEnum[] binaryTypeEnumA, Object[] typeInformationA, Int32[] memberAssemIds, ObjectReader objectReader, Int32 objectId, BinaryAssemblyInfo assemblyInfo, SizedArray assemIdToAssemblyTable)
   at System.Runtime.Serialization.Formatters.Binary.ObjectMap.Create(String name, String[] memberNames, BinaryTypeEnum[] binaryTypeEnumA, Object[] typeInformationA, Int32[] memberAssemIds, ObjectReader objectReader, Int32 objectId, BinaryAssemblyInfo assemblyInfo, SizedArray assemIdToAssemblyTable)
   at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.ReadObjectWithMapTyped(BinaryObjectWithMapTyped record)
   at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.Run()
   at System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler handler, __BinaryParser serParser, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
   at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream, HeaderHandler handler, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
   at System.Runtime.Remoting.Channels.CrossAppDomainSerializer.DeserializeObject(MemoryStream stm)
   at System.AppDomain.Deserialize(Byte[] blob)
   at System.AppDomain.UnmarshalObject(Byte[] blob)

If the code is in async Task then DLLs are taken from different location? Should I install it to GAC?

This is my web.config:

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-8.0.0.0" newVersion="8.0.0.0" />
      </dependentAssembly>

In Bin folder I have a Newtonsoft.Json.Dll, I run powershell script to check what is the version and it is:

[Reflection.AssemblyName]::GetAssemblyName('MyLocation\Newtonsoft.Json.DLL').Version

And the result is:

Major  Minor  Build  Revision
-----  -----  -----  --------
8      0      0      0

Then I wanted to check which assemblies are loaded into w3wp.exe process using listDlls.exe and there is:

C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root\xxx\Newtonsoft.Json.DLL

So I navigated there copied the dll and checked the version (just to be sure) and it is 8.0.0.0

I'm not sure what else can I do :D

Snorlax
  • 787
  • 2
  • 9
  • 22
  • 1
    Could you show some of your code? – JustinHui Aug 01 '17 at 22:31
  • You must post some code you are using. Right now it is hard to tell, where is the problem – Piotr Aug 01 '17 at 22:31
  • 1
    I doubt it has anything to do with the code being in an async task. More likely you have different dependencies that require different versions of JSON.NET, and your bindings are strict enough that your app won't accept the version that ends up in your bin folder. – StriplingWarrior Aug 01 '17 at 22:32
  • @StriplingWarrior I just edited the question – Snorlax Aug 01 '17 at 22:41
  • @JustinHui Sure, done – Snorlax Aug 01 '17 at 22:42
  • @Snorlax: Have you gone through the suggestions listed [here](https://stackoverflow.com/questions/12027543/visual-studio-2012-web-api-project-wont-run-cant-find-newtonsoft-json)? – StriplingWarrior Aug 01 '17 at 22:47
  • The error is in your developer environment or in the server?. You have to ensure this DLL have to be in your Bin directory and no other in the moment of compilation. Read this https://msdn.microsoft.com/en-us/library/ms366723.aspx – Javier Jimenez Matilla Aug 01 '17 at 22:50
  • The error is on server, locally it works fine – Snorlax Aug 01 '17 at 22:52

1 Answers1

0

I see that this is a cross domain serailization exception coming from CrossAppDomainSerializer and this is used as Remoting Infrastructure Sink for making calls across context boundaries

This is an issue originating from your code and remoting is done,please refer this SO post .

Hope this helps!

Rohith
  • 5,527
  • 3
  • 27
  • 31