[英]Reference to a class library (.Net framework) method from .Net core API is throwing an error
我有一个 Web API 项目,其目标框架是.Net Core 2.1
。 该项目引用了一个基于.Net Framework 4.5.2 的类库。 在类库上调用基本上对给定值进行编码/解码的方法时,会引发以下运行时错误。
无法从程序集 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' 加载类型 'System.Security.Cryptography.MACTripleDES'。":"System.Security.Cryptography.MACTripleDES"
在类库上定义的方法:
public string Encryptor(string ID)
{
string EncrytionKey = "sampleKey";
MACTripleDES mac3des = new MACTripleDES();
MD5CryptoServiceProvider md5 = MD5CryptoServiceProvider();
mac3des.Key = md5.ComputeHash(Encoding.UTF8.GetBytes(EncrytionKey));
return Convert.ToBase64String(Encoding.UTF8.GetBytes(ID)) + '-' + Convert.ToBase64String(mac3des.ComputeHash(Encoding.UTF8.GetBytes(ID)));
}
我可以在 SO 上看到类似的问题,建议将project.json文件添加到项目中,但我不清楚。 我的 Web API 和类库中都没有project.json文件。
请提供有关它的任何见解。
对我有用的似乎是:
<dependentAssembly> <assemblyIdentity name="System.Security.Cryptography.MACTripleDES" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-4.3.0.0" newVersion="4.0.2.0" /> </dependentAssembly>
<dependentAssembly> <assemblyIdentity name="System.Security.Cryptography.MACTripleDES"
publicKeyToken="B03F5F7F11D50A3A" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-4.3.0.0" newVersion="4.3.0.0" /> </dependentAssembly>
<dependentAssembly> <assemblyIdentity name="System.Security.Cryptography.MACTripleDES" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-4.3.0.0" newVersion="4.0.2.0" /> </dependentAssembly>
<dependentAssembly> <assemblyIdentity name="System.Security.Cryptography.MACTripleDES"
publicKeyToken="B03F5F7F11D50A3A" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-4.3.0.0" newVersion="4.3.0.0" /> </dependentAssembly>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.