4

I thought this problem was fixed. I'm using Visual Studio 2013 and it is Entity Framework 6.1. I get the error message: PublicKeyToken=xxxxxx is not marked as serializable.

I thought this was fixed. Is it broken again and if so, is there a workaround?

Thanks.

Here is the complete error message when trying to install into a win32 C++ console application. (Built with default settings, no other adds to new build.) Error: Type 'Microsoft.VisualStudio.Project.VisualC.VCProjectEngine.VCProjectShim' in Assembly 'Microsoft.VisualStudio.Project.VisualC.VCProjectEngine, Version=12.0.0.0,Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' is not marked as serializable.

Here is the complete error message when trying to install into a C++ CLR: (Actually, it's the exact same error message.)

Here is the complete error message when trying to install into a General Empty C++ Project: (Again, same error message.)

Jiminion
  • 5,080
  • 1
  • 31
  • 54
  • Ugh, the documentation is unclear, but I'm not sure this is possible. And why the downvote? FWIW, MSDN actually points to SO to get questions answered: http://msdn.microsoft.com/en-us/data/ef.aspx – Jiminion May 10 '14 at 16:58
  • 2
    Avoid assuming SO is a dating service for programmers with exceptions. The number of them that use EF in a C++/CLI app are comparable to the number of Eskimos that have trouble choosing a suntan oil brand. You need to document the error message properly, you've only posted part of the message. What is on the left of "PublicKeyToken", the type name, is essential info. And of course the exception's stack trace. And of course a snippet of the code that generates it. – Hans Passant May 13 '14 at 13:05
  • @HansPassant, I have documented the complete error. They were installs into empty projects, so no novel code is involved. I'm running VS 2013. If EF can't work in C++, that's fine, but they should document that. My workaround is putting it into a dll/assembly and having the C++ access that. – Jiminion May 13 '14 at 13:27
  • Was any ORM alternative proposed? – Sergei Krivonos Feb 27 '16 at 11:55
  • What do you mean by ORM? – Jiminion Feb 29 '16 at 22:29

1 Answers1

13

Okay, I can finally figure out what you are doing. You are trying to run Nuget to download and install the Entity Framework into a C++ project. Yes, that's going to be a fail-whale. Nuget acquired the ability to install C++ libraries at version 2.5, but that only works for native libraries. Pure C++, not managed code like EF. Being a relatively new feature, it doesn't do anything to stop you from getting it wrong, it doesn't filter the available packages to the kind that can work in a C++ project.

The step that fails is the final one, download and copying files work okay but then Nuget runs a Powerscript script to modify the project properties. Which, for EF, was written to work in a C# or VB.NET project. The VS extension model for C++ projects (implemented by the VCProjectEngine class as reported in the error message) is too different to permit that script to complete successfully.

Do keep in mind that the odds of using EF in a native C++ projects are zero. You'll only have a smallish shot at it in a C++/CLI project. Starting with a project template in the CLR node is a required first step.

The next one is to fool the Nuget installer, add a dummy C# project to your solution and run Nuget to get EF installed into that project. You'll see it adding an app.config file to the project, you need to do the same in your C++/CLI project. And it adds two EF assemblies that you also need to add to your C++/CLI project:

  • Right-click the project in the Solution Explorer window, Properties
  • Select Common Properties + References
  • Click the Add New Reference button
  • Click the Browse button
  • Navigate to the dummy C# project's packages\EntityFramework.6.1.0\lib\net45 directory
  • Select EntityFramework.dll you see there
  • Repeat to add EntityFramework.SqlServer.dll there.

Be sure to write C++/CLI code to use it. Beware that you'll have a Eskimo's chance to find any. The much saner approach is to create a C# library that uses EF and use that library in a C++/CLI project.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • 1
    OK, that makes sense. I was confused by the fact that Nuget seemed to allow it to load (or try to) and the Entity Framework documentation makes no mention that it can't work with C++/CLI (though it doesn't say it can either.) Tricking Nuget to load into a C++/CLI project sounds really dicey, and the main project might have to be native C++. So I'm definitely going the C# library approach for now. Thank your for your help. – Jiminion May 13 '14 at 15:08