wpf Assembly.LoadFile dll GetType 反射 抛异常 不具有由 URI 识别的资源。

时间:2023-03-09 15:22:53
wpf  Assembly.LoadFile dll GetType 反射 抛异常 不具有由 URI 识别的资源。
public static void LoadViewFromUri(this Window window, string baseUri)
{
try
{
var resourceLocater = new Uri(baseUri, UriKind.Relative);
var exprCa = (PackagePart)typeof(Application).GetMethod("GetResourceOrContentPart", BindingFlags.NonPublic | BindingFlags.Static).Invoke(null, new object[] { resourceLocater });
var stream = exprCa.GetStream();
var uri = new Uri((Uri)typeof(BaseUriHelper).GetProperty("PackAppBaseUri", BindingFlags.Static | BindingFlags.NonPublic).GetValue(null, null), resourceLocater);
var parserContext = new ParserContext
{
BaseUri = uri
};
typeof(XamlReader).GetMethod("LoadBaml", BindingFlags.NonPublic | BindingFlags.Static).Invoke(null, new object[] { stream, parserContext, window, true }); }
catch (Exception)
{
//log
}
}
   public partial class WinEditPedestrianNormalDeploy : Window
{ public WinEditPedestrianNormalDeploy()
{
//InitializeComponent();//屏蔽
this.LoadViewFromUri("/Harzone.VideoData.RetrieveObjects;component/view/windows/wineditpedestriannormaldeploy.xaml");
}
}