Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12201

Class in DLL crashes application

$
0
0

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 17VisualStudioVersion = 17.8.34525.116MinimumVisualStudioVersion = 10.0.40219.1Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SimonP", "SimonP.csproj", "{A483645B-2014-47B0-BD80-DA56F4356D3F}"EndProjectGlobal    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}    EndGlobalSectionEndGlobal

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:\LocalDev\VisualStudio\Project\FrmMain.cs:line 55   at Project.Program.Main() in C:\LocalDev\VisualStudio\Project\Program.cs:line 24

I've searched online for demos and examples and I really can't see what I've done wrong.

When running in debug I've tried to add a Watch to 'SimonP.clsTest.ShowName' the Value shows:

error CS0012: The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.

I just create a simple Console project, added the reference to the DLL and the exact same call, it worked with no exceptions.

I then create another project this time a Windows Forms App (.NET Framework), added the reference to the dll and the same call to Form1.cs Form1() after InitializeComponet() and 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=SimonPApp  StackTrace:   at SimonPApp.Form1..ctor() in C:\LocalDev\VisualStudio\SimonP\SimonPApp\Form1.cs:line 17   at SimonPApp.Program.Main() in C:\LocalDev\VisualStudio\SimonP\SimonPApp\Program.cs:line 16

SimonPApp project properties, Application, Target framework:.NET Framework 4.7.2

Build Platform:Active (Any CPU)

Platform target:x64

Prefer 32-bit:unchecked


Viewing all articles
Browse latest Browse all 12201

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>