English 中文(简体)
银根:不能对跨XAP的田地进行反思?
原标题:Silverlight: Cannot use reflection to GetValue of a field across XAPs?

我的银灯应用有两种不同的XAP,一种初步XAP,固定在超文本页上载,另一种是动态XAP,在最初XAP中装上代码。 自动取款机装载的代码类似:

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);

我有一个使用思考(特别是外地信息)的类别来使数据具有约束力。 这一类别在初始XAP中界定。 如果我试图在动态XAP中使用这一类别,我就有一个错误:

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)

我可以打破这一错误,利用反省,用反省的方法,制造一个子级:

public class InitialXAP.ClassUsingReflection {

        public virtual object GetValue()
        {
            return fieldInfo.GetValue(parent);
        }
}

public class ClassUsingReflection : InitialXAP.ClassUsingReflection {

        public override object GetValue()
        {
            return fieldInfo.GetValue(parent);
        }
}

但我倾向于避免这种重复,允许在动态XAP中从最初的XAP中进行反思。 关于我能做些什么的想法?

问题回答

虽然有一个学习曲线,但我想看一下银星号、EF或棱镜(两者在最近B>)。 它们既支持模块的动态负荷,也支持采用良好的再利用模式和单独/开发。

<编码>InitialXAP.ClassUsing Reflection

Note the duplicate isn t part of the inital xap namespace (ClassUsingReflection), and may be imported. Notice GetVisible - as in not visible to Dynamic xap... Just leave the duplicate (take away base class obviously) and try.





相关问题
Silverlight Rich text box control

Our team decided that we need our own custom Rich text box control for Silverlight app we are developing. We looked at existing controls mentioned at A good rich text control for Silverlight but ...

Silverlight ImageBrush not rendering (with Bing Map Control)

I m trying to add an image to a Pushpin instance from the Silverlight Bing Map Control, but I can t seem to get it to render (the pushpin renders fine). This is probably a general WPF question rather ...

Silverlight OpenFileDialog DoEvents equivalent

I m processing large files after they are selected by the user. My code looks like the following: if (FileDialog.ShowDialog() == true) { // process really big file } This freezes up the UI so ...

list of controls with templates in silverlight

Does anyone know where to find a list of controls that you can set the template on in Silverlight? I ve wasted several hours now trying to create control templates only to find that the control doesn ...

Silverlight, Updating the UI during processing

I have a simple silverlight multifile upload application, and i want to provide the user with some feedback, right now its only in a test phase and i dont have the webservice. Somehow i cant get the ...

Silverlight 3 - FindName returns null

This looks a bug to me.. Using Silverlight 3 and i have a user control defined in XAML and trying to access the object during runtime returns a null. <Grid> <common:CommonGridEditPanel x:...

silverlight 3 collection binding

Someone please help me understand why this binding does not work... I have a class called SelectionManager with a property called dates which is populated by a WCF service. The property is an ...

热门标签