“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. SAP成都C4C小李探花:浅谈Fiori Design Guidelines

    Jerry: 我和周帅认识不久,自去年7月SAP成都研究院Cloud for Customer(以下简称为C4C)开发团队组建至今,根据这段时间和周帅愉快的合作经历,我觉得如果把周帅比作我读过的小说里 ...

  2. object dection资源

    https://handong1587.github.io/deep_learning/2015/10/09/object-detection.html

  3. unity简单例子

    1. https://www.cnblogs.com/chengxuzhimei/p/4992106.html 2.https://www.cnblogs.com/GreenLeaves/p/7086 ...

  4. c#无限循环

    for( ; ; ) 最快的 while(true) while(1)             ?好像也是不过就是扫到的 public bool a= true; 中断一个循环while(a) a=f ...

  5. Linux 安装Oracle11g完整安装图文教程另附基本操作 (分享)

    一.修改操作系统核心参数 在Root用户下执行以下步骤: 1)修改用户的SHELL的限制,修改/etc/security/limits.conf文件 输入命令:vi /etc/security/lim ...

  6. MySql客户端远程连接MySql服务器

    设置MySql服务器以接听端口及以绑定IP地址 MySql服务器默认监听3306端口,确定防火墙以开放此端口. 编辑/etc/my.cnf 添加绑定IP地址.bind-address=192.168. ...

  7. Java web--过滤器

    本文引自:https://www.cnblogs.com/dudududu/p/8505177.html 参考博客:http://www.cnblogs.com/coderland/p/5902878 ...

  8. dede后台添加优酷等视频iframe链接时被替换成了图片

     添加文章时 添加优酷视频 :<iframe height=498 width=510 src='http://player.youku.com/embed/XNDAzNTAzODE4OA==' ...

  9. scrapy--json(喜马拉雅Fm)(二)

    学习了对数据的储存,感觉还不够深入,昨天开始对储存数据进行提取.整合和图像化显示.实例还是喜马拉雅Fm,算是对之前数据爬取之后的补充. 明确需要解决的问题 1,蕊希电台全部作品的进行储存 --scra ...

  10. linux 特殊命令(一)

    1.ifconfig 网卡配置:ifconfig  [网络设备] [参数] 1) up 启动指定网络设备/网卡. 2) down 关闭指定网络设备/网卡.该参数可以有效地阻止通过指定接口的IP信息流, ...