sjh37 / EntityFramework-Reverse-POCO-Code-First-Generator

EntityFramework Reverse POCO Code First Generator - Beautifully generated code that is fully customisable. This generator creates code as if you reverse engineered a database and lovingly created the code by hand. It is free to academics (you need a .edu or a .ac email address), not free for commercial use. Obtain your licence from
https://www.reversepoco.co.uk/
Other
700 stars 230 forks source link

'Microsoft.VisualStudio.CommonIDE.Solutions.Dte.DteProjects' in Assembly is not marked as serializable #755

Closed marhyno closed 2 years ago

marhyno commented 2 years ago

I suddenly have this error on this line in EF.Reverse.POCO.Core. This leads to not able to fetch changes from DB when I save the template.

I have Visual Studio 2022 Version 17.2.1 Poco version v2.37.1

image

Severity    Code    Description Project File    Line    Suppression State
Error       Running transformation: System.Runtime.Serialization.SerializationException: Type 'Microsoft.VisualStudio.CommonIDE.Solutions.Dte.DteProjects' in Assembly 'Microsoft.VisualStudio.CommonIDE, Version=17.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' is not marked as serializable.

Server stack trace: 
   at System.Runtime.Serialization.FormatterServices.InternalGetSerializableMembers(RuntimeType type)
   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.get_Projects()
   at Microsoft.VisualStudio.TextTemplatingAD1F76D243D696A22C1CF6CAA6A34950D7CC971A187F75F10ACF46B602E02DD854F94A360931DA4DE07A2A2E33F90A726F5C4EC36CBFF900157C05E4E0D8FBD5.GeneratedTextTransformation.<GetAllProjects>d__29.MoveNext() in C:\_WA\BifItaly\Source\Crif.BIF.IT.Common\Model\PCT\..\EF.Reverse.POCO.Core.ttinclude:line 419
   at Microsoft.VisualStudio.TextTemplatingAD1F76D243D696A22C1CF6CAA6A34950D7CC971A187F75F10ACF46B602E02DD854F94A360931DA4DE07A2A2E33F90A726F5C4EC36CBFF900157C05E4E0D8FBD5.GeneratedTextTransformation.GetConfigPaths() in C:\_WA\BifItaly\Source\Crif.BIF.IT.Common\Model\PCT\..\EF.Reverse.POCO.Core.ttinclude:line 510
   at Microsoft.VisualStudio.TextTemplatingAD1F76D243D696A22C1CF6CAA6A34950D7CC971A187F75F10ACF46B602E02DD854F94A360931DA4DE07A2A2E33F90A726F5C4EC36CBFF900157C05E4E0D8FBD5.GeneratedTextTransformation.GetConnectionString(String& connectionStringName, String& providerName, String& configFilePath) in C:\_WA\BifItaly\Source\Crif.BIF.IT.Common\Model\PCT\..\EF.Reverse.POCO.Core.ttinclude:line 300
   at Microsoft.VisualStudio.TextTemplatingAD1F76D243D696A22C1CF6CAA6A34950D7CC971A187F75F10ACF46B602E02DD854F94A360931DA4DE07A2A2E33F90A726F5C4EC36CBFF900157C05E4E0D8FBD5.GeneratedTextTransformation.InitConnectionString() in C:\_WA\BifItaly\Source\Crif.BIF.IT.Common\Model\PCT\..\EF.Reverse.POCO.Core.ttinclude:line 333
   at Microsoft.VisualStudio.TextTemplatingAD1F76D243D696A22C1CF6CAA6A34950D7CC971A187F75F10ACF46B602E02DD854F94A360931DA4DE07A2A2E33F90A726F5C4EC36CBFF900157C05E4E0D8FBD5.GeneratedTextTransformation.GetDbProviderFactory() in C:\_WA\BifItaly\Source\Crif.BIF.IT.Common\Model\PCT\..\EF.Reverse.POCO.Core.ttinclude:line 635
   at Microsoft.VisualStudio.TextTemplatingAD1F76D243D696A22C1CF6CAA6A34950D7CC971A187F75F10ACF46B602E02DD854F94A360931DA4DE07A2A2E33F90A726F5C4EC36CBFF900157C05E4E0D8FBD5.GeneratedTextTransformation.TransformText() in C:\_WA\BifItaly\Source\Crif.BIF.IT.Common\Model\PCT\pctTemplate.tt:line 12       C:\_WA\BifItaly\Source\Crif.BIF.IT.Common\Model\PCT\..\EF.Reverse.POCO.Core.ttinclude   419 
