Getting HttpCompileException in Razor ServiceStack View (Self-Service)

ASSEMBLY 1

This is my project structure (I serve content from embedded resources):

Common_Assembly.dll Css Common.css Views Shared _Layout.cshtml 

It also has a class called Model.cs, which is essentially true:

 public class Model { public string Title {get; set; } } 

_Layout.cshtml

 @model MyNameSpace.Model <html> <head> <script language="javascript" href="css/common.css"></script> <title>@Model.Title</title> </head> <body> @RenderBody </body> </html> 

ASSEMBLY 2

Then I have a second assembly (which refers to the above) and is the one that actually hosts the web service:

 Concrete_Assembly.dll Views Index.cshtml 

This class has an IndexResponse class, which derives from Model in another assembly.

 public class IndexResponse : Model { } 

Index.cshtml

 @Model MyOtherNameSpace.IndexResponse <p>Test</p> 

Now the problem. If I delete the @Model line, everything works correctly, and I see my index page on the layout page of another DLL ( I use a custom VirtualPathProvider to search for resources in several Dlls ). However, if I try to use IndexResponse as a model on the index page, I get an HttpCompileException . Since it is thrown by an external component, I don’t really know what the exception message is (I use the service stack binaries).

At first I wondered if it was because the model class was different from the layout class (although it stems from it). To test this theory, I created the TestModel class obtained from Model (placed in the general assembly) and used this - it worked fine.

This makes me think that this is because IndexResponse is in the secondary assembly, but cannot be sure, because I do not see the error.

Any help would be appreciated!

EDIT

For completeness, here is the actual WebService method. I don’t think that something is wrong here because it worked fine when I did other tests (using TestModel instead).

  public IndexResponse Any(Index index) { return new IndexResponse() { Title = "Test Title" }; } // eo Any 

EDIT 2

Sorry for all the changes. Also, is there anyway I can get this exception or handle it so that I can look at the error? It would be nice to catch this and display it - otherwise the development of these pages, since the embedded resources will be similar to pulling your teeth :)

EDIT 3

After fulfilling some suggestions from Mythz and adding the correct namespaces to the Razornamespace configuration, I finally grabbed onto the error that it was throwing:

+ $exception {"(0): error CS1704: An assembly with the same simple name 'Concrete_Assembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null has already been imported. Try removing one of the references or sign them to enable side-by-side."} System.Exception {System.Web.HttpCompileException} `

+2
source share
1 answer

If you have not added any assemblies you are using to your app.config , for example:

 <system.web.webPages.razor> <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> <pages pageBaseType="ServiceStack.Razor.ViewPage"> <namespaces> <add namespace="ServiceStack.Html" /> <add namespace="ServiceStack.Razor" /> <add namespace="ServiceStack.Text" /> <add namespace="ServiceStack.OrmLite" /> <add namespace="Concrete_Assembly" /> <add namespace="Common_Assembly" /> </namespaces> </pages> </system.web.webPages.razor> 

Also disable ASP.NET web pages:

 <appSettings> <add key="webPages:Enabled" value="false" /> </appSettings> 

Refer to the RazorRockstars Self Host app.config for help.

+1
source

Source: https://habr.com/ru/post/950875/


All Articles