[英]Reference to a class library (.Net framework) method from .Net core API is throwing an error
I have a Web API project whose target framework is .Net Core 2.1
.我有一个 Web API 项目,其目标框架是
.Net Core 2.1
。 The project has reference to a class library built on .Net Framework 4.5.2 .该项目引用了一个基于.Net Framework 4.5.2 的类库。 While calling the method on the class library which basically encodes / decodes a given value is throwing the following run time error.
在类库上调用基本上对给定值进行编码/解码的方法时,会引发以下运行时错误。
Could not load type 'System.Security.Cryptography.MACTripleDES' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.":"System.Security.Cryptography.MACTripleDES"
无法从程序集 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' 加载类型 'System.Security.Cryptography.MACTripleDES'。":"System.Security.Cryptography.MACTripleDES"
Method defined on class Library:在类库上定义的方法:
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)));
}
I could see similar questions on SO, suggesting to add project.json file to the project but I am not clear.我可以在 SO 上看到类似的问题,建议将project.json文件添加到项目中,但我不清楚。 Neither my Web API nor class library has a project.json file in it.
我的 Web API 和类库中都没有project.json文件。
Please provide any insights on it.请提供有关它的任何见解。
What worked for me seems to be:对我有用的似乎是:
<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>
<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.