Silverlight 动态调用XAP 发生异常解决方法
来源:互联网 发布:怎么用软件开网店 编辑:程序博客网 时间:2024/05/19 02:43
怎么在Silverlight 动态调用XAP 我就不说了
问题在于很多人调用时候总发生异常不知所云。
我就把我的经验说说:
1、首先你应该找找动态调用的代码有没有问题
这是我找的没有问题的方法:
<UserControl x:Class="DynamicLoad.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="400"> <Grid x:Name="LayoutRoot" Background="White"> <Border BorderBrush="Silver" BorderThickness="1" Height="271" HorizontalAlignment="Left" Name="border1" VerticalAlignment="Top" Width="400" /> <Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="166,277,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" /> </Grid></UserControl>
using System;using System.Collections.Generic;using System.Linq;using System.Net;using System.Windows;using System.Windows.Controls;using System.Windows.Documents;using System.Windows.Input;using System.Windows.Media;using System.Windows.Media.Animation;using System.Windows.Shapes;using System.Reflection;using System.Windows.Resources;using System.IO;using System.Xml;namespace DynamicLoad{ public partial class MainPage : UserControl { public MainPage() { InitializeComponent(); } private void button1_Click(object sender, RoutedEventArgs e) { try { //下载BeCalled1.xap WebClient webClient = new WebClient(); webClient.OpenReadCompleted += client_OpenReadCompleted; webClient.OpenReadAsync(new Uri("SilverlightApplicationLdaptest.xap", UriKind.RelativeOrAbsolute)); } catch (Exception ex) { MessageBox.Show(ex.Message + "," + ex.StackTrace); } } void client_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e) { if (e.Error == null) { //透過 GetResourceStream 方法取得的其他套件,提供資源資料流資訊 StreamResourceInfo xapResource = new StreamResourceInfo(e.Result, null); //將其中的AppManifest讀取出來 StreamResourceInfo appManifest = Application.GetResourceStream(xapResource, new Uri("AppManifest.xaml", UriKind.Relative)); //建立xml reader XmlReader xmlReader = XmlReader.Create(appManifest.Stream, new XmlReaderSettings { DtdProcessing = DtdProcessing.Ignore }); List<Assembly> list = new List<Assembly>(); while (!xmlReader.EOF) { if (xmlReader.ReadToFollowing("AssemblyPart")) { string dll = xmlReader.GetAttribute("Source"); StreamResourceInfo dllStreamInfo = Application.GetResourceStream(xapResource, new Uri(dll, UriKind.Relative)); AssemblyPart part = new AssemblyPart(); Assembly assembly = part.Load(dllStreamInfo.Stream); list.Add(assembly); } } Assembly appAssembly = list.SingleOrDefault((a) => a.FullName.StartsWith("SilverlightApplicationLdaptest") //这个和XAP包 里面DLL名字必须相同 ); Type type = appAssembly.GetType("SilverlightApplicationLdaptest.MainPage"); //呼叫MainPage那Contol UserControl control = Activator.CreateInstance(type) as UserControl; border1.Child = control; } } }}
2、 你调用XAP 如果用到Web引用 还有App 级别的资源,那么你的主项目就是 调用方必须也要引用。否则会报找不到web服务节点或者找不到资源的问题。
3、如果你用到WebClient那么是无法在本机就是直接打开Html页面方式使用。必须使用服务器,就是地址是http://这种
- Silverlight 动态调用XAP 发生异常解决方法
- Silverlight 动态加载XAP文件
- IIS HTTP 错误 404.17 - Not Found 解决方法 Silverlight xap
- 一个XAP中有多个Silverlight控件时如何选择调用
- Silverlight动态加载XAP,利用反射技术呈现
- Silverlight 理解.xap文件
- silverlight xap 与网站关联
- Silverlight加载xap 使用WCF
- Silverlight中调用ClientBin下非xap内的xml的方法
- Silverlight加载xap后通过反射相互调用方法及元素
- Silverlight加载xap后通过反射相互调用方法及元素
- Silverlight加载xap后通过反射相互调用方法及元素
- 动态加载XAP文件
- MapXtreme 操作地图时出现调用目标发生异常的解决方法--地图状态保存
- MapXtreme 操作地图时出现调用目标发生异常的解决方法--地图状态保存
- android调用jni方法生成的so库函数的过程&发生的异常解决方法(持续更新)
- Silverlight 动态调用 WebService(转)
- 动态配置Silverlight调用WCF
- JDK Logging深入分析
- 推荐引擎:信息逆流
- RegEx Tpis
- 公积金及其社保补缴办理
- SharZipLib 例子
- Silverlight 动态调用XAP 发生异常解决方法
- shell脚本
- ubuntu 11.10 nginx压力测试
- Linux下移植PPPOE
- The problem of one shared object reference between 100 threads.
- JavaScript解析过程你真的清楚吗??
- VB.NET GDI+ 天气预报
- qt中的一个问题
- ApmServ mysql(#1307 :Failed to create procedure 和#1577等错误)解决方法