I am using Microsoft Visual Studio Professional 2022 (64-bit), I am trying to add classes to a DLL. Previously I have created a DLL which contains string resources and this works fine. However any attempt at adding a class, even the simplest example, crashes. Here is my demo DLL class:
namespace SimonP {
public class clsTest {
public static void ShowName() {
Console.WriteLine("Hello World");
}
}
}
This is the project (.sln
) file:
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.8.34525.116
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SimonP", "SimonP.csproj", "{A483645B-2014-47B0-BD80-DA56F4356D3F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{A483645B-2014-47B0-BD80-DA56F4356D3F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A483645B-2014-47B0-BD80-DA56F4356D3F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A483645B-2014-47B0-BD80-DA56F4356D3F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A483645B-2014-47B0-BD80-DA56F4356D3F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {C307CDC2-0CE5-46C5-9B0F-5BD811779D98}
EndGlobalSection
EndGlobal
In my C# application, at the top of FrmMain.cs
:
using SimonP;
Later in the FrmMain
constructor:
public FrmMain() {
try {
SimonP.clsTest.ShowName();
} catch(FileNotFoundException ex) {
Console.WriteLine("HACK");
}
}
I’ve built this and am running it only in the debugger, but as soon as I start debugging I get:
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=Project
StackTrace:
at Project.FrmMain..ctor() in C:LocalDevVisualStudioProjectFrmMain.cs:line 55
at Project.Program.Main() in C:LocalDevVisualStudioProjectProgram.cs:line 24
I’ve searched online for demos and examples and I really can’t see what I’ve done wrong, can anyone help?