“System.IO.FileNotFoundException:“Could not load file or assembly 'ClassLibrary2, Culture=neutral, PublicKeyToken=null'. 系统找不到指定的文件。””

  在 .net 程序开发中我们会经常用到反射,最近在开始慢慢接触 .netCore。Core 反射的语法也是一样的,所以写下来也没有什么问题,但是一运行,就弹出了开头的 异常。

  项目结构如下

  

  ClassLibrary3 是一个接口

  

namespace ClassLibrary3
{
public interface IClass1
{
void Print();
}
}

ClassLibrary2 是 ClassLibrary3 的实现

namespace ClassLibrary2
{
public class Class1:IClass1
{
public void Print()
{
Console.WriteLine("Print.....");
}
}
}

主程序通过反射获取到到类型并创建对象

class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!"); Assembly assembly = Assembly.Load(new AssemblyName("ClassLibrary2"));
Type type = assembly.GetType("ClassLibrary2.Class1");
var instance = (IClass1)Activator.CreateInstance(type);
instance.Print();
Console.ReadLine();
}
}

这代码都这里没有问题,但是执行的时候却抛出了 开篇的异常。仔细检查了下,ClassLibrary2 生成的 dll 确认已经是复制到了主程序目录下。

刚开始接触Core  也没有系统去熟悉,最后经过多方努力后,发现在主程序项目下有个 deps.json 的文件

文件内容是这样的(里面没有 ClassLibrary2 因为我们没有在项目中引用 ClassLibrary2)

然后想着 那异常提示找不到路径,那我们在这里配置下不久可以了?

然后改成如下:

这时候我们运行程序:

完美!

.netCore 反射 :Could not load file or assembly 系统找不到指定文件的更多相关文章

  1. Could not load file or assembly ‘ Oracle.ManagedDataAccess.EntityFramework, Version=6.121.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342’ or one of its dependencies系统找不到指定文件 处理方法

    前些天做EF Model-First测试,开发环境为VS2013,数据库为Oracle 11g.所有东西都装好数据模型已经建立后准备执行“根据模型生成数据库”命令时,出现:Could not load ...

  2. 服务 在初始化安装时发生异常:System.IO.FileNotFoundException: "file:///D:\testService"未能加载文件或程序集。系统找不到指定文件。

    @echo.@if exist "%windir%\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe" goto INSTALL ...

  3. Could not load file or assembly 'System.ServiceModel.DomainServices.Hosting'.系统找不到指定文件

    项目部署到服务器后出现如下错误信息: Parser Error Message: Could not load file or assembly 'System.ServiceModel.Domain ...

  4. NET core 添加了新的nuget包,部署出现Could not load file or assembly

    这个坑,今天整了一天,我添加了Microsoft.AspNetCore.Mvc.Versioning包,结果发布到服务器,我复制了dll过去出现了一直找不到加载不成功的问题 Startup.Confi ...

  5. 【C# 程序集】.NET core Could not load file or assembly

    NET core 添加了新的nuget包,部署出现Could not load file or assembly 这个坑,今天整了一天,我添加了Microsoft.AspNetCore.Mvc.Ver ...

  6. configuration error-could not load file or assembly crystaldecisions.reportappserver.clientdoc

    IIS启动网站后报错: configuration error Could not load file or assembly 'crystaldecisions.reportappserver.cl ...

  7. Could not load file or assembly 'Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its de

    页面加载时出现这个错误: Could not load file or assembly 'Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Cul ...

  8. ASP.NET corrupt assembly “Could not load file or assembly App_Web_*

    以下是从overFlow 复制过来的问题 I've read through many of the other questions posted on the same issue, but I s ...

  9. Could not load file or assembly 'Microsoft.SqlServer.Management.Sdk.Sfc, Version=11.0.0.0 系统找不到指定的文件。

    环境: web服务器: ip:192.168.1.32 ,安装有 Visual Studio Premium 2013 操作系统: Microsoft  Server 2008 r2+sp1 数据库服 ...

随机推荐

  1. Selenium入门7 内嵌框架iframe

    如果网页内嵌iframe,那么iframe里的元素是无法直接定位的,需要使用switch_to.frame进入frame操作: 之后需要再操作页面上非嵌入在iframe里的元素,需要使用switch_ ...

  2. Java中JSON字符串与java对象的互换实例详解

    这篇文章主要介绍了在java中,JSON字符串与java对象的相互转换实例详解,非常不错,具有参考借鉴价值,需要的朋友可以参考下 在开发过程中,经常需要和别的系统交换数据,数据交换的格式有XML.JS ...

  3. P1151 子数整数

    题目描述 对于一个五位数a_1a_2a_3a_4a_5a1​a2​a3​a4​a5​,可将其拆分为三个子数: sub_1=a_1a_2a_3sub1​=a1​a2​a3​ sub_2=a_2a_3a_ ...

  4. mysql基础 反范式化

  5. LeetCode970. 强整数

    问题:970. 强整数 用户通过次数0 用户尝试次数0 通过次数0 提交次数0 题目难度Easy 给定两个非负整数 x 和 y,如果某一整数等于 x^i + y^j,其中整数 i >= 0 且  ...

  6. 云计算之KVM虚拟化实战

    1 基础环境规划 1.1 主机环境规划 系统版本 主机名 IP地址 内存 磁盘 CentOS6.9 kvm-node1 10.0.0.200 2G 20G CentOS6.9 kvm-node2 10 ...

  7. PHP常用180函数总结

    数学函数 1.abs(): 求绝对值 <span style="font-size: 14px;">$abs = abs(-4.2); //4.2<br>& ...

  8. 10.2 DOM 操作技术【JavaScript高级程序设计第三版】

    很多时候,DOM 操作都比较简明,因此用JavaScript 生成那些通常原本是用HTML 代码生成的内容并不麻烦.不过,也有一些时候,操作DOM 并不像表面上看起来那么简单.由于浏览器中充斥着隐藏的 ...

  9. Windows手工创建服务方法

    需要将程序设置成Windows服务的情况,可以利用一下windows自带的sc命令来创建服务. 该命令的基本用法如下:打开cmd命令, 输入如下信息:1 创建服务:sc create SecServe ...

  10. Matplotlib库介绍

    pyplot的plot()函数 pyplot的中文显示 pyplot的文本显示 pyplot的子绘图区域