IDiagramContext is always null RRS feed

  • Question

  • In the following, modelingItem is always null albeit there are several usecasediagrams.

    <#@include file="Requirements.ttinclude"#>
    <#@ output extension=".html" #>
    	foreach (EnvDTE.ProjectItem item in Project.ProjectItems)
    		IDiagramContext modelingItem = item as IDiagramContext;
    		if (modelingItem != null)
    			WriteLine("---> " + item.Name);

    - Ciper
    Thursday, May 19, 2011 8:22 PM


All replies

  • Yes, I think this is because the .tt file runs in a separate AppDomain.

    In general, IDiagramContext is only non-null if the ProjectItem is open. It won't be open in the T4 AppDomain.

    To help think of an alternative approach, take a look at How to Read a UML Model in Program Code.



    - Alan -MSFT

    Tuesday, May 24, 2011 9:37 PM
  • Thank you; that was indeed the reason.

    I ended up loading the model into the template's AppDomain manually:

    private IModelStore LoadModel(EnvDTE.Project project)
     if (project == null) return null;
     // Load UML model into this AppDomain and access model store:
     return ModelingProject.LoadReadOnly(project.FullName).Store;

    - Ciper

    Tuesday, May 24, 2011 11:37 PM
  • Hi, 

    How do you then resolve a ProjectItem from the IModelStore? I'm trying to export UML Diagrams via a t4 template but can't seem to get hold of an IDiagramContext. 



    Tuesday, July 16, 2013 6:42 AM
  • AFAIK, there is no such automatic resolution.

    - Ciper

    Wednesday, July 17, 2013 4:33 PM