标签: dynamically-loaded-xap

Silverlight:不能在XAP中使用反射到字段的GetValue?

我有一个Silverlight应用程序,它有两个不同的XAP - 一个由HTML页面静态加载的InitialXAP和一个从初始XAP中的代码加载的DynamicXAP.DynamicXAP加载了与此类似的代码:

var asm = LoadAssemblyFromXap(stream, "DLLName"); 
// LoadAssemblyFromXAP will load the DynamicXAP as a file stream, 
// unpack it and load DLLName as a dll. 
var controllerType = asm.GetType("ClassNameToInstantiate_InsideAsm");
var constructor = controllerType.GetConstructor(Type.EmptyTypes);
return constructor.Invoke(null);
Run Code Online (Sandbox Code Playgroud)

我有一个使用反射(特别是FieldInfo.GetValue)来进行数据绑定的类.该类在InitialXAP中定义.如果我尝试在DynamicXAP中使用此类,则会收到错误消息:

Message: Unhandled Error in Silverlight Application System.FieldAccessException: Class.In.DynamicXAP.Which.Uses.The.Reflection.Class.In.InitialXAP
   at System.Reflection.RtFieldInfo.PerformVisibilityCheckOnField(IntPtr field, Object target, IntPtr declaringType, FieldAttributes attr, UInt32 invocationFlags)
   at System.Reflection.RtFieldInfo.InternalGetValue(Object obj, Boolean doVisibilityCheck, Boolean doCheckConsistency)
   at System.Reflection.RtFieldInfo.InternalGetValue(Object obj, Boolean doVisibilityCheck)
   at System.Reflection.RtFieldInfo.GetValue(Object obj)
Run Code Online (Sandbox Code Playgroud)

我可以通过使用反射创建类的子类并使用反射覆盖方法来解决此错误,如下所示:

public class InitialXAP.ClassUsingReflection {

        public virtual object …
Run Code Online (Sandbox Code Playgroud)

reflection silverlight dynamically-loaded-xap

6
推荐指数
1
解决办法
1511
查看次数

动态加载的xap中的WCF服务调用失败

我有一个容器/主Silverlight应用程序.此容器动态下载xaps并调用下载的xaps中的特定用户控件.其中一些用户控件调用托管在服务器上的WCF服务.

当用户控制下载的xap调用WCF服务时,会出现以下错误:

System.InvalidOperationException was unhandled by user code
Message=Cannot find 'ServiceReferences.ClientConfig' in the .xap application 
package. This file is used to configure client proxies for web services, and 
allows the application to locate the services it needs. Either include this 
file in the application package, or modify your code to use a client proxy
constructor that specifies the service address and binding explicitly. Please
see inner exception for details.
StackTrace:
   at System.ServiceModel.Configuration.ServiceModelSectionGroup.
       GetSectionGroup()
   at System.ServiceModel.Configuration.ServiceModelSectionGroup.get_Current()
   at System.ServiceModel.Description.ConfigLoader.LookupChannel(
       String configurationName, String …
Run Code Online (Sandbox Code Playgroud)

silverlight mef dynamically-loaded-xap

5
推荐指数
1
解决办法
2040
查看次数