Visual Studio Development Bookmark and Share   
 index > Visual Studio Guidance Automation Toolkit > Cant get a ITypeResolutionService instance from GetService.
 

Cant get a ITypeResolutionService instance from GetService.

Hi,
Code Snippet



I'm trying to get an instance of a ITypeResolutionService from the GetService method but it returns null always... i dont know where to go with this..

any ideas??? am completely stuck until i can sort it...

regards...

[ServiceDependency(typeof (ITypeResolutionService))]
public class AddTemplateAtPositionAction : T4Action
{
private EditPoint insertPoint;
private string file;
private string template;

[Input(Required = true)]
public EditPoint InsertPoint
{
get { return insertPoint; }
set { insertPoint = value; }
}
[Input(Required = true)]
public string Template
{
get { return template; }
set { template = value; }
}

/// <summary>
/// Gets the template.
/// </summary>
/// <returns></returns>
private string GetTemplate()
{
// Path is always relative to package root folder.
// WARNING: if we were to copy our files and zip them, this may not work.
TypeResolutionService resolver = GetService(typeof (ITypeResolutionService)) as TypeResolutionService;

if (resolver == null)
{
throw new ArgumentNullException("TypeResolutionService");
}
if (resolver.BasePath == null)
{
throw new ArgumentNullException("TypeResolutionService.BasePath");
}

file = new FileInfo(Path.Combine(resolver.BasePath + @"\Templates\Text\", Template)).FullName;
return new StreamReader(file).ReadToEnd();
}

/// <summary>
/// See <see cref="M:Microsoft.Practices.RecipeFramework.IAction.Execute"/>.
/// </summary>
public override void Execute()
{
insertPoint.Insert(Render(GetTemplate(), file));
}

/// <summary>
/// See <see cref="M:Microsoft.Practices.RecipeFramework.IAction.Undo"/>.
/// </summary>
public override void Undo()
{
}
}
}


mickdelaney  Thursday, July 05, 2007 1:15 PM

Hi Mick,

are you executing the action as the usual way? because it seems that the action is not sited. I'm not sure if it's your case, but If you're trying to execute an action from another action, you have to site it before to call the Execute.

something like this:

public void Execute()

{
FooAction fooAction = new FooAction();

this.Container.Add(fooAction);

fooAction.Execute();
}

Jose Escrich  Friday, July 06, 2007 3:39 AM
Ok,
this seems like a bigger problem as i cant seem to get ANY service using GetService or even if i explicitly create a IServiceProvider e.g.

Code Snippet

IServiceProvider provider = new VsServiceProvider(VisualStudio);
IConfigurationService service = provider.GetService(typeof(IConfigurationService)) as IConfigurationService;

//service = null



anyone with any suggestions?? i'm lost...
mickdelaney  Thursday, July 05, 2007 2:42 PM

Hi Mick,

are you executing the action as the usual way? because it seems that the action is not sited. I'm not sure if it's your case, but If you're trying to execute an action from another action, you have to site it before to call the Execute.

something like this:

public void Execute()

{
FooAction fooAction = new FooAction();

this.Container.Add(fooAction);

fooAction.Execute();
}

Jose Escrich  Friday, July 06, 2007 3:39 AM
hi jose,
yeah u were right, that was the issue. i was looking thru the docs on addins and services and found the stuff on "sited" but could figure out how to do it.. so i pulled all the code back to the parent action, i'll now refactor it back again..

cheers!!!
mickdelaney  Friday, July 06, 2007 8:00 AM

You can use google to search for other answers

Custom Search

More Threads

• Unable to load type System.Collections.Generic.Dictionary
• Pass an argument to value provider
• Recipe Designer for VS 2008
• Can a recipe be called from a recipe?
• IExtenderProvider the GAT way...
• Installed GAT/GAX but "Guidance Package" items not in VS08's menus
• June 2006 CTP and Hands On Lab
• exception in execution of recipe
• T4 template in Isolated Shell
• Bug in Loading Packages created with GAT June 2006