View & Template Selection with CacheResponse attribute

Appears that in view selection, if CacheResponse attribute is applied, #1 will not work. You must set DefaultView attribute or use the convention of request/response dto.cshtml – is this correct / by design or am I doing something wrong?

[CacheResponse(Duration = 60)]
public object Get(Rockstars5 request)
{
    return new HttpResult(new RockstarsResponse6()) 
    {
        View = "DevSpecified1" //#1  this does not work if CacheResponse attribute is set.  returns the html report view
    }
}

This should now be fixed in the latest v4.5.13 release which is now available on MyGet.

1 Like

Is #5 no longer supported?

[ClientCanSwapTemplates]        // #4 Client can select with ?view=UserSpecified4
[DefaultView("DevSpecified3")]  // #3 
public class RockstarsService : Service 
{
    [DefaultView("DevSpecified2")]        // #2 
    public object Get(Rockstars5 request) // #5
    {
        return new HttpResult(new RockstarsResponse6()) // #6
        {
            View = "DevSpecified1"  // #1
        }
    }
}

Are you asking whether it’s still possible to resolve the view from the Request DTO name? That’s still possible, if you don’t have anything with higher precedence, a Get(Rockstars5 request) should use a view named Rockstars5.cshtml in your /Views folder.

Right. I guess there is a difference in view selection when using Gateway to internally execute a service vs. resolving the service and executing it.

I have a view named ApiDocs.cshtml. It is not being used using this method. This method requires a view named MyAccountCategories.cshtml

public object Get(ApiDocs req)
{
	return new ApiDocsResponse
	{
		Categories = Gateway.Send<List<Category>>(new MyAccountCategories())
	};
}

This works: ApiDocs.chtml is used;

public object Get(ApiDocs req)
{
	using (var categoryService = base.ResolveService<CategoryServices>())
	{
		return new ApiDocsResponse
		{
			Categories = (List<Category>)categoryService.Get(new MyAccountCategories())
		};
	}
}

The issue with Gateways should now be resolved from the latest v4.5.13 that’s now available on MyGet.

Thanks Demis – Unfortunately I cannot get 4.5.13 to work.

Could not load file or assembly 'System.Web.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.

Exception Details: System.IO.FileNotFoundException: Could not load file or assembly 'System.Web.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.

The only thing I did was update the Nuget packages. I noticed that in the project file definition, there is a reference removed:

ok strange, for some reason ServiceStack.Razor didn’t end up on MyGet even though CI says it deployed it like everything else. I’ve redeployed to MyGet where ServiceStack.Razor made it this time, can you try upgrading again?

Actually 4.5.12 doesn’t work either.

Appears System.Web.Razor.dll is missing in the package. It’s there in 4.5.8.

packages\ServiceStack.Razor.4.5.13\lib\net45

That’s how it’s meant to be, from ServiceStack.Razor v4.5.0+ ServiceStack.Razor is referencing the official Microsoft.AspNet.Razor NuGet package instead of embedding it’s own System.Web.Razor.dll.

Yeah, 4.5.8 is working. I guess I’ll keep using it.

I update to 4.5.12 - when I start the app, the browser physically downloads the login.cshtml file.
I update to 4.5.13 - YSOD saying can’t find System.Web.Razor

Only difference when I do the upgrade is that in the csproj it’s removing the reference for System.Web.Razor:

<Reference Include="System.Web.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
  <HintPath>..\..\packages\ServiceStack.Razor.4.5.8\lib\net45\System.Web.Razor.dll</HintPath>
  <Private>True</Private>
</Reference>

Edit: Oddly when I start a new SS Razor Web App in VS, and upgrade to 4.5.13, it’s works. I guess I’ll go thru all of project files/configs and compare them.

Yeah, when upgrading, System.Web.Razor is being removed as a reference. I had to physically go back and add reference manually to it in \packages\Microsoft.AspNet.Razor.3.2.3\lib\net45

It’s working now. Any ideas why it would be removed when upgrading?

This still seems to be an issue with 4.5.13.

It removes the old config when uninstalling before adding a new one back when it’s installing, I think the cause of this issue was a bad upgrade when ServiceStack.Razor wasn’t published on MyGet. Can you try uninstalling ServiceStack.Razor and any Microsoft Razor packages and removing all Razor config from web.config, then manually add ServiceStack.Razor back?

Yep. That seems to have worked!

Back to the original issue though, when using the Gateway, ApiDocs.cshtml is not used. If I change the name to MyAccountCategories.cshtml, it works.

Not a big issue - I’m wrapping the responsedto in http result and specifying the view so it is working, but thought I’d mention it.

This should be resolved in the latest v4.5.13 on MyGet as you had an existing v4.5.13 installed you’ll need to clear your NuGet cache to download the latest v4.5.13: http://docs.servicestack.net/myget#redownloading-myget-packages

Ok that did it. Thanks for the help.

1 Like