I use VSTA 2.0 CTP.
Hello, I have near the same question about dynamic programming.
In my project, user can layout .NET component dynamically at runtime.
e.g. add an System.Windows.Forms.Label, or 3-party user control.
So when generating proxy file, I don't know the collection of types.
When new control added, I call the following code:
internal void AddHostObject(Control ctrl)
{
string cookie = ctrl.Name + "$" + ctrl.GetType().FullName + "$ThisApplication";
IVstaHostItem item = addInProperty.HostAdapter.ProjectHostItems["ThisApplication"].ProgrammingModelHostItem;
IVstaHostObject hostObject = item.HostObjects.Add(ctrl.Name, ctrl.GetType().FullName, cookie);
}
e.g. add a System.Windows.Forms.Label control named Lable1.
Label1 will be added to VSTA project correctly(?) with type System.Windows.Forms.Label.
When compiling, VSTA complain that the reference can't be found.
I add the System.Windows.Forms to the project.
compile passed.
when loading, a ArgumentNullException throw at <Proxy.cs>:
"this.providerHost.GetHostObject(global::System.Type.GetType(primaryType), primaryCookie);"
with argument name "localType".
public object GetHostObject(string primaryType, string primaryCookie)
{
if (this.providerHost == null)
{
throw new global::System.NullReferenceException("HostItemProvider is not initialized");
}
return this.providerHost.GetHostObject(global::System.Type.GetType(primaryType), primaryCookie);
}
I don't know what's wrong.
GetHostObject of my HostItemProvider wasn't called yet.
Maybe I mixed the proxy type and local type?
Shouldn't I add System.Windows.Forms reference in the VSTA project?
How to resolve this problem?
Thanks.