I’ve tried to get this sorted here:
c# building dll, why do I get an error only in dll build
But its turning into a bit of a huge mess with no clear way forward. I’ve added an enum to a dll and I want to get the num names as a string array, but this causes the application and debugger to crash.
In my dll I’ve create a wrapper class:
namespace myNamespace {
public enum myEnum {
on,
off
};
public class ENUM {
static public string[] GetMyEnumNames() {
return typeof(myEnum).GetNestedType("myEnum").GetEnumNames();
}
}
}
From my c# application, at the top of a cs file I have:
using myNamespace;
Somewhere in the code:
string[] names = myNamespace.ENUM.GetMyEnumNames();
I launch the application in the IDE which is MSVC 2022 Professional, with the above in place it crashes before it hits the line, the function that calls it is the one that crashes, I have no idea why, the error message isn’t very helpful:
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=DataLoggerCS
StackTrace:
at DataLogger.FrmMain.InitGUI() in C:LocalDevVisualStudioProjectFrmMain.cs:line 408
at DataLogger.FrmMain.FrmMain_Shown(Object sender, EventArgs e) in C:LocalDevVisualStudioProjectFrmMain.cs:line 752
at System.Windows.Forms.Form.OnShown(EventArgs e) in System.Windows.FormsForm.cs:line 4840
at System.Windows.Forms.Form.CallShownEvent() in System.Windows.FormsForm.cs:line 4156
at System.Windows.Forms.Control.InvokeMarshaledCallbackDo(ThreadMethodEntry tme) in System.Windows.FormsControl.cs:line 10918
at System.Windows.Forms.Control.InvokeMarshaledCallbackHelper(Object obj) in System.Windows.FormsControl.cs:line 10905
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) in System.ThreadingExecutionContext.cs:line 516
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) in System.ThreadingExecutionContext.cs:line 487
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) in System.ThreadingExecutionContext.cs:line 480
at System.Windows.Forms.Control.InvokeMarshaledCallback(ThreadMethodEntry tme) in System.Windows.FormsControl.cs:line 10888
at System.Windows.Forms.Control.InvokeMarshaledCallbacks() in System.Windows.FormsControl.cs:line 10965
at System.Windows.Forms.Control.WndProc(Message& m) in System.Windows.FormsControl.cs:line 16167
at System.Windows.Forms.ScrollableControl.WndProc(Message& m) in System.Windows.FormsScrollableControl.cs:line 1480
at System.Windows.Forms.Form.WndProc(Message& m) in System.Windows.FormsForm.cs:line 6763
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) in System.Windows.FormsControl.cs:line 136
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) in System.Windows.FormsControl.cs:line 164
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) in System.Windows.FormsNativeWindow.cs:line 761
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData) in System.Windows.FormsApplication.cs:line 305
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context) in System.Windows.FormsApplication.cs:line 1236
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context) in System.Windows.FormsApplication.cs:line 1152
at System.Windows.Forms.Application.Run(Form mainForm) in System.Windows.FormsApplication.cs:line 3232
at DataLogger.Program.Main() in C:LocalDevVisualStudioProjectProgram.cs:line 25
Can anyone help me?