This project is read-only.

Reference to custom type within view

Topics: Customizing Orchard, Troubleshooting, Writing modules
Feb 28, 2011 at 5:39 PM


I have created my own search module, which I loosely based on the Orchard search functionality. Instead of querying orchard I go to my own service to query and return a List<T>. The views and viewmodels are pretty much the same.

Within my search project I have a reference to a separate WCF service, I use this within my controller to populate the viewmodel.

However when displaying the view it needs a reference to T held in my List<T>. Even though in the view I have a using statement to the type. I get the error.

"The type or namespace name 'yyy' does not exist in the namespace 'xxx' (are you missing an assembly reference?)"

In the Orchard search they have a using statement in the page, which seems to work fine.

Is this a bug or am I missing something in my web.config or something else?

Feb 28, 2011 at 7:22 PM

Are you missing an assembly reference? :) In other words, did you reference the assembly from the csproj for your module?

Mar 1, 2011 at 9:33 AM

No I am not missing the assembly reference. I have a reference to it in my controller to populate the viewmodel.

Mar 1, 2011 at 2:43 PM

This happens sometimes at the development stage.

I guess you added your module project to the Orchard.sln solution and get the error when running from VS directly, without installing the module explicitely. Orchard copies the appropriate referenced assemblies when installing module. If there's no explicit installation (which is true at dev time), the main web site project lacks the referenced dll in /bin folder. The workaround is to add your reference directly to the Orchard.Web project.

This won't happen if you deploy your module as package and install it from Orchard admin UI though.

Hope it helps!

Mar 2, 2011 at 5:05 PM

Cool. Thanks for your help. I though of this after as well.

I ended up doing it a different way and loading the data into a viewmodel in my contoller, within my module project.

I then was able to pass through to my view, therefore without needing the references in my web project.

Jun 15, 2011 at 4:47 PM

Just wanted to post an update to this for anyone looking for something a little more manageable on the development side. 

I'm working on a custom module that has a similar implementation needing a model that's in an external library. Here's what I'm doing:

  • Using Orchard.Web package with run in browser
  • I used symbolic links from the command line (mklink)
  • created a directory symbolic link for my module (which is under source control) directory to Orchard.Web\Modules
  • created a normal symbolic link for each referenced assembly to Orchard\bin
  • attached to process in VS2010 that has my module project and other projects (which are under SVN) to the webserver for debugging

Obviously this is just for development, but it's making it much easier to work with (instead of copying and pasting code and dll's or creating module packages all the time)