0

enter image description hereI want to create model: add > class > ado.net entity, for my db first project and also want to create CRUD operation by asp.netscaffolding, but failed to create a model with necessary code.and thus i failed to create scaffolding . in my model file AllahHelp.Context.cs, there is no code, only the text "ErrorGeneratingOutput".

Error 1:

A namespace cannot directly contain members such as fields or methods F:\project\WebApplication8\WebApplication8\Models\AllahHelp.Context.cs 1 1 WebApplication8

Error 2:

Compiling transformation: Metadata file 'C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\Tools..\IDE\EntityFramework.dll' could not be found F:\project\WebApplication8\WebApplication8\Models\AllahHelp.tt 1 1 WebApplication8

2 Answers2

2

If there is an error transforming your .tt files into class files, your class files will just have "ErrorGeneratingOutput" in the source file, which causes a "namespace cannot directly contain members such as fields" error, but doesn't really have anything to do with that.

Your actual error sounds like you're missing a reference to EntityFramework.dll. Right click the project, choose "Manage NuGet Packages..." and find and install EntityFramework to your project.

In some situations I've also run into a problem where since the transformation occurs before files are copied, referenced dlls don't ever get copied since the error occurs and stops the process. In this case you would need to remove the model from your project temporarily, successfully compile the project, and then add the model back.

According to this similar question it could also be because of your install path. If that is your issue, try to find where the dll is, and correct the environment variable VS120COMNTOOLS (Control Panel -> System -> Advanced System Settings -> Environment Variables -> System Variables)

(Be careful changing system variables, though.)

Community
  • 1
  • 1
Dave Cousineau
  • 12,154
  • 8
  • 64
  • 80
  • thanks sahuagin. i have already installed entity framework.but same problem. – Engr Muhammad Enayet Abdullah Sep 24 '16 at 07:56
  • @EngrMuhammadEnayetAbdullah well, somehow or other, VS is failing to find `EntityFramework.dll`. According to [this similar question](http://stackoverflow.com/questions/19664833/metadata-file-not-found-data-entity-model) it can be because of your install path. If that is your issue, try to find where the dll is, and correct the environment variable VS120COMNTOOLS (control panel -> system -> advanced system settings -> environment variables -> system variables) – Dave Cousineau Sep 24 '16 at 19:02
  • Closing and restarting Visual Studio Fixed my problem – DarioN1 Aug 21 '18 at 17:32
0

I was getting this error when attempting to build a project using .tt templates. I fixed the issue by checking everywhere that I used C# code injection and making sure that I closed each section of C# code by including #>.

Example:

Problematic code:

{
          "find": "__LOCATION__",
          "replaceWith": "<#= deployment.Location"
},

Fixed code:

{
          "find": "__LOCATION__",
          "replaceWith": "<#= deployment.Location #>"
},
Ethan Seal
  • 31
  • 8