我試圖從dnx451將Web應用程序升級到dotnetcoreapp1.0。CoreCLR,'類型'不包含'GetTypeFromProgID'的定義
此應用程序需要使用舊的庫(至少我認爲它是一個庫)。這段代碼曾經與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核心Web應用程序的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": {}
}
您要求更多「核心」。沒有人喜歡在手機上運行註冊表清潔工。或Linux。使用.NETCore完全沒有任何意義,因爲當你依賴一個只能在Windows上安裝的組件時,纔會有意義。只要將.NET的完整版本作爲目標,它總是可以在這樣的機器上使用。 –
@HansPassant我改變了我的框架到net461,這似乎解決了這個錯誤。謝謝你的幫助。 –