Hopefully this will help somebody else.
In a new project which uses ASP.net MVC, VB , Entity framework and razor I kept getting the following when running the application and connecting to my controller..
BC30451: 'ViewData' is not declared. It may be inaccessible due to its protection level.
Various hits simply suggested that the protection level was wrong – i.e private not public etc.
The view is a strongly typed view using ModelType of an entity class found in a separate DLL i.e my Datalayer.
Non EF objects were fine.
Eventually I created some simple projects from scratch with the minimum amount of anything possible. One entity with one property , trivial controller etc.
Still no luck
Finally I tried creating a c# project which gave me a useful error message straight away along the lines of you need to reference System.Data.Entity …..
Adding <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> to the assemblies section of the web.config solved the problem for the c# project and back in my original VB project which now proceeds full steam ahead.
It seems reasonable now but the message should have been present for VB!
Thanks, I spent about half an hour trying to work out what the problem was, and it was very similar to yours (my Model was in an unreferenced namespace). The C# compiler actually tells you what the problem is. It seems very strange that the VB compiler doesn't pick that up in the first place. Maybe it has more than one error and only displays that less relevant one for some reason.
ReplyDelete