Hello Friends,
In my system I installed some NuGet packages, when I tried to compile I got an error message as below:
"The type 'Task' exists in both 'System.Threading, Version=1.0.2856.102, Culture=neutral, PublicKeyToken=31bf3856ad364e35' and 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
so I removed the "System.Threading" I installed via Nuget, then the new error message is as:
CS0012: The type 'System.Threading.Tasks.Task`1' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Threading, Version=1.0.2856.102, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
Before this I was running on framework 4.5, so I upgraded to 4.5.1 and change my project to 4.5.1, but the error is still the same as the second error.
So, how do I resolve this issue?
Below is the code I am working on
var client = new HttpClient();
var values = new List<KeyValuePair<string, string>>();
values.Add(new KeyValuePair<string, string>("task", task));
values.Add(new KeyValuePair<string, string>("merchant", merchant_id));
values.Add(new KeyValuePair<string, string>("ref", id));
var content = new FormUrlEncodedContent(values);
System.Threading.Tasks.Task<httpresponsemessage> t = client.PostAsync("https://myepay.com/api/", content);
t.Wait();
var response = t.Result;
What I have tried:
I upgraded to 4.5.1 and change my project to 4.5.1
I edited the web.config from:
<system.web>
<compilation debug="true" targetFramework="4.5.1"/>
To:
<system.web>
<compilation debug="true" targetFramework="4.5.1">
<assemblies>
<add assembly="System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
UPDATED
I tried further to resolve the issue, I tried the redirecting ask suggested.below is what I did:
Former
<runtime>
<assemblyBinding appliesTo="v2.0.50727" 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></runtime>
Latter
<runtime>
<assemblyBinding appliesTo="v2.0.50727" 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>
<dependentAssembly>
<assemblyIdentity name="System.Threading" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="4.0.30319.18402" newVersion="1.0.2856.102" />
</dependentAssembly>
</assemblyBinding>
</runtime>
still it gives the same error as:
CS0012: The type 'System.Threading.Tasks.Task`1' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Threading, Version=1.0.2856.102, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
And again, I installed a NuGet "NuGet Package Management" and it came with many dependencies. could that be the cause or what else is have I done wrong?