locked
Could not load type... in strongly typed view RRS feed

  • Question

  • User-1424919406 posted

    Hello, I just started to play around with MVC and today I tried to create a strongly typed view using RC1.

    Though, first of all I didn't received any intellisence as I expected (and read about) and when I try to run it I get this error:

    Could not load type 'System.Web.Mvc.ViewPage<MyMvcProject.Models.MyObject>'.

    The first line was automatic added through the "add View wizard" in RC1 (no code behind files which I like a lot)

    Line 1: <%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<MyMvcProject.Models.MyObject>" %

     I'm sure there's a very "stupid" thing that I'm overlooking, but it might help (and go faster) is someone can point me out here.
    I assume it has something to do with the <> syntax for generics, but I read everywhere this should work in RC1. (It didn't work either with '1[ ] )

    I also found out that RC1 does NOT install the System.Web.Mvc reference in the GAC (error in the msi?)

    Thanks for any help

    Saturday, January 31, 2009 1:31 PM

All replies

  • User-693970323 posted

     I have the same problem, but I tryed to update MVC Beta to MVC RC1.

    After the upgrade - all is fine, but when I create strongly typed page (by one page with no cede behind)  i get this error:

     Cannot Load Type 'System.Web.Mvc.ViewPage<ConceptStyle.Models.CcsAuto.Field>'.

    Line 1:  <%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<ConceptStyle.Models.CcsAuto.Field>" %>
    I've tryed to place a simple types like List<int>, but this doesn't work too. 
    I created a new MVC application - all works fine. Compared web.configs - all posible issues is the same. 
    What is wrong?

    Saturday, January 31, 2009 2:01 PM
  • User-1424919406 posted

    So you're saying that it does work by creating a complete new application from scratch using RC?
    I can try that (I also updated from beta to RC). I'm still playing around and haven't written much essentials in the web application. Though it would be nice to know what has to be done to upgrade correctly.

    Saturday, January 31, 2009 2:45 PM
  • User287763314 posted

    Hello guys.

     

    1. the dlls are installed in gac. If you're not seeing System.Web.Mvc there then something went wrong with the installation. Try removing it and installing it again

    2. I've been using the new view syntax without any problems. It seems like you're not using the correct MVC assemblies. Have youtried removing the references and adding them again?

    final note: you can stop using the namespace on the < > if you add an Imports directive to the page:

    <%@ Import Namespace="MVCRC.Models"%>

    ANd then you can simply put: Inherits="System.Web.Mvc.ViewPage<DumbData>"

    Saturday, January 31, 2009 2:48 PM
  • User-1424919406 posted

    Well, I tried a lot of things without success. The only thing that worked perfectly, is when you create a complete new mvc project from scratch. Then you can do everything, but upgrading from beta didn't worked for me.

    I guess it does have to do something with the GAC and VS that not seems to work correctly. These are the steps I went through without success.

    1) uninstall ASP.NET MVC through control panel
    2) check with gacutil if all dll's are gone from the gac (System.Web.Abstractions and System.Web.Routing where still in there)
    3) tried to manually remove them from the GAC --> failed because they where "in use by an installer"
    4) reboot pc (didn't fixed the lock)
    5) went through this article (removing from the registery so I could uninstall them from GAC manually)
    http://dylanbeattie.blogspot.com/2008/11/working-on-aspnet-mvc-beta-and-preview.html (Now this is unknown territory for me, but since i don't have a wife or cat and I can always buy a new pc I thought I'd give it a try. I did only remove the first key though)
    6) install mvc rc again through the msi (checked with gacutil, all dll's are there again)
    7) opened my solution and removed all mvc references from my project
    8) try to add references again with "add reference" --> NO System.Web.Mvc listed
    9) add manually mvc dll's by browsing to the folder (program files/microsoft asp.net/asp.net mvc rc/assemblies)
    10) run it with no success at all
    11) create a complete new mvc application from scratch
    12) create a quick strong typed view, received the promised intellisence
    13) run with success....

    In my case it's ok. I just need an extra hour or so to add the few classes to a new project, but still I'd like to know (to satisfy my own curiosity) how to convert a beta to rc. It has to be possible. I am running it under Vista Ultimate sp1. Don't think it should do anything.

    Saturday, January 31, 2009 4:05 PM
  • User287763314 posted

    Hello again.

    I've installed MVC RC on another machine and i can confirm that it is on the gac and listed on the add reference dialog. if it's not there, then something has gone wrong. btw, do keep in mind that being in the gac is not enough for being shown on the add reference dialog:

     http://www.csharp411.com/adding-assemblies-to-the-visual-studio-add-reference-dialog/

    Having said that, I'm not sure on why you're not seeing the assembly on that dialog...

    Saturday, January 31, 2009 4:55 PM
  • User-693970323 posted

    Absolutely the same thing. I don't see an assembly in reference .NET menu. I've tryed to add manually from (program files/microsoft asp.net/asp.net mvc rc/assemblies), tryed to set copy local or get from gac, tryed to delete all the old assemblies. Tryed to copy them manually and add from \bin. Works only on new project.

    I can copy classes to a new project, etc... But what is wrong? I can't understand. Why doesn't it  work when I copy assemlies and set them manually?

     

    Saturday, January 31, 2009 5:15 PM
  • User-693970323 posted

     Doesn't work after the project migration. Something breaks it... Can't find out what.

    Saturday, January 31, 2009 9:53 PM
  • User1399601127 posted

    Create a brand new Asp.net MVC Application, copy ~/Views/Web.config to override the one of your existing project.

    If it's still not working, do the same for ~/Web.config (and of course merge the changes you've made).

    I've met the problem because some of these places references the GAC version of System.Web.Mvc assembly, and my code references my custom build of the released source code.

    Sunday, February 1, 2009 9:50 AM
  • User287763314 posted

    Yep, had forgotten about the web.config on the Views folder. That one must point to the correct version too...

    Sunday, February 1, 2009 10:32 AM
  • User-1660770209 posted

    I was having very similar problems. Changing out the web.config file under ~/Views/ helped out a bit. I can now run the site with the views working correctly.

    Unfortunately, I'm now experiencing a crashing problem from within VisualStudio when opening the view for editing. The entire IDE process simply goes away. Upon restart and reopening of the solution file, I am told that the documents caused the crash and are thus not being opened this time by default. Still, this doesn't help me.

    Interestingly, even within a non-strongly-typed view page, VS can't resolve the Html helpers. Specifically, Html and Request can't be found.

    Finally, I too don't see System.Web.Mvc in my Add References dialog. Something is clearly amiss. I've tried reinstalling several times, new web.config files, etc. I think there's some obvious sort of problem with VS and MVC now. At least the site runs correctly though.

    Can we get any official word on this? Is there a manual process to fix VS integration and ensure System.Web.Mvc shows up in the Gac?

    Sunday, February 1, 2009 11:16 AM
  • User-1660770209 posted

    To anyone having crashing issues, try disabling any VS plugins you may have installed. There was a thread on StackOverflow1 about this same issue. I had to disable my Huagati DBML/EDMX Tools add-in and others disabled TestDriven.net and Gallio.

     1) http://stackoverflow.com/questions/500696/why-does-visual-studio-crash-opening-aspx-with-mvc-rc1/

    Sunday, February 1, 2009 2:26 PM
  • User-1424919406 posted

    Well, I kind off solved it.

    Thanks deerchao for the web.config tip. I forgot to look at the views config file as well. The new project contained a little more data like this:

        <pages 
            validateRequest="false"
            pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
            pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
            userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
          <controls>
            <add assembly="System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" />
          </controls>      
        </pages>

    As you can see, the pages item has now a couple more attributes linked to types. After copy/past this in my old project, the page got loaded.

    But then I got the same problem as Nairb was mentioning. When trying to open the view in the IDE, it just shuts down.
    I "solved" this by uninstalling the "Visual Studio 2008 PowerCommands" plug in.
    So besides loosing this plug-in, the project runs again.

    Few more notes...
    A new created project with RC1 works perfect with the PowerCommands plug in
    I still don't see the System.Web.Mvc reference in the "Add Reference" dialog altough it is installed in the GAC (gacutil)  

    Monday, February 2, 2009 4:06 AM
  • User1500441438 posted
    I have a problem with "Add View" wizard too (MVC RC1). But it is related to type resolution.

    I have Common.dll which contains interfaces for my domain model (for example, IEntity). Domain.dll references Common.dll and contains actual business entities (like Customer : IEntity).

    MVC project references both of these assemblies so they are located in \Bin folder.

    When I try to add a strongly typed view for Customer I get the following exception:

    ---------------------------
    Template Processing resulted in 1 Errors
    ---------------------------
    C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates\CSharp\Web\MVC\CodeTemplates\AddView\List.tt(-1,-1) : error : An Exception was thrown while running the transformation code. The process cannot continue.  The following Exception was thrown:

    System.TypeLoadException: Could not load type 'Common.Domain.IEntity' from assembly 'DomainModel, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.



    Server stack trace:

       at System.Reflection.Assembly._GetType(String name, Boolean throwOnError, Boolean ignoreCase)

       at System.UnitySerializationHolder.GetRealObject(StreamingContext context)

       at System.Runtime.Serialization.ObjectManager.ResolveObjectReference(ObjectHolder holder)

       at System.Runtime.Serialization.ObjectManager.DoFixups()

       at System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler handler, __BinaryParser serParser, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)

       at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream, HeaderHandler handler, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)

       at System.Runtime.Remoting.Channels.CrossAppDomainSerializer.DeserializeObject(MemoryStream stm)

       at System.Runtime.Remoting.Channels.CrossAppDomainSerializer.DeserializeMessageParts(MemoryStream stm)

       at System.Runtime.Remoting.Messaging.SmuggledMethodCallMessage.FixupForNewAppDomain()

       at System.Runtime.Remoting.Channels.CrossAppDomainSink.DoDispatch(Byte[] reqStmBuff, SmuggledMethodCallMessage smuggledMcm, SmuggledMethodReturnMessage& smuggledMrm)

       at System.Runtime.Remoting.Channels.CrossAppDomainSink.DoTransitionDispatchCallback(Object[] args)



    Exception rethrown at [0]:

       at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)

       at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)

       at Microsoft.VisualStudio.TextTemplating.TransformationRunner.RunTransformation(String fullClassName, String baseClassName, String[] importedNamespaces, String[] references, String source, String inputFile, Boolean debug, SupportedLanguages language, IDictionary`2 languageOptions, IFormatProvider format, ITextTemplatingEngineHost host, Boolean cacheAssemblies, String& result)

       at Microsoft.VisualStudio.TextTemplating.Engine.CompileAndRunCode(String generatorCode, ITextTemplatingEngineHost host, TemplateProcessingSession session)

    Tuesday, February 3, 2009 12:56 PM
  • User1500441438 posted

     Oh, I've found the answer. It's a bug (http://stackoverflow.com/questions/492671/problem-using-add-view-dialog-in-asp-net-mvc-rc1-for-strongly-typed-view).

    Tuesday, February 3, 2009 1:44 PM
  • User-923369995 posted

    littlefool >> your comment on the web.config in the View folder did it for me. Thanx!

    Friday, March 13, 2009 4:14 AM
  • User-352287631 posted

    Thanks for the link to the fix. VS has been crashing every time I opened a .aspx file since I moved from MVC Beta to RC1

    Thursday, April 9, 2009 11:10 AM
  • User-434868552 posted

    Just curious Stephen:  Is there some reason you are avoiding the final version:  ASP.NET MVC v1.0 (a.k.a. RTM)
    which also has as a bonus its being officially supported by Microsoft?

    You can get to it via this link http://www.asp.net/mvc/.

    gerry

    Thursday, April 9, 2009 12:38 PM
  • User-352287631 posted

    It is the RTM version that screws up VS, the Beta versions were fine!

    Friday, April 10, 2009 5:54 AM
  • User-434868552 posted

    Stephen, does this happen on other computers?

    I had a problem that occurred version after version.
    I falsely assumed, since the whatever version still had the same bug
    that Microsoft had failed to fix, that is was not even being tested.
    A member in Japan also had that bug.  Since the bug was so easy to demonstrate,
    I falsely assumed that Microsoft was not testing properly.

    I was wrong.  Phil Haack could not reproduce the bug
    and other members of this forum who tried at my request
    also could not reproduce it.  I'm not saying that it was not
    a bug because it was.  Unfortunately, it was a random bug
    that does not affect everybody and is therefore difficult to exterminate.

    Once I realized that this was a random bug, I used the free
    VMware Server 2 to build a clean virtual version of Windows XP Pro SP3
    inside of my Windows 2003 and applied every Windows Update to the
    fresh, virtual XP Pro platform.

    Next, I did a clean install of VS 2008 Pro, updated it to VS SP1,
    installed the then current version of ASP.NET MVC, and repeated
    my test.  The random bug did not reoccur.

    That's why I'm asking whether this happens on other computers
    to your knowledge.  I strongly feel that everyone needs to get on
    the final version:  ASP.NET MVC v1.0 (a.k.a. RTM) as the best
    practice.  It's better unless someone is holding a gun to your head
    (figuratively) to transition now because Microsoft's only version of
    ASP.NET MVC that is officially supported is v1.0 and also
    because all future development by Microsoft and likely by most
    third party developers with be on v1.0 as a starting point.

    Regards,
    Gerry (Lowry)

    Friday, April 10, 2009 8:17 AM
  • User-619855079 posted

    Create a brand new Asp.net MVC Application, copy ~/Views/Web.config to override the one of your existing project.

    If it's still not working, do the same for ~/Web.config (and of course merge the changes you've made).

    I've met the problem because some of these places references the GAC version of System.Web.Mvc assembly, and my code references my custom build of the released source code.

    LMAO, THANK YOU!!! I would have wasted hours until I figured this out on my own...

    Wednesday, January 27, 2010 2:23 PM