9

I'm using VS2010, and I've download the C# POCO Entity Generator and installed it, now I want to use it.

I can't read the toturial 1 and I can't find any other good toturials, so I've had a go myself - I have created a model and then I'm creating new POCO Entity, but I got the bellow error:

Error 1 Running transformation: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.IO.FileNotFoundException: Unable to locate file
   at Microsoft.VisualStudio.TextTemplating.VSHost.TextTemplatingService.ResolvePath(String path)
   at Microsoft.VisualStudio.TextTemplating.VSHost.TextTemplatingService.ResolvePath(String path)
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle._InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeType typeOwner)
   at System.RuntimeMethodHandle.InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeType typeOwner)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at Microsoft.VisualStudio.TextTemplatingA9DB2432A51EA8D42A615FBEB2ECB4E5.GeneratedTextTransformation.DynamicHost.ResolvePath(String path)
   at Microsoft.VisualStudio.TextTemplatingA9DB2432A51EA8D42A615FBEB2ECB4E5.GeneratedTextTransformation.MetadataLoader.TryCreateEdmItemCollection(String sourcePath, String[] referenceSchemas, EdmItemCollection& edmItemCollection)
   at Microsoft.VisualStudio.TextTemplatingA9DB2432A51EA8D42A615FBEB2ECB4E5.GeneratedTextTransformation.MetadataLoader.CreateEdmItemCollection(String sourcePath, String[] referenceSchemas)
   at Microsoft.VisualStudio.TextTemplatingA9DB2432A51EA8D42A615FBEB2ECB4E5.GeneratedTextTransformation.TransformText()
   at Microsoft.VisualStudio.TextTemplating.TransformationRunner.RunTransformation(TemplateProcessingSession session, String source, ITextTemplatingEngineHost host, String& result)

What is the problem? I think it can't find the model mapping, if this is the case, how do I resolve this?

1: due to internet restriction on my hometown.

Saeed Amiri
  • 22,252
  • 5
  • 45
  • 83

3 Answers3

11

Check this article for error description and how to deal with it. It is problem of path substitution when creating POCO template from Add item in Visual Studio.

Ladislav Mrnka
  • 360,892
  • 59
  • 660
  • 670
11

This error occurs when the path to the EDMX file is incorrect in the TT file. To resolve it, open the TT file, and replace the path manually with the relative path to the EDMX file.

For example, change this:

string inputFile = @"Db.edmx";

to something like this:

string inputFile = @"..\DataAccess\Db.edmx";
Tarzan
  • 4,270
  • 8
  • 50
  • 70
  • This is the bottom line from the article linked in the [currently accepted answer](http://stackoverflow.com/a/3906780/947171). This was exactly my problem. I had renamed the .edmx file, which renamed the designer and diagram, but did not update the internal file name in the T4. Manually modifying the T4 templates (both the Model and Context) to `const string inputFile = @".edmx";` fixed my problem. – Jon Peterson Feb 10 '16 at 15:38
0

as described in entityframeworktutorial, before POCO entities generation, please disable default code generation which generates Context and Entities code in Model1.designer.cs. To disable default code generation, right click on .edmx, select properties and then remove the value of ‘Custom Tool’ property value ‘EntityModelCodeGenerator’. Now right click on designer surface, select "Add Code Generation Item.." and continue as you did before

Oleg
  • 1