. Netcore Reflection: Could not load file or assembly system cannot find the specified file

Source: Internet
Author: User

"System.IO.FileNotFoundException:" Could not load file or assembly ' ClassLibrary2, Culture=neutral, publickeytoken= Null '. The system cannot find the file specified. ""

In. NET program development we will often use reflection, and recently began to touch slowly. Netcore. The syntax for Core reflection is the same, so it's fine to write it down, but as soon as you run it, it pops up the beginning of the exception.

The project structure is as follows

  

ClassLibrary3 is an interface

  

namespace classlibrary3{    publicinterface  IClass1    {        void  Print ();    }}

ClassLibrary2 is the realization of ClassLibrary3

namespace classlibrary2{    publicclass  class1:iclass1    {         public  void  print ()        {            Console.WriteLine ("print ... .. " );        }    }}

The main program gets to the type and creates the object through reflection

classProgram {Static voidMain (string[] args) {Console.WriteLine ("Hello world!"); Assembly Assembly= Assembly.Load (NewAssemblyName ("ClassLibrary2")); Type type= assembly. GetType ("Classlibrary2.class1"); varInstance =(ICLASS1) activator.createinstance (type); Instance.            Print ();        Console.ReadLine (); }    }

This code is not a problem here, but when executed, it throws the opening exception. After careful examination, the DLL acknowledgement generated by ClassLibrary2 has been copied to the main program directory.

The first contact with the core is not familiar with the system, finally after a multi-party effort, found under the main program project has a Deps.json file

The contents of the file are like this (there is no ClassLibrary2 because we have not referenced ClassLibrary2 in the project)

And then think of the exception hint can not find the path, then we will be configured here soon?

Then change to the following:

At this time we run the program:

Perfect!

. Netcore Reflection: Could not load file or assembly system cannot find the specified file

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.