如何将.Net Framework 中的函数调用到.Net core [英] How to call function in .Net Framework to .Net core
问题描述
我正在做一个同时使用 .net 框架和 .net 核心的项目.
I am doing a project that use both .net framework and .net core.
我想调用在 .net core 的 API 控制器中获取数据的存储库,但出现以下错误:
I want to call repository that fetch data in API controller of .net core but i get the following error:
System.TypeLoadException: '无法从程序集'System.Web,版本=4.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a'中加载类型'System.Web.HttpContext'.'
System.TypeLoadException: 'Could not load type 'System.Web.HttpContext' from assembly 'System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.'
请帮助我,谢谢.
推荐答案
您不适合从 .NET 框架调用 .NET 核心中的函数.相反,我建议对于在您的两个项目之间共享的函数和类,您可以在 .NET Standard 的库中编写它们.这可以从 .NET 框架项目和 .NET 核心项目访问.
You are not in position to call functions in .NET core from .NET framework. Rather, I recomment that for the functions and classes shared between both of your projects, you write them in a library in .NET Standard. This will be accessible from both the .NET framework projects and .NET core projects.
有关 NET 架构组件(.NET 标准、核心和框架)的更多信息,请访问 https://docs.microsoft.com/en-us/dotnet/standard/components
For more information about NET architectural components (.NET standard, core and framework), kindly visit https://docs.microsoft.com/en-us/dotnet/standard/components
谢谢
这篇关于如何将.Net Framework 中的函数调用到.Net core的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!