Attempting to add a strongly typed view does not find any classes in the MVC project

后端 未结 5 742
难免孤独
难免孤独 2021-02-08 06:44

I have a very odd problem. Whenever I try to use the \"Add View\" dialog in ASP.NET MVC2 and then try to \"Create a strongly-typed view\" by selecting a \"View data class\" from

5条回答
  •  花落未央
    2021-02-08 07:12

    Figured this out, here is the solution:

    The MVC Project was referencing a bunch of service contract assemblies that where referencing a "CommonServiceContractAssembly.dll". The MVC Project was also referencing "CommonServiceContractAssembly.dll". The MVC Project and the service contract assemblies were all built referencing slightly different versions of "CommonServiceContractAssembly.dll"

    When Visual Studio 2010 was reflecting on all referenced assemblies to "Create a strongly-typed view" of I believe it wasn't sure how to handle the slightly different version of "CommonServiceContractAssembly.dll" being referenced so it didn't display the reflected "strongly typed model" possibilities for any assemblies dependent on "CommonServiceContractAssembly.dll".

    The fix is to actually force Visual Studio 2010's app domain to use the correct version of "CommonServiceContractAssembly.dll" when Visual Studio 2010 starts up. This was accomplished with a Post Build Event like the following:

    REM This is required for T4 generation from models to work properly copy "$(TargetDir)"CommonServiceContractAssembly.dll" "$(DevEnvDir)PublicAssemblies\" /Y

    So I copy "CommonServiceContractAssembly.dll" that is referenced "everywhere" into where Visual Studio will load it. After I did this everything worked properly.

    Another option would be to always ensure that all assemblies that share a common dependency are always compiled with the same version of that dependency.

提交回复
热议问题