Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running EF 6.x DbContext Generator in a .NET Standard 2.1 project fails #1384

Closed
NetherGranite opened this issue Oct 15, 2019 · 7 comments
Closed
Assignees

Comments

@NetherGranite
Copy link

When 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

  1. Open Visual Studio's EF model designer by double-clicking an .edmx file in a .NET Framework project within Visual Studio 2019.
  2. Right-click anywhere in the diagram and select "Add Code Generation Item".
  3. Select the EF 6.x DbContext Generator, and name the file Generator.tt.
    Copy the resulting Generator.tt and Generator.Context.tt files into a .NET Standard 2.1 project.
  4. 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

@ajcvickers
Copy link
Member

@lajones Can you investigate this please. The issue may be that T4 templates don't work in .NET Standard 2.1 projects.

@jaccil
Copy link

jaccil commented Nov 7, 2019

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

@ajcvickers
Copy link
Member

Ping @lajones

@lajones
Copy link
Contributor

lajones commented Nov 22, 2019

We have an internal bug on this: Feedback Item 972704. It's been transferred to the T4 team, but I haven't seen any movement on it for a while. I've pinged them again...

@lajones
Copy link
Contributor

lajones commented Mar 19, 2020

@bricelam Apart from the internal bug above, isn't this also covered by #883?

@NetherGranite
Copy link
Author

Any updates on this?

@ajcvickers
Copy link
Member

This issue has been closed because EF6 is no longer being actively developed. We are instead focusing on stability of the codebase, which means we will only make changes to address security issues. See the repo README for more information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants