小编Yog*_*ogi的帖子

.Net Core 3.0通过Reflection调用.Net Framework 4.8程序

我有一个 .net Core 3.0 应用程序尝试通过反射调用 .Net Framework 4.8。我们的目标是使用 ConfigurationManager 读取加密的 AppSettings.config (xml),这在 .Net Core 中是不可能的。未加密是,但已加密(CipherData),否。

我访问静态类和方法的反射代码如下所示:

        Assembly assembly = Assembly.LoadFrom(exeFullName);
        MethodInfo method = assembly.GetType(nameSpacenClass).GetMethod(methodName);
        if (method != null)
        {
            object rtnVal = method.Invoke(null, new object[] { jsonParms });
            return rtnVal;
        }
        else
            return null;
Run Code Online (Sandbox Code Playgroud)

method.Invoke 错误并显示以下异常消息: FileNotFoundException: Could not load file or assembly 'System.Configuration.ConfigurationManager, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'。该系统找不到指定的文件。

所以我在.Net Framework 4.8中编写了一个代理程序,并使用相同的代码来访问通过反射读取加密配置的代码,并且工作正常。

然后,我编写了 .net Core 3.0 代码以通过反射访问该代理,但失败了。代理 .Net Framework 4.8 没有任何引用。它是准系统。然而,即使代理不需要,核心仍然需要 ConfigurationManager。Config 程序只有一个引用 - System.Configuration。

Core 3.0 => 加密 App.config => …

.net c# asp.net .net-core asp.net-core

3
推荐指数
1
解决办法
1092
查看次数

标签 统计

.net ×1

.net-core ×1

asp.net ×1

asp.net-core ×1

c# ×1