Newtonsoft Json.NET exception when running project automation on Windows 10

I just tried to test my PowerShell Tookit scripts on Windows 10 and it's not working due to following exception.
It works perfectly fine on Windows 7.

Does the "Version=4.5.0.0" have something to do with .NET Framework version? Windows 10 ship with .NET 4.6.x by default...

And what on Earth has JSON library to do with retrieving language ISO abbreviation property?!?! :-O

The following exception occurred while retrieving member "IsoAbbreviation": "Could not load file or assembly
'Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The
system cannot find the file specified."
At C:\Users\Tester\Documents\WindowsPowerShell\Modules\PackageHelper\PackageHelper.psm1:117 char:3
+         $TargetLanguagesList = @($Project.GetProjectInfo().TargetLang ...
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], ExtendedTypeSystemException
    + FullyQualifiedErrorId : CatchFromBaseGetMember
  • Hi,
    We use JSON format to store information about languages - some special information which are missing in the .NET CultureInfo (or they don't belong there as they are SDL specific).
    Can you post the code of the script where you are getting this error?
    Regards
    Patrik
  • I see, okay...

    Well, the error doesn't seem to be specific for my code as I don't see anything obviously weird in the code.
    It's only obtaining the target languages info from project:

    $Project = Get-Project $ProjectLocation
    $TargetLanguagesList = @($Project.GetProjectInfo().TargetLanguages.IsoAbbreviation)

    The "Get-Project" function is slightly enhanced function from the original PS Toolkit - it takes the project directory as parameter and finds the *.sdlproj file path automatically:

    function Get-Project {
        param(
            # Path to directory where the project file is located.
            [Parameter (Mandatory = $true)]
            [String] $ProjectLocation
        )

        # get project file path
        $ProjectFilePath = Get-ChildItem (Resolve-Path $ProjectLocation) *.sdlproj | ForEach {$_.FullName}

        # get file based project
        $Project = New-Object Sdl.ProjectAutomation.FileBased.FileBasedProject($ProjectFilePath)

        return $Project
    }

    I'm wondering what does the "4.5.0.0" version actually refer to.
    I found this article: http://www.tomasvoracek.com/2015/07/could-not-load-file-or-assembly-newtonsoft-json-version4-5-0-0-cultureneutral-publickeytoken30ad4fe6b2a6aeed-or-one-of-its-dependencies/, but I see that assembly redirection, recommended as a solution in the article, is actually already present in SDLTradosStudio.exe.config:

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

    So I'm pretty perplexed what the heck is going on...

  • Could it be that the CU7 wasn't built correctly? The Newtonsoft JSON.net DLL was part of CU7.
    See e.g. support.sharpcrafters.com/.../1836-error-occurs-after-upgrading-jsonnet

    Actually I found that CU7 contains several DLLs with LOWER VERSION than CU6!
    That means that installing using Studio 2015 SR2 installer and applying CU7 directly results in DIFFERENT installation than installing SR2 and applying CU6 first and then CU7.
  • BUMMER!

    Just got the Newtonsoft error on my main Win7 machine when tried to apply RetroFit. I'm EXTREMELY overloaded now and the last thing I need is TOTALLY UNRELIABLE tool :(

    Going back to CU6 immediately! :(

    <SDLErrorDetails time="10/24/2016 7:28:07 PM">
      <ErrorMessage>Could not load file or assembly 'Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)</ErrorMessage>
      <Exception>
        <Type>System.IO.FileLoadException, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</Type>
        <FileName>Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed</FileName>
        <FusionLog>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].
    </FusionLog>
        <HelpLink />
        <Source>mscorlib</Source>
        <HResult>-2146234304</HResult>
        <StackTrace><![CDATA[   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(RuntimePropertyInfo property, RuntimeType caType)
       at System.Reflection.RuntimePropertyInfo.GetCustomAttributes(Type attributeType, Boolean inherit)
       at System.Runtime.Serialization.ClassDataContract.ClassDataContractCriticalHelper.ImportDataMembers()
       at System.Runtime.Serialization.ClassDataContract.ClassDataContractCriticalHelper..ctor(Type type)
       at System.Runtime.Serialization.DataContract.DataContractCriticalHelper.CreateDataContract(Int32 id, RuntimeTypeHandle typeHandle, Type type)
       at System.Runtime.Serialization.DataContract.DataContractCriticalHelper.GetDataContractSkipValidation(Int32 id, RuntimeTypeHandle typeHandle, Type type)
       at System.Runtime.Serialization.XmlObjectSerializerContext.GetDataContract(Int32 id, RuntimeTypeHandle typeHandle)
       at System.Runtime.Serialization.XmlObjectSerializerReadContext.InternalDeserialize(XmlReaderDelegator xmlReader, Int32 id, RuntimeTypeHandle declaredTypeHandle, String name, String ns)
       at ReadRetrofitFileMappingItemFromXml(XmlReaderDelegator , XmlObjectSerializerReadContext , XmlDictionaryString[] , XmlDictionaryString[] )
       at System.Runtime.Serialization.ClassDataContract.ReadXmlValue(XmlReaderDelegator xmlReader, XmlObjectSerializerReadContext context)
       at System.Runtime.Serialization.XmlObjectSerializerReadContext.ReadDataContractValue(DataContract dataContract, XmlReaderDelegator reader)
       at System.Runtime.Serialization.XmlObjectSerializerReadContext.InternalDeserialize(XmlReaderDelegator reader, String name, String ns, Type declaredType, DataContract& dataContract)
       at System.Runtime.Serialization.XmlObjectSerializerReadContext.InternalDeserialize(XmlReaderDelegator xmlReader, Int32 id, RuntimeTypeHandle declaredTypeHandle, String name, String ns)
       at ReadArrayOfRetrofitFileMappingItemFromXml(XmlReaderDelegator , XmlObjectSerializerReadContext , XmlDictionaryString , XmlDictionaryString , CollectionDataContract )
       at System.Runtime.Serialization.CollectionDataContract.ReadXmlValue(XmlReaderDelegator xmlReader, XmlObjectSerializerReadContext context)
       at System.Runtime.Serialization.XmlObjectSerializerReadContext.ReadDataContractValue(DataContract dataContract, XmlReaderDelegator reader)
       at System.Runtime.Serialization.XmlObjectSerializerReadContext.InternalDeserialize(XmlReaderDelegator reader, String name, String ns, Type declaredType, DataContract& dataContract)
       at System.Runtime.Serialization.XmlObjectSerializerReadContext.InternalDeserialize(XmlReaderDelegator xmlReader, Type declaredType, DataContract dataContract, String name, String ns)
       at System.Runtime.Serialization.DataContractSerializer.InternalReadObject(XmlReaderDelegator xmlReader, Boolean verifyObjectName, DataContractResolver dataContractResolver)
       at System.Runtime.Serialization.XmlObjectSerializer.ReadObjectHandleExceptions(XmlReaderDelegator reader, Boolean verifyObjectName, DataContractResolver dataContractResolver)
       at System.Runtime.Serialization.DataContractSerializer.ReadObject(XmlReader reader)
       at Sdl.Core.Settings.Implementation.DataContractSerializableSetting`1.get_Value()
       at Sdl.TranslationStudio.Common.BatchProcessing.RetrofitWizardPage.OnNext()
       at Sdl.Desktop.Platform.Wizard.AbstractWizard`1.Next()
       at Sdl.Desktop.Platform.Wizard.AbstractWizard`1._form_Next(Object sender, CancelEventArgs e)
       at Sdl.Desktop.Platform.WinForms.WizardForm._nextButton_Click(Object sender, EventArgs e)
       at System.Windows.Forms.Control.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnClick(EventArgs e)
       at System.Windows.Forms.Button.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)]]></StackTrace>
      </Exception>
      <Environment>
        <ProductName>SDL Trados Studio</ProductName>
        <ProductVersion>12.0.0.0</ProductVersion>
        <EntryAssemblyFileVersion>12.2.5195.7</EntryAssemblyFileVersion>
        <OperatingSystem>Microsoft Windows 7 Professional </OperatingSystem>
        <ServicePack>Service Pack 1</ServicePack>
        <OperatingSystemLanguage>1033</OperatingSystemLanguage>
        <CodePage>1250</CodePage>
        <LoggedOnUser>EvzenP-NB\EvzenP</LoggedOnUser>
        <DotNetFrameWork>4.0.30319.42000</DotNetFrameWork>
        <ComputerName>EVZENP-NB</ComputerName>
        <ConnectedToNetwork>True</ConnectedToNetwork>
        <PhysicalMemory>16655412 MB</PhysicalMemory>
      </Environment>
    </SDLErrorDetails>

  • Any further statements from SDL side, please?
    Any CU7 re-release or similar in sight?
  • Need  or  to respond to this one.  There won't be a CU7 re-release of course but it would be good to see if we can find out what is happening here.

  • Well, some solution will definitely be needed... so that one can actually use CU7.
    I can only say that downgrading to CU6 solved the problem here.
  • You could try and use the assembly resolver class from .NET Framework. An example of using it from powershell can be found here. This is a similar solution as the one I applied on my assembly resolver library for SDL Studio where I'm resolve dependencies to Studio public API when you have an application installed outside of SDL Studio folder.

  • Okay, might try that... but that won't solve the problem within Studio itself (see screenshot on page 1) anyway.
  • I finally tried to use the referenced piece of PS code, but it doesn't work... the error is still the same.

    But that's not the point... I don't want any workarounds, I need correctly working Studio.

    It's a clean W10 installation with only Studio 2015 installed (SR2 installer + CU7). And that's the result - I'm not an expert, but it seems to me like something incorrectly done by Studio installer (newer Newtonsoft.Json.dll not properly registered, or what):