If the ms
variable is a MemoryStream
and contains a .Net assembly, you would normally run it like this:
var asm = Assembly.Load(ms.ToArray());
var entry = asm.EntryPoint;
var inst = asm.CreateInstance(entry.Name);
entry.Invoke(inst, null);
This works well on console applications and windows forms applications, however, WPF applications throw an exception:
Exception has been thrown by the target of an invocation.
With the inner exception of type System.IO.IOException
:
Cannot locate resource 'mainwindow.xaml'.
The stacktrace is really big, but guessing from the start, it can't locate the resources when loaded from memory:
at MS.Internal.AppModel.ResourcePart.GetStreamCore(FileMode mode, FileAccess access)
at System.IO.Packaging.PackagePart.GetStream(FileMode mode, FileAccess access)
at System.IO.Packaging.PackagePart.GetStream()
at System.Windows.Application.LoadComponent(Uri resourceLocator, Boolean bSkipJournaledProperties)
at System.Windows.Application.DoStartup()
at System.Windows.Application.<.ctor>b__1(Object unused)
[...]
How could I fix this?