我尝试将网络应用程序从dnx451升级到dotnetcoreapp1.0。
这个应用程序需要使用一个旧库(至少我认为它是一个库)。此片段曾用于与DNX合作,但现在我还没有升级。
//COMPILE ERROR: 'Type' does not contain a definition for 'GetTypeFromProgID'
var comType = Type.GetTypeFromProgID("ABCCrypto2.Crypto");
var abc = Activator.CreateInstance(comType);
var license = _config["AbcCrypto:License"];
var password = _config["AbcCrypto:Password"];
comType.InvokeMember("License", System.Reflection.BindingFlags.SetProperty, null, abc, new object[] { license });
comType.InvokeMember("Password", System.Reflection.BindingFlags.SetProperty, null, abc, new object[] { password });
var hashed = comType.InvokeMember("Encrypt", System.Reflection.BindingFlags.InvokeMethod, null, abc, new object[] { data });
任何想法或解决方法?谢谢!
修改
上面的代码位于一个独立于引用它的ASP.NET核心Web应用程序的类库中。这是类库的project.json:
"buildOptions": {
"emitEntryPoint": false
},
"dependencies": {
"MyApp.Data": "1.0.0-*",
"System.Net.Mail": "1.0.0-rtm-00002",
"System.Runtime": "4.1.0"
},
"frameworks": {
"netcoreapp1.0": { }
}
这是ASP.NET Core Web Application的project.json:
"buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true
},
"dependencies": {
"MyApp.Services": "1.0.0-*",
"Microsoft.AspNetCore.Authentication.Cookies": "1.0.0",
"Microsoft.AspNetCore.Authorization": "1.0.0",
"Microsoft.AspNetCore.Diagnostics": "1.0.0",
"Microsoft.AspNetCore.Hosting": "1.0.0",
"Microsoft.AspNetCore.Hosting.Abstractions": "1.0.0",
"Microsoft.AspNetCore.Http.Extensions": "1.0.0",
"Microsoft.AspNetCore.Localization": "1.0.0",
"Microsoft.AspNetCore.Mvc": "1.0.0",
"Microsoft.AspNetCore.Routing": "1.0.0",
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
"Microsoft.AspNetCore.Session": "1.0.0",
"Microsoft.AspNetCore.StaticFiles": "1.0.0",
"Microsoft.Extensions.Caching.SqlServer": "1.0.0",
"Microsoft.Extensions.Logging.Console": "1.0.0",
"Microsoft.Extensions.Logging.Debug": "1.0.0",
"Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0"
},
"frameworks": {
"netcoreapp1.0": {
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.0"
}
}
}
},
"runtimes": {
"win10-x86": {}
}
答案 0 :(得分:0)
Type.GetTypeFromProgID
添加到依赖项部分,则存在 "System.Runtime": "4.1.0"
。
如果您想检查某些api是否存在以及它存在于何处,请使用apisof.net。
无论如何,正如汉斯写的那样,也许你根本不应该以网络核心为目标。
答案 1 :(得分:0)
我将我的框架更改为net461并且有效。我仍然可以使用AspNetCore包:
"frameworks": {
"net461": {}
}
但是,我现在遇到了与加载COM库有关的问题,但我认为这是一个单独的错误,所以我会发布一个新问题。