【发布时间】:2016-10-14 22:04:38
【问题描述】:
我正在构建一个 C# (.NET 4.5) 应用程序,它使用 Newtonsoft.Json 来处理各种事情。我正在尝试集成 Twitterizer,但它似乎正在尝试加载旧版本的 Newtonsoft.Json,从而导致运行时异常。
我尝试将重定向添加到我的 App.config,如下所示:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30AD4FE6B2A6AEED" culture="neutral"/>
<bindingRedirect oldVersion="2.4.2.43046" newVersion="4.5.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
不幸的是,这并没有解决问题。这是添加重定向后的异常:
System.IO.FileLoadException: 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)
File name: 'Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'
at Twitterizer.Core.TwitterCommand'1.ExecuteCommand()
at Twitterizer.Core.CommandPerformer.PerformAction[T](ICommand'1 command)
at Twitterizer.TwitterTimeline.UserTimeline(OAuthTokens tokens, UserTimelineOptions options)
at (redacted).Workflow.GetMyTweets(Int32 count) in (redacted)\Workflow.cs:line 810
at (redacted).Workflow.Twitter() in (redacted)\Workflow.cs:line 787
at (redacted).Workflow.Execute(Int32 browser, Log WorkflowLog) in (redacted)\Workflow.cs:line 677
=== Pre-bind state information ===
LOG: DisplayName = Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed
(Fully-specified)
LOG: Appbase = file:///(redacted)/bin/Release/
LOG: Initial PrivatePath = NULL
Calling assembly : Twitterizer2, Version=2.4.2.43046, Culture=neutral, PublicKeyToken=69d1469eac671567.
LOG: This bind starts in default load context.
LOG: Using application configuration file: (redacted)\bin\Release\(redacted).vshost.exe.Config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed
LOG: Attempting download of new URL file:///(redacted)/bin/Release/Newtonsoft.Json.DLL.
WRN: Comparing the assembly name resulted in the mismatch: Major Version
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.
请注意,由于各种原因,我无法切换到不同的 Twitter 库(即 Linq2Twitter 等不是一个选项),我也无法将我的 JSON 处理恢复为使用的旧库版本通过 Twitterizer。
我需要找到一种方法来完成这项工作,而无需更改我正在使用的库/版本。
有什么想法吗?感谢您的帮助!
【问题讨论】:
标签: c# .net json twitter twitterizer