1

I refactored my MVC/Entity Framework projects by separating namespaces into separate projects. So I now have this structure:

MySolution.Data
MySolution.Data.Contracts
MySolution.Model
MySolution.Website

Everything builds and runs in my development environment. However I hit problems when I tried to deploy to my "Staging" server.

The problem I have is that it would not build when I changed the solution configuration to "Staging". In the configuration manager all the projects also have "Staging" configurations. I assume these were created when the new projects were added.

The first thing I tried was to create a new solution configuration with everything copied from Debug named "Solution 2". No luck, still fails.

Then I figured that I only need a different configuration for the Website project - where I transform the configuration file. So I changed the solution configuration, telling it to build and deploy the "Debug" configuration of Hub.Model - which from the first error message looked like the problem project. Sure enough it now builds.

The first error message (of 263) is:

The type or namespace name 'Schema' does not exist in the namespace 'System.ComponentModel.DataAnnotations' (are you missing an assembly reference?) MySolution.Model

So it looks like a problem with references to Entity Framework dlls

While I do have a workaround for now, I am concerned that this unexplained error will come back and bite me at some point in the future - probably just when I am about to deploy an urgent fix.

So why would one of my projects fail to build when I change project configuration?

Colin
  • 22,328
  • 17
  • 103
  • 197
  • hmm it does sound peculiar. Are all of the 263 errors relating to namespaces not existing? – Luke May 28 '15 at 10:07
  • @Coulton it certainly looked like that was the root cause. Baffled as to why it would build in one configuration but not another. Anyway, I have continued on my journey - which is an upgrade from MVC 4 to MVC 5. So I upgraded a number of packages since I posted the question, and I removed MVC altogether from my Models project. Now it builds, whatever the configuration, so probably going to be OK. Thanks – Colin May 28 '15 at 12:57
  • Great to hear, all the best! – Luke May 28 '15 at 12:58

1 Answers1

1

You need to make sure you are installing proper nuget packages and referencing all assemblies.

The solution of the error you have shown is as below: (Reference)

You have to reference the assembly in which this namespace is defined (it is not referenced by default in the visual studio templates). Open your reference manager and add a reference to the System.ComponentModel.DataAnnotations assembly (Solution explorer -> Add reference -> Select .Net tab -> select System.ComponentModel.DataAnnotations from the list). Then select that reference and under properties set "copy local" to true and once you publish it will be in your bin folder and wont impact at all on any server be it x32 or x64.

Happy coding :)

Community
  • 1
  • 1
NewDirection
  • 116
  • 10
  • The question isn't just why one of my projects fails to build - because, actually, it doesn't!. The question is why does it fail when I change project configuration? Anyways, I have subsequently upgraded to ASP.NET 4.6 and during that process I have removed packages and re-installed others, and now the problem has gone away. So I will accept your answer! Glitches in Visual Studio I suspect... – Colin May 28 '15 at 13:16
  • ok good, actually before ASP.NET version 4.5 , such issues happen now hope you will not get such again after changing your project configurations or after publishing. – NewDirection May 28 '15 at 13:41