I am currently working on a console application which references a class in a WPF project, with hopes of launching the WPF Window when specific conditions are met.
I have a simple object I would like to call from the console application, and it looks like this:
namespace MyNamespace
{
public class TestLoad
{
public string Property { get; set; }
public TestLoad()
{
Property = "hey there";
}
}
}
In my console application, I am using this simple constructor to call to the object (I have a reference to the WPF executable):
using MyNamespace;
...
TestLoad myObject = new TestLoad();
This builds and compiles with no issues; however, at runtime, when I get to the function that contains the above line, it jumps of the function with this error:
System.TypeLoadException was unhandled by user code
HResult=-2146233054
Message=Could not load type 'MyNamespace.TestLoad' from assembly 'MyNamespace, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
Source=MyProject
TypeName=MyNamespace.TestLoad
StackTrace:
at MyProject.DiskInit.UploadNewDocument(String DrivePath)
at MyProject.DiskInit.<>c__DisplayClass67_0.<CbFsWriteFile>b__0() in C:\<somepath>\DiskInit.cs:line 1130
at System.Threading.Tasks.Task.InnerInvoke()
at System.Threading.Tasks.Task.Execute()
InnerException:
I have checked that both projects are on the same .NET version (4.5) and run on the same architecture (x86). Even if the class is changed to a static reference, the same TypeLOadException error occurs. I have been looking into this and read that it is a potential bug with Visual Studio, essentially compiling something it should not since it will cause this runtime error. I have also read that it is a potential bug with referencing WPF projects, and the only way to resolve that is to change the project to output a dll. My only issue with that is that I seem to lose the ability to create a WPF window that can be launched externally from the executing application. Is this correct?
Has anyone encountered this type of issue before or know how to get around it? If not, is there a better alternative to using a WPF Window in this manner, which is essentially to load a (pretty) user input dialog when the console application's conditions are met? Thank you in advance for any feedback.