有一个装配问题 [英] Having an assembly issue

查看:72
本文介绍了有一个装配问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友,



在我的系统中我安装了一些NuGet包,当我尝试编译时收到如下错误信息:



类型'任务'存在于'System.Threading,Version = 1.0.2856.102,Culture = neutral,PublicKeyToken = 31bf3856ad364e35'和'mscorlib,Version = 4.0.0.0,Culture =中性,PublicKeyToken = b77a5c561934e089'





所以我删除了我通过Nuget安装的System.Threading,然后新的错误消息是as:



CS0012:类型'System.Threading.Tasks.Task`1'在未引用的程序集中定义。您必须添加对程序集的引用'System.Threading,Version = 1.0.2856.102,Culture = neutral,PublicKeyToken = 31bf3856ad364e35'。



在此之前我在框架4.5上运行,所以我升级到4.5 .1并将我的项目更改为4.5.1,但错误仍然与第二个错误相同。



那么,我该如何解决这个问题e?



以下是我正在处理的代码



  var  client =  new  HttpClient(); 
var values = new 列表< KeyValuePair< string,string>>();
values.Add( new KeyValuePair< string,string>( task,task));
values.Add( new KeyValuePair< string,string>( 商家,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;





我尝试了什么:



我升级到4.5.1并将我的项目更改为4.5.1



我编辑了web.config:



 <   system.web  >  
< 编译 debug = true targetFramework = 4.5.1 / >





收件人:



 <   system.web  >  
< 编译 debug = true targetFramework = 4.5 .1 >
< 程序集 >
< add assembly = System.Runtime,Version = 4.0.0.0,Culture = neutr al,PublicKeyToken = b03f5f7f11d50a3a / >







更新



我尝试进一步解决了这个问题,我尝试了重定向问题建议。我是做了什么:



< runtime> 
< assemblyBinding applyTo =v2.0.50727xmlns =urn:schemas-microsoft-com:asm.v1>
< dependentAssembly>
< assemblyIdentity name =Newtonsoft.JsonpublicKeyToken =30ad4fe6b2a6aeedculture =neutral/>
< bindingRedirect oldVersion =0.0.0.0-9.0.0.0newVersion =9.0.0.0/>
< / dependentAssembly>< / runtime>





后期

<运行时间> 
< assemblyBinding applyTo =v2.0.50727xmlns =urn:schemas-microsoft-com:asm.v1>
< dependentAssembly>
< assemblyIdentity name =Newtonsoft.JsonpublicKeyToken =30ad4fe6b2a6aeedculture =neutral/>
< bindingRedirect oldVersion =0.0.0.0-9.0.0.0newVersion =9.0.0.0/>
< / dependentAssembly>
< dependentAssembly>
< assemblyIdentity name =System.ThreadingpublicKeyToken =31bf3856ad364e35culture =neutral/>
< bindingRedirect oldVersion =4.0.30319.18402newVersion =1.0.2856.102/>
< / dependentAssembly>
< / assemblyBinding>
< / runtime>





仍然会出现与以下相同的错误:

 CS0012:类型'System.Threading.Tasks.Task`1'在未引用的程序集中定义。您必须添加对程序集'System.Threading,Version = 1.0.2856.102,Culture = neutral,PublicKeyToken = 31bf3856ad364e35'的引用。





再次,我安装了一个NuGetNuGet包管理,它带来了许多依赖项。这可能是原因还是我做错了什么?

解决方案

我认为这是重定向问题读在其中 [ ^ ]关于它:



我有类似于你描述的东西 - 所以我很确定这是解决方案。这很糟糕,因为来自Projects设计时的app.config将在运行时被重定向覆盖,很难发现 - 所以看看你的RUNTIME! app.config ...


目前UWP和Xamarin似乎不支持该库。



我'我有同样的问题,在检查后我发现使用System.Threading.Thread库的软件包实际上无法运行,因为该依赖项失败(即使微软称该软件包完全兼容)。



这里有2篇文章



https://neosmart.net/blog/2017/system-threading-thread -universal-windows-platform-and-the-fragmentation-of-standard-



https://github.com/dotnet/corefx/issues/2576

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));
   // include other fields
   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?

解决方案

I think this is the "Redirect Problem" read here[^] about it:

I had something similar to what you described - so I'm pretty sure this is the solution. It's nasty because your app.config from the Projects design time will be overwritten at runtime with the Redirects, hard to spot - so have a look at your RUNTIME! app.config...


At the moment UWP and Xamarin don't appear to support that library.

I've had the same issues, and after checking around I found that packages that use the System.Threading.Thread library can't actually run because that dependency fails(Even when Microsoft says the package is perfectly compatible).

Here are 2 articles on the subject

https://neosmart.net/blog/2017/system-threading-thread-universal-windows-platform-and-the-fragmentation-of-net-standard/

https://github.com/dotnet/corefx/issues/2576


这篇关于有一个装配问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