Question

I am trying to extend the default webrole template. I have added a new entity model and created a skeleton framework for it. When the loading of the index page is attempted, a server error is displayed.

"The type 'Microsoft.WindowsAzure.ServiceRuntime.RoleEntryPoint' is defined in an assembly that is not referenced. You must add a reference to assembly 'Microsoft.WindowsAzure.ServiceRuntime, Version=2.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'."

I have double checked that the WebRole includes this reference and it does. I can fix this error by setting this reference Copy Local property to true.

If I do this, the error changes to "The type name 'Models' does not exist in the type 'WebRole.WebRole'"

Both errors are thrown from the Index.cshtml file, specificially on the line:

public class _Page_Views_BankAccount_Index_cshtml : System.Web.Mvc.WebViewPage<IEnumerable<WebRole.Models.BankAccount>> {

What is causing this?

Was it helpful?

Solution

You are missing references in your view compilation.

The view compiler uses a different set of references, and to make your model work you will need to add the references in your web.config

For example:

<configuration>
  <system.web>
    <assemblies>
      <add assembly="YourAssembly, Version=4.0.0.0, Culture=neutral, PublicKeyToken=TOKENKEY" />
    </assemblies>
  </system.web>
 </configuration>

OTHER TIPS

I know it's old but might help anyone else.

This error occurs due to a conflict in the default project for Windows Azure Cloud Service when the web project is created with the name WebRole (Which puts the project in the same namespace as the Microsoft.WindowsAzure.ServiceRuntime dll). To fix there are two easy options:

replace this code

@model WebRole.Models.RegisterViewModel

and add the using statement and your model without the namesapce

@using WebRole.Models
@model RegisterViewModel

Or instead one can add a namespace in the web.config inside the views folder (not the one in the root)

<pages pageBaseType="System.Web.Mvc.WebViewPage">
   <namespaces>
       -----
      <add namespace="WebRole.Models" />
   </namespaces>
</pages>

And on your views just replace the existing code with

@model RegisterViewModel

Hope it helps.

Do you have the correct version of Azure Tools installed? I know for me, I only get this error when I'm missing the Azure Tools library.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top