DPool34
DPool34

Reputation: 85

Getting an exception error when trying to run the default Program.cs (C#) in Visual Studio 2019

I'm taking a course to learn C#. The course had me create a number of directories from the Command Line Interface (CLI). When I tested the directories I created in the CLI (on the top-level folder), by typing the command "dotnet run", it ran the default code correctly, returning "Hello World!"

I then moved on to open the top-level folder in Visual Studio 2019 so I could begin editing. The folder opened correctly and all of my directories were in the Solution Explorer. However, when I attempted to run the default code, I got the following exception.

An unhandled exception of type 'System.IO.FileNotFoundException' occurred in Unknown Module. Could not load file or assembly 'System.Runtime, Version=4.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

Does anyone have any idea what's going on? The strange thing is when I create a new C# project and attempt to run the code, it runs fine. It just seems to be this particular project that's giving me an issue. I deleted the directories and started over from scratch, following the tutorial step by step, but got the same exception.

I should also note that when I created the .NET file (i.e. "dotnet new") in the CLI, I created a Console Application. I created the top-level directory of "testproject". I created two directories inside of testproject: "src" and "test". Inside of the "src" directory, I created the directory "TestProject" and then inside of TestProject, I typed the command "dotnet new console". When I changed directory (cd) to "testproject" (top level), and typed the command "dotnet run" it returned "Hello World!" However, as mentioned, when I opened the top-level testproject folder in Visual Studio, and tried running, it went into break mode and threw that exception.

This noob appreciates the help!

Visual Studio version information (the application is up to date):

Microsoft Visual Studio Community 2019 Version 16.5.4 VisualStudio.16.Release/16.5.4+30011.22 Microsoft .NET Framework Version 4.8.03752

Installed Version: Community

ASP.NET and Web Tools 2019 16.5.236.49856 ASP.NET and Web Tools 2019

ASP.NET Web Frameworks and Tools 2019 16.5.236.49856 For additional information, visit https://www.asp.net/

Azure App Service Tools v3.0.0 16.5.236.49856 Azure App Service Tools v3.0.0

Azure Functions and Web Jobs Tools 16.5.236.49856 Azure Functions and Web Jobs Tools

C# Tools
3.5.0-beta4-20153-05+20b9af913f1b8ce0a62f72bea9e75e4aa3cf6b0e C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Common Azure Tools 1.10 Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

IntelliCode Extension 1.0 IntelliCode Visual Studio Extension Detailed Info

Microsoft Azure Tools 2.9 Microsoft Azure Tools for Microsoft Visual Studio 2019 - v2.9.30207.1

Microsoft Continuous Delivery Tools for Visual Studio 0.4 Simplifying the configuration of Azure DevOps pipelines from within the Visual Studio IDE.

Microsoft JVM Debugger 1.0 Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

Microsoft Library Manager 2.1.25+gdacdb9b7a1 Install client-side libraries easily to any web project

Microsoft MI-Based Debugger 1.0 Provides support for connecting Visual Studio to MI compatible debuggers

Microsoft Visual Studio Tools for Containers 1.1 Develop, run, validate your ASP.NET Core applications in the target environment. F5 your application directly into a container with debugging, or CTRL + F5 to edit & refresh your app without having to rebuild the container.

NuGet Package Manager 5.5.0 NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/

ProjectServicesPackage Extension 1.0 ProjectServicesPackage Visual Studio Extension Detailed Info

SQL Server Data Tools 16.0.62003.05170 Microsoft SQL Server Data Tools

SQL Server Reporting Services 15.0.19103.0 Microsoft SQL Server Reporting Services Designers Version 15.0.19103.0

TypeScript Tools 16.0.20225.2001 TypeScript Tools for Microsoft Visual Studio

Visual Basic Tools
3.5.0-beta4-20153-05+20b9af913f1b8ce0a62f72bea9e75e4aa3cf6b0e Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual F# Tools 10.8.0.0 for F# 4.7
16.5.0-beta.20181.6+85af456066acd4e76d2bc7821b44a325e46f2fca Microsoft Visual F# Tools 10.8.0.0 for F# 4.7

Visual Studio Code Debug Adapter Host Package 1.0 Interop layer for hosting Visual Studio Code debug adapters in Visual Studio

Visual Studio Container Tools Extensions (Preview) 1.0 View, manage, and diagnose containers within Visual Studio.

Visual Studio Tools for Containers 1.0 Visual Studio Tools for Containers

Upvotes: 0

Views: 1104

Answers (1)

John ClearZ
John ClearZ

Reputation: 1001

Why don't you create the project from within Visual Studio? File -> New -> Project.

Does a project file get created in the testproject/src/TestProject/ directory. It will be called TestProject.csproj. Open this in Visual Studio (File -> Open -> Project/Solution) and use this as your root directory. I wouldn't worry about trying to layout custom directories in Visual Studio for now since your a noob like you say.

Upvotes: 1

Related Questions