sjh37 commented 2 years ago

Version 2 does not support .Net Core. Version 3 supports .Net Core. If you use v3 commercially, you will need a licence for it which is available at www.reversepoco.co.uk

erwin-faceit commented 2 years ago

Same for me.

I'm running a .NET Framework 4.7 project with Poco version 2.37.2, and got the same exception after updating Visual Studio 2022 to 17.2.3.

So no .NET Core here, that doesn't seem to be the issue here.

sjh37 commented 2 years ago

Could you try v3 and see if you still get the error. You won't need a licence for the test. I am wondering if this is already fixed.

TheRancid commented 2 years ago

Hi, I see that the issue is marked as closed, but didn't find any solution.

Anyway, same problem here, we are using v2.17.2 of the template under Visual Studio 17.2.2 (I can try to update, but I see that another user is reporting the same issue nonetheless), while the same template works flawlessly under Visual Studio 2019 16.11.10.

Let me know if any solution has already been found (aside from updating to v3 of the template, we are using the template on legacy 4.7.2 Framework code that we are planning to migrate to NET Core + EF Core code-first) or if I can be of any help.

Thanks in advance. Best regards

sjh37 commented 2 years ago

I created a .Net framework 4.7.2 class library using Visual Studio 2022 (64 bit) 17.2.3. Added in the generator v3.6.0 and played around with filtering to add and remove generated files. All worked perfectly without the serialisation error you are seeing.

Version 3 supports both EF6 and EFCore

Open the solution below, edit test.tt line 19 to point to your database and press save and let me know how you get on.

Legacy EFRPG 472.zip

TheRancid commented 2 years ago

Hi Simon, thanks for your prompt response.

I've changed the connection string to my database and was able to execute the generation without the serialization error.

However, many stored procedures weren't generated because of "cannot be created due to having out parameters, or is relying on the procedure result (int)" errors, while with version 2.x they could be generated (maybe that's a limitation of the trial version?).

sjh37 commented 2 years ago

Hi Pier, The only limitation on the trial is the number of tables and stored procs generated. V2 and V3 should be the same in that respect with regard to generating stored procedures (or not) due to entity framework limitations.

sjh37 commented 2 years ago

@TheRancid Attached is a 7 day trial so you can check out how v3 works for you. @marhyno you use it too, see if it resolves your issue.

ReversePOCO.txt Place this file in the root of your Documents folder: %userprofile%\documents Name this file ReversePOCO.txt

TheRancid commented 2 years ago

Hi Simon, the license file worked flawlessly and I've been able to generate every object in the database.

The problem I had encountered was just that the trial template didn't generate both the sync and async versions of the ProcUsersChangeStatus stored procedure, but the first wasn't generated for trial limitations and not for a bug: with the license file the sync version was being generated correctly, so that solves the problem.

Still, I don't understand why the older template works ok in VS2019, while it does not in VS2022... Let me know if you'd like to do more testing with that.

Anyway, thanks for your support so far: I see that you're suggesting to move to version 3.x (and rightly so), but as of know we won't probably update, as we've planned to upgrade the framework and switch to EFCore + scaffolding in the near future. In any case I have to say that this is an amazing project with a definitely higher level of customization!

Best regards

sjh37 commented 2 years ago

Great to hear that version 3 works well for you Pier. I won't be fixing version 2 so will leave this case closed.