Running EF 6.x DbContext Generator in a .NET Standard 2.1 project fails
See original GitHub issueWhen I run the ____.Context.tt
file generated from the EF 6.x DbContext Generator in a project that targets .NET Standard 2.1, it fails with the following exception and stack trace.
Exception message:
Running transformation: System.Runtime.Serialization.SerializationException: Type 'Microsoft.VisualStudio.ProjectSystem.VS.Implementation.Package.Automation.OAProjectItem' in Assembly 'Microsoft.VisualStudio.ProjectSystem.VS.Implementation, Version=16.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' is not marked as serializable.
Stack trace:
at System.Runtime.Serialization.FormatterServices.InternalGetSerializableMembers(RuntimeType type)
at System.Runtime.Serialization.FormatterServices.<>c__DisplayClass9_0.<GetSerializableMembers>b__0(MemberHolder _)
at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
at System.Runtime.Serialization.FormatterServices.GetSerializableMembers(Type type, StreamingContext context)
at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitMemberInfo()
at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitSerialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter, SerializationBinder binder)
at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.Serialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter, SerializationBinder binder)
at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(Object graph, Header[] inHeaders, __BinaryWriter serWriter, Boolean fCheck)
at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph, Header[] headers, Boolean fCheck)
at System.Runtime.Remoting.Channels.CrossAppDomainSerializer.SerializeMessageParts(ArrayList argsToSerialize)
at System.Runtime.Remoting.Messaging.SmuggledMethodReturnMessage..ctor(IMethodReturnMessage mrm)
at System.Runtime.Remoting.Messaging.SmuggledMethodReturnMessage.SmuggleIfPossible(IMessage msg)
at System.Runtime.Remoting.Channels.CrossAppDomainSink.DoDispatch(Byte[] reqStmBuff, SmuggledMethodCallMessage smuggledMcm, SmuggledMethodReturnMessage& smuggledMrm)
at System.Runtime.Remoting.Channels.CrossAppDomainSink.DoTransitionDispatchCallback(Object[] args)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at EnvDTE._Solution.FindProjectItem(String FileName)
at Microsoft.VisualStudio.TextTemplatingA45BC353BC9A6E91693EE919ADDF54E15FB38670C2E99FD37E446B907DC7D4065460A497F165AB32ADD7A7F5153D8DBC67AB3331D4CE06B5CE6CEBA98C5DDFF8.GeneratedTextTransformation.EntityFrameworkTemplateFileManager.VsEntityFrameworkTemplateFileManager..ctor(Object textTemplating)
at Microsoft.VisualStudio.TextTemplatingA45BC353BC9A6E91693EE919ADDF54E15FB38670C2E99FD37E446B907DC7D4065460A497F165AB32ADD7A7F5153D8DBC67AB3331D4CE06B5CE6CEBA98C5DDFF8.GeneratedTextTransformation.EntityFrameworkTemplateFileManager.Create(Object textTransformation)
at Microsoft.VisualStudio.TextTemplatingA45BC353BC9A6E91693EE919ADDF54E15FB38670C2E99FD37E446B907DC7D4065460A497F165AB32ADD7A7F5153D8DBC67AB3331D4CE06B5CE6CEBA98C5DDFF8.GeneratedTextTransformation.TransformText() Project C:\Path\To\Project\Generator.tt 1
Steps to reproduce
- Open Visual Studio’s EF model designer by double-clicking an
.edmx
file in a .NET Framework project within Visual Studio 2019. - Right-click anywhere in the diagram and select “Add Code Generation Item”.
- Select the EF 6.x DbContext Generator, and name the file
Generator.tt
. Copy the resultingGenerator.tt
andGenerator.Context.tt
files into a .NET Standard 2.1 project. - Run the
Generator.Context.tt
file.
Further technical details
EF version: 6.3.0 Database Provider: EntityFramework.SqlServer Operating system: Windows 10) IDE: e.g. Visual Studio 2019 16.3.5
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (5 by maintainers)
Top Results From Across the Web
Can't add EF 6.4 migrations in a .Net Standard 2.1 project
NET 5 or a .NET Core project and you use EF6 in it, here is how to run the migrations from PowerShell :...
Read more >7.1 Entity Framework 6 Support
MySQL Connector/NET integrates support for Entity Framework 6 (EF6), which now includes support for cross-platform application deployment with the EF 6.4 ...
Read more >Upgrading to Entity Framework 6 - EF6
There are currently only EF 6.x DbContext Generator templates available for Visual Studio 2012 and 2013. Delete existing code-generation ...
Read more >'Entity Framework 5 or later is required for the current ...
There was an error running the selected code generator: 'Entity Framework 5 or later is required for the current operation but not available....
Read more >Please stop lying about .NET Standard 2.0 support!
This post is a bit of a rant about an issue I've been fighting against more and more recently: NuGet packages lying about...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@bricelam Apart from the internal bug above, isn’t this also covered by #883?
Hi,
The problem is actually when generating the template in a project with a new sdk-style project, even when the target is .NET Framework. The strange thing is that if you choose Debug T4 Template, it works! But not if you Run Custom Tool.
Can you please give this immediate attention? I see similar issues raised and closed on the MS Dev Community (#703422 - not enough info) and here in issue #231 , yet it is still a problem in 6.3.0.
Recreation is simple, creating an EF6.* model from DB in a project with the sdk format, then try to generate the template. I have attached an example. Edit: the data.Context.tt actually works fine in this example, but not the model template (data.tt).
Thanks. EFModelGen2.zip