Cannot use class libraries

Thomas Olson 0 Reputation points
2024-11-11T01:27:20.06+00:00

I am learning how to program in C# using Visual Studio Community 2022 (64-bit). When I build a class library and attempt to call it in a program, the program crashes with a file not found error. (error copied below) I added the dll as a reference and also added the using directive for the library.

text of error:

System.IO.FileNotFoundException

  HResult=0x80070002

  Message=Could not load file or assembly 'System.Runtime, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

  Source=<Cannot evaluate the exception source>

  StackTrace:

<Cannot evaluate the exception stack trace>

Developer technologies Visual Studio Other
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Anna Xiu-MSFT 31,056 Reputation points Microsoft External Staff
    2024-11-11T08:14:59.85+00:00

    Hi @Thomas Olson, 

    Welcome to Microsoft Q&A! 

    Could you please tell us how you build a class library and call it in a program? 

    Which version of System.Runtime did you reference? Please ensure that the version of the referenced ‘System.Runtime’ package is 8.0.0.  

    Please check your project’s target framework and try to target a different version. 

    Besides, please check if you have enabled autogenerated binding redirects in the project’s property page or not. You can go to project Properties > Application > check “Auto-generate binding redirects” option. Then, clean and rebuild your solution.

    If it persists, please update your VS2022 and create a new project to build it again. 

    Sincerely,

    Anna


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".  Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.