Error info:
System.InvalidCastException: Unable to cast object of type 'ClassLibrary1.Plugin' to type 'PluginInterface.IPlugin'.
What I'm trying to do is get my program to access an assembly and run whatever it may have.
This loads the .dll
private void AddPlugin(string FileName)
{
Assembly pluginAssembly = Assembly.LoadFrom(FileName);
foreach (Type pluginType in pluginAssembly.GetTypes())
{
if (pluginType.IsPublic)
{
if (!pluginType.IsAbstract)
{
Type typeInterface = pluginType.GetInterface("PluginInterface… true);
if (typeInterface != null)
{
Types.AvailablePlugin newPlugin = new Types.AvailablePlugin();
newPlugin.AssemblyPath = FileName;
newPlugin.Instance = (IPlugin)Activator.CreateInstance(plugin…
// Above line throws exception.
newPlugin.Instance.Initialize();
this.colAvailablePlugins.Add(newPlugin);
newPlugin = null;
}
typeInterface = null;
}
}
}
pluginAssembly = null;
}
Both my program and my assembly have these two interfaces:
using System;
namespace PluginInterface
{
public interface IPlugin
{
IPluginHost Host { get; set; }
string Name { get; }
string Description { get; }
string Author { get; }
string Version { get; }
System.Windows.Forms.Form MainInterface { get; }
void Initialize();
void Dispose();
void ReceivedMessage(PlayerIOClient.Message m);
void Disconnected();
}
public interface IPluginHost
{
void Say(string message);
void Send(PlayerIOClient.Message m);
void Send(string message_Type, params object[] paramss);
}
}
My Class/Assembly to add:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using PluginInterface;
namespace ClassLibrary1
{
public class Plugin : IPlugin // <-- See how we inherited the IPlugin interface?
{
public Plugin()
{
}
string myName = "Title";
string myDescription = "Descrip";
string myAuthor = "Me";
string myVersion = "0.9.5";
IPluginHost myHost = null;
Form1 myMainInterface = new Form1();
public string Description
{
get { return myDescription; }
}
public string Author
{
get { return myAuthor; }
}
public IPluginHost Host
{
get { return myHost; }
set { myHost = value; }
}
public string Name
{
get { return myName; }
}
public System.Windows.Forms.Form MainInterface
{
get { return myMainInterface; }
}
public string Version
{
get { return myVersion; }
}
public void Initialize()
{
//This is the first Function called by the host...
//Put anything needed to start with here first
MainInterface.Show();
}
public void ReceivedMessage(PlayerIOClient.Message m)
{
}
public void Disconnected()
{
}
public void Dispose()
{
MainInterface.Dispose();
}
}
}
All help is greatly appreciated.
Both my program and my assembly have these two interfaces:
There's your problem.
Two identical interfaces in two different assemblies create two distinct (and unrelated) types.
You need to define the interfaces in a single assembly and add a reference to it.
Related
I have the following classes in a serialization:
[XmlRoot()]
public class XmlExample
{
private NodeA_Elem _nodea;
[XmlElemnt("NodeA")]
public NodeA_Elem NodeA
{
get
{
return _nodea;
}
set
{
_nodea=value;
}
}
private NodeB_Elem _nodeb;
[XmlElemnt("NodeB")]
public NodeB_Elem NodeB
{
get
{
return _nodeb;
}
set
{
_nodeb=value;
}
}
private NodeC_Elem _nodec;
[XmlElemnt("NodeC")]
public NodeC_Elem NodeC
{
get
{
return _nodec;
}
set
{
_nodec=value;
}
}
public class NodeA_Elem
{
[XmlText()]
public string value{get;set;}
}
public class NodeB_Elem
{
[XmlText()]
public string value{get;set;}
}
public class NodeC_Elem
{
[XmlText()]
public string value{get;set;}
}
If the value property of any classes NodaA, NodeB or NodeC is null or empty I have the following result:
<XmlExample>
<NodeA/>
<NodeB/>
<NodeC/>
</XmlExample>
What I have to do to these nodes don't appear like empty nodes if I don't set the value property?
You can use ShouldSerialize* pattern, something like this:-
public bool ShouldSerializeNodeA() {
return NodeA != null;
}
Refer here :-
Conditional xml serialization
Update:
Make it non nullable:-
[XmlElement(IsNullable = false)]
Edit:
Earlier I mentioned :-
public bool ShouldSerializeNodeA() {
return NodeB != null;
}
My mistake, it should be like this:-
public bool ShouldSerializeNodeA() {
return NodeA != null;
}
You can also use a boolean property with the suffix xSpecified to indicate whether or not to serialize a property. This is used by Xml clients which consume xml which have a default value (e.g. as specified with default=xxx in an XSD):
public bool NodeASpecified
{
get { return _nodea != null && !String.IsNullOrEmpty(_nodea.value); }
}
Do not mark these Specified properties with any Xml attributes.
Not related, but hard coding the *Specified properties to true in a partial class is useful if you have consumed a web service which has a default and a minOccurs=0, which would otherwise not be sent at all to the service if the value was coincidentally the same as the default value.
I added up some comments and find a solution. I could use the ShouldSerialize pattern in my code. The resulting code is:
[XmlRoot()]
public class XmlExample
{
private NodeA_Elem _nodea;
[XmlElemnt("NodeA")]
public NodeA_Elem NodeA
{
get
{
return _nodea;
}
set
{
_nodea=value;
}
}
public bool ShouldSerializeNodeA()
{
return !String.IsNullOrEmpty(_nodea.value);
}
private NodeB_Elem _nodeb;
[XmlElemnt("NodeB")]
public NodeB_Elem NodeB
{
get
{
return _nodeb;
}
set
{
_nodeb=value;
}
}
public bool ShouldSerializeNodeB()
{
return !String.IsNullOrEmpty(_nodeb.value);
}
private NodeC_Elem _nodec;
[XmlElemnt("NodeC")]
public NodeC_Elem NodeC
{
get
{
return _nodec;
}
set
{
_nodec=value;
}
}
public bool ShouldSerializeNodeC()
{
return !String.IsNullOrEmpty(_nodec.value);
}
}
public class NodeA_Elem
{
[XmlText()]
public string value{get;set;}
}
public class NodeB_Elem
{
[XmlText()]
public string value{get;set;}
}
public class NodeC_Elem
{
[XmlText()]
public string value{get;set;}
}
Edit:
Here is the full code of my example:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
namespace Serialization_Example
{
class Program
{
static void Main(string[] args)
{
MyXmlDocument document = new MyXmlDocument();
document.MyExample.NodeA.value = "Value To Node A";
document.MyExample.NodeC.value = "Value To Node C";
document.WriteToXml(#"C:\Users\user_Name\Desktop\mydocument.xml");
}
}
[XmlRoot("xmlExample")]
public class XmlExample
{
private NodeA_Elem _nodea;
[XmlElement()]
public NodeA_Elem NodeA
{
get
{
return _nodea;
}
set
{
_nodea = value;
}
}
public bool ShouldSerializeNodeA()
{
return !String.IsNullOrEmpty(_nodea.value);
}
private NodeB_Elem _nodeb;
[XmlElement("NodeB")]
public NodeB_Elem NodeB
{
get
{
return _nodeb;
}
set
{
_nodeb = value;
}
}
public bool ShouldSerializeNodeB()
{
return !String.IsNullOrEmpty(_nodeb.value);
}
private NodeC_Elem _nodec;
[XmlElement("NodeC")]
public NodeC_Elem NodeC
{
get
{
return _nodec;
}
set
{
_nodec = value;
}
}
public bool ShouldSerializeNodeC()
{
return !String.IsNullOrEmpty(_nodec.value);
}
public XmlExample()
{
_nodea = new NodeA_Elem();
_nodeb = new NodeB_Elem();
_nodec = new NodeC_Elem();
}
}
public class NodeA_Elem
{
[XmlText()]
public string value { get; set; }
}
public class NodeB_Elem
{
[XmlText()]
public string value { get; set; }
}
public class NodeC_Elem
{
[XmlText()]
public string value { get; set; }
}
public class MyXmlDocument
{
private XmlExample _myexample;
public XmlExample MyExample
{
get
{
return _myexample;
}
set
{
_myexample = value;
}
}
public void WriteToXml(string path)
{
XmlSerializer serializer = new XmlSerializer(typeof(XmlExample));
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
settings.Encoding = Encoding.Unicode;
StringWriter txtwriter = new StringWriter();
XmlWriter xmlwtr = XmlWriter.Create(txtwriter, settings);
serializer.Serialize(xmlwtr, MyExample);
StreamWriter writer = new StreamWriter(path);
writer.Write(txtwriter.ToString());
writer.Close();
}
public MyXmlDocument()
{
_myexample = new XmlExample();
}
}
}
If you compile it, you'll see that if I don't set the value for NodeB.value, it won't generate a empty node like was happening before.
I've been searching for a while now and tested several methods, but i didn't find the answer i was looking for. I'll try to explain.
I have an object with several fields/properties. These properties have custom attributes.
What i want is to get the custom attribute from a specific propertie without all the knowlege of the object.
The are the base classes
// FieldAttr has a public Text propery
public class TestObject
{
// Declare fields
[FieldAttr("prop_testfld1")]
public FLDtype1 testfld1 = new FLDtype1();
[FieldAttr("prop_testfld2")]
public FLDtype2 testfld2 = new FLDtype2();
[FieldAttr("prop_testfld3")]
public FLDtype1 testfld3;
}
public class FLDtype1
{
public string Value { get; set; }
}
public class FLDtype2
{
public Guid Value { get; set; }
}
public sealed class FieldAttr: System.Attribute
{
private string _txt;
public EntityFieldType(string txt)
{
this._text = txt;
}
public string Text { get { return this._text; } }
}
And i want to be able to do this in my application:
static void Main(string[] args)
{
TestObject test = new TestObject();
// (Option 1: preferred)
Console.WriteLine(test.testfld1.getFieldAttr().Text);
// (Option 2)
Console.WriteLine(test.getFieldAttr(test.testfld1).Text);
}
Is this possible? I've seen methods to get custom attribute values from all properties/fields of an object, but not for a specific field.
I've got a working method to get custom attribute from an enum, but wasn't able to recreate it for object fields/properties. This is because i couldn't get the name of the field i was trying to explore, because (for example) test.testfld1.ToString() give's me "ns.FLDtype1".
Looking forward for the answer :)
(and excuse my english)
Yes it is possible:
public static class Extensions
{
public static FieldAttr GetFieldAttr(
this TestObject source,
Expression<Func<TestObject,object>> field)
{
var member = field.Body as MemberExpression;
if (member == null) return null; // or throw exception
var fieldName = member.Member.Name;
var test = typeof (TestObject);
var fieldType = test.GetField(fieldName);
if (fieldType != null)
{
var attribute = fieldType.GetCustomAttribute<FieldAttr>();
return attribute;
}
return null;
}
}
Usage:
TestObject test = new TestObject();
var attr = test.GetFieldAttr(x => x.testfld3);
if(attr != null) Console.WriteLine(attr.Text);
Here is the fiddle
After another day of trial and error I decided to make use of Selman22 answer with a little modification. This is code I created:
public class TestObject : iTestObject
{
// Declare fields
[FieldAttr("prop_testfld1")]
public FLDtype1 testfld1 = new FLDtype1();
[FieldAttr("prop_testfld2")]
public FLDtype2 testfld2 = new FLDtype2();
[FieldAttr("prop_testfld3")]
public FLDtype1 testfld3;
}
public class FLDtype1 : iField
{
public string Value { get; set; }
}
public class FLDtype2 : iField
{
public Guid Value { get; set; }
}
public sealed class FieldAttr: System.Attribute
{
private string _txt;
public FieldAttr(string txt)
{
this._txt = txt;
}
public string Text { get { return this._txt; } }
}
public interface iField { }
public interface iTestObject { }
public static class Extensions
{
public static FieldAttr GetFieldAttr<T>(this T source, Expression<Func<iField>> field) where T : iTestObject
{
// Get member body. If no body present, return null
MemberExpression member = (MemberExpression)field.Body;
if (member == null) { return null; }
// Get field info. If no field info present, return null
FieldInfo fieldType = typeof(T).GetField(member.Member.Name);
if (fieldType == null) { return null; }
// Return custom attribute
return fieldType.GetCustomAttribute<FieldAttr>();
}
}
Usage:
public class Program
{
public static void Main()
{
TestObject test = new TestObject();
Console.WriteLine(test.GetFieldAttr(() => test.testfld1).Text);
Console.WriteLine(test.GetFieldAttr(() => test.testfld2).Text);
Console.WriteLine(test.GetFieldAttr(() => test.testfld3).Text);
}
}
Uses:
using System;
using System.Linq;
using System.Reflection;
using System.Linq.Expressions;
I have implemented interfaces to protect the GetFieldAttr method
#Sulman22: Thnx for the response!
When I was working on nest classes and ran into issues. That's when somebody told me I need to use interface. Along the way on implementing the interface, there I learned that interface doesn't allow constructor or passing of the argument parameters. So, I'm thinking of abstract but I'm uncertain on implementing them and keeping it simple.
In the source code below. Environment Setting is populated in Console project and is passed on to the Database class in DLL project.
Question #1 - Is it possible to abstract Environment Setting for simplier script?
Question #2 - Using the nested class or not, How do I protected the DealerRepository class (Make it invisible to Console project? (I'm guessing abstract).
Question #3 - Does DealerRepository class need to be abstracted or what?
What I want here is to protect/hide the DealerRepository class from Console project and not having to pass on EnvironmentSetting class/model repeatly through nest classes.
Thanks...
//EnvironmentSetting.cs
namespace zTestcase1.Model {
public class EnvironmentSetting : IDisposable
{
public EnvironmentSetting() { } //Constructor...
public void Dispose() { } /Dispose...
//Member variables...
private string _emulation = "";
private string _application = "";
private string _database = "";
//Get/Set properties...
public string Emulation { get {return _emulation;} set {_emulation = value;} }
public string Application { get {return _application;} set {_application = value;} }
public string Database { get {return _database;} set {_database = value;} }
}
}
//DealerRepository.cs
namespace zTestcase1.Data.Dealer
{
public class DealerRepository : IDisposable
{
public DealerRepository(EnvironmentSetting parmEnvironmentSetting) {
_environmentSettingA = parmEnvironmentSetting;
} //Constructor...
public void Dispose() { } //Dispose...
//Member variables...
private EnvironmentSetting _environmentSettingA = "";
//Get/Set properties...
//N/A...
//Functions...
public string EnvironmentResponse()
{
return "Emulation - " + _environmentSettingA.Emulation + ", Application - " + _environmentSettingA.Application + ", Database - " + _environmentSettingA.Database + "";
}
public string DealerProifle_Lookup(string parmName)
{
return "(DealerProfile-Lookup) - " + parmName;
}
public string DealerProfile_Save(string parmName)
{
return "(DealerProfile-Save) - " + parmName;
}
}
}
namespace zTestcase1.Library
{
/*public class Database : IDisposable
{
//Class...
public class DataDealer : IDisposable
{
//Constructor...
public DataDealer(EnvironmentSetting parmEnvironmentSetting)
{
_environmentSettingA = parmEnvironmentSetting;
}
//Dispose...
public void Dispose() { }
//Member variables...
private EnvironmentSetting _environmentSettingA = null;
private DealerRepository _dataDealer = null;
//Get/Set properties...
public DealerRepository Dealer { get { if (_dataDealer == null) { _dataDealer = new DealerRepository(_environmentSettingA); } return _dataDealer; } }
//Functions...
//N/A...
}*/
//Constructor...
public Database(EnvironmentSetting parmEnvironmentSetting)
{
_environmentSettingB = parmEnvironmentSetting;
}
public void Dispose() { } //Dispose...
//Member variables...
private EnvironmentSetting _environmentSettingB = null;
//private DataDealer _dataDealerB = null;
private DealerRepository _dataDealerC = null;
//Get/Set properties...
//public DataDealer Dealer { get { if (_dataDealerB == null) { _dataDealerB = new DataDealer(_environmentSettingB); } return _dataDealerB; } }
public DealerRepository Dealer { get { if (_dataDealerC == null) { _dataDealerC = new DealerRepository(_environmentSettingB); } return _dataDealerC; } }
//Functions...
//N/A...
}
}
namespace zTestcase1.Sample1.Console
{
class Program
{
static void Main(string[] args)
{
EnvironmentSetting environmentSettting = new EnvironmentSetting();
environmentSettting.Application = "DOS Console";
environmentSettting.Database = "Not yet hooked up";
environmentSettting.Emulation = "Development";
Database _libraryDatabase = new Database(environmentSettting);
//var test1 = _libraryDatabase.Dealer.Dealer.DealerProifle_Lookup("Best Dealer Cars Buy");
var test2 = _libraryDatabase.Dealer.DealerProifle_Lookup("Best Dealer Cars Buy");
System.Console.WriteLine(_libraryDatabase.Dealer.EnvironmentResponse() + " [=] " + test2);
System.Console.ReadLine(); //To pause the console...
}
}
}
Answer #1: Instead of ...
//Member variables...
private string _emulation = "";
private string _application = "";
private string _database = "";
//Get/Set properties...
public string Emulation { get {return _emulation;} set {_emulation = value;} }
public string Application { get {return _application;} set {_application = value;} }
public string Database { get {return _database;} set {_database = value;} }
Your properties can be expressed this way instead (it is equivalent, except for the initialization to "", which can be done if needed in a constructor instead):
public string Emulation { get; set; }
public string Application { get; set; }
public string Database { get; set; }
Answer 2/3: Abstractness and inner classes are not used to limit the visibility of classes to outside callers. Use internal instead: this will give other classes within the same library access, while prohibiting access from outside the current library. Though, in this case, it looks as though you are working with the DealerRepository class from the Console application through the _libraryDatabase.Dealer property. I'm not exactly sure what you're trying to achieve here.
If I've understood you correctly, you need dependency injection.
This will require DI-container. E.g., with MEF the code will look like this:
1) assembly "A.dll" (contracts):
public interface IEnvironmentSetting
{
string Emulation { get; }
string Application { get; }
string Database { get; }
}
public interface IDealerRepository
{
string EnvironmentResponse();
string DealerProifle_Lookup(string parmName);
string DealerProfile_Save(string parmName)
}
public interface IDatabase
{
IDealerRepository Dealer { get; }
}
2) Assembly "B.dll" (implementations):
[Export(typeof(IDatabase))]
public class Database : IDatabase, IDisposable
{
[Import]
public IDealerRepository Dealer { get; set; }
// other code here...
}
[Export(typeof(IDealerRepository))]
public class DealerRepository : IDealerRepository, IDisposable
{
[Import]
private IEnvironmentSetting EnvironmentSetting { get; set; }
// other code here...
}
[Export(typeof(IEnvironmentSetting))]
public class EnvironmentSetting : IEnvironmentSetting, IDisposable
{
// other code here...
}
3) Assembly "C.exe" (console application). You need to refer assembly "A.dll" only from "C.exe":
static void Main(string[] args)
{
using (var catalog = // configure composable part catalog here, read MEF docs to find best way for you)
using (var container = new CompositionContainer(catalog))
{
var database = container.GetExportedValue<IDatabase>();
// you're working with IDatabase and IDealerRepository here,
// there's no direct access to the particular implementation classes
database.Dealer.DealerProifle_Lookup("Best Dealer Cars Buy");
// ...
}
}
i created a json file on my server which im using to send data to a c# program through JSON.NET deserialize. However im im getting a null object exception, can anyone please show me how to create the classes. Thanks
My class is here
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Newtonsoft.Json;
namespace WindowsFormsApplication4
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Load();
}
public void Load()
{
label1.Text = "State:\nLoading...";
try
{
Products pd = new Products();
using (var webClient = new System.Net.WebClient())
{
// download json from url
var json = webClient.DownloadString(url);
// Now parse with JSON.Net
Products convert = JsonConvert.DeserializeObject<Products>(json) as Products;
label1.Text += pd.info.ToString();
label1.Text += "\nWeb Service Connected To";
}
}
catch (JsonSerializationException jsonerr) { label1.Text += "\nWeb Service Connection Failed"; MessageBox.Show(jsonerr.ToString()); }
catch (Exception err) { throw; }
finally { label1.Text += "\nWeb Service Closed"; }
}
}
}
public class Products
{
public Info info;
[JsonProperty("post")]
public Info infos
{
get { return info; }
set { info = value; }
}
}
public class Info
{
private string pd_name;
private int pd_id;
[JsonProperty("pd_id")]
public int pd_ids
{
get { return pd_id; }
set { pd_id = value; }
}
[JsonProperty("pd_name")]
public string pd_names
{
get { return pd_name; }
set { pd_name = value; }
}
}
You're not handling the posts value in the JSON. So if your JSON is formatted like this:
{ "posts" : [ { "post" : { "pd_id" : "399",
"pd_name" : "1.2mm Cylinder Labret"} },
{ "post" : { "pd_id" : "415",
"pd_name" : "1.2mm Laser Etched Labret" }}
] }
Try setting up your classes like this:
public class Posts
{
public List<Products> posts { get; set; }
}
public class Products
{
public List<Info> post { get; set; }
}
public class Info
{
public string pd_id { get; set; }
public string pd_name {get; set; }
}
The following code is a silverlight application but the same happens in WPF, so it seems to be just something I'm missing regarding the delegate, event, etc.
Can anyone tell me why the following code successfully executes this event:
OnLoadingComplete(this, null);
but never executes this event handler?
void initialDataLoader_OnLoadingComplete(object obj, DataLoaderArgs args)
CODE:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Controls;
using System.Diagnostics;
namespace TestEvent22928
{
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
DataLoader initialDataLoader = new DataLoader("initial");
initialDataLoader.RegisterText("test1", "http://test:111/testdata/test1.txt");
initialDataLoader.RegisterText("test2", "http://test:111/testdata/test2.txt");
initialDataLoader.BeginLoading();
initialDataLoader.OnLoadingComplete += new DataLoader.LoadingComplete(initialDataLoader_OnLoadingComplete);
}
void initialDataLoader_OnLoadingComplete(object obj, DataLoaderArgs args)
{
Debug.WriteLine("loading complete"); //WHY DOES EXECUTION NEVER GET HERE?
}
}
public class DataManager
{
public DataLoader CreateDataloader(string dataloaderIdCode)
{
DataLoader dataLoader = new DataLoader(dataloaderIdCode);
return dataLoader;
}
}
public class DataLoader
{
public string IdCode { get; set; }
public List<DataItem> DataItems { get; set; }
public delegate void LoadingComplete(object obj, DataLoaderArgs args);
public event LoadingComplete OnLoadingComplete = delegate { };
private int dataItemCurrentlyLoadingIndex;
public DataLoader(string idCode)
{
IdCode = idCode;
DataItems = new List<DataItem>();
dataItemCurrentlyLoadingIndex = -1;
}
public void RegisterText(string idCode, string absoluteSourceUrl)
{
DataItem dataItem = new DataItem
{
IdCode = idCode,
AbsoluteSourceUrl = absoluteSourceUrl,
Kind = DataItemKind.Text
};
DataItems.Add(dataItem);
}
public void BeginLoading()
{
LoadNext();
}
private void LoadNext()
{
dataItemCurrentlyLoadingIndex++;
if (dataItemCurrentlyLoadingIndex < DataItems.Count())
{
DataItem dataItem = DataItems[dataItemCurrentlyLoadingIndex];
Debug.WriteLine("loading " + dataItem.IdCode + "...");
LoadNext();
}
else
{
OnLoadingComplete(this, null); //EXECUTION GETS HERE
}
}
}
public class DataItem
{
public string IdCode { get; set; }
public string AbsoluteSourceUrl { get; set; }
public DataItemKind Kind { get; set; }
public object DataObject { get; set; }
}
public enum DataItemKind
{
Text,
Image
}
public class DataLoaderArgs : EventArgs
{
public string Message { get; set; }
public DataItem DataItem { get; set; }
public DataLoaderArgs(string message, DataItem dataItem)
{
Message = message;
DataItem = dataItem;
}
}
}
You're registering the handler only after you start loading:
initialDataLoader.BeginLoading();
initialDataLoader.OnLoadingComplete += new DataLoader.LoadingComplete(initialDataLoader_OnLoadingComplete);
The way your code is currently written, it looks like BeginLoading() blocks until completion, which means the handler will never be called, as you don't set it until after you've finished loading.