11

At work I just installed a brand new copy of my OS and a brand new copy of VS2015. When I clone my solution for the first time, I cannot build it anymore, even if I've generated the C# files like I always do, by opening the .edmx file first, and clicking on "save" icon.

When building it throws the error:

CS0150: A constant value is expected

Because the enums that it has generated are incomplete! An example of one:

public enum DocumentType : int
{
    Identity = 1,
    ResidenceProof = 2,
    RegisterDoc = ,
}

I also had this compiler error at the time, but after fixing it my C# enums are still being generated wrongly:

The ADO.NET provider with invariant name 'MySql.Data.MySqlClient' is either not registered in the machine or application config file, or could not be loaded. See the inner exception for details

How the hell should I fix this problem?

13
  • What message is contained in the InnerException? Commented May 20, 2016 at 2:32
  • The following post might be helpful:stackoverflow.com/questions/15142841/… -- but I'm not certain. Commented May 20, 2016 at 2:35
  • @DavidTansey: not sure this is the same problem, I don't have exceptions but compiler errors Commented May 20, 2016 at 2:41
  • Yeah, I understand what you're saying. I only asked because of the part of the message that says: See the inner exception for details I would at least compare the relevant config sections that are referenced in that post to see if something helps to get a hint why EF is not behaving as you expect. Commented May 20, 2016 at 2:45
  • oh, but I go to see the build output and I don't see that error in there, so not sure where to look for the innerException :-/ Commented May 20, 2016 at 3:00

2 Answers 2

7

I had the same problem. Turned out that texttransform.exe cannot understand different line endings well. My .tt file was saved with Unix EOL, and when I saved it with Windows EOL, it started to work correctly. Just that simple - open your .tt file in WordPad and save.

Sign up to request clarification or add additional context in comments.

2 Comments

Excellent. FYI you can open the *.tt file(s) in VS and change the line endings to CRLF at the bottom-right of the document: i.imgur.com/EFc2Lz5.png
I can confirm this is still a problem in VS2019 and EF 6.2. This is the fix.
2

Not really an answer but i'll post my findings and the workaround i chose to use;

The T4 Code Generation template (The file attached to your .edmx file using the .tt file-extention) contains code to generate C# using the data available in your model, I suspect the code at line #204 (might be located on a different line number in your version) to contain a minor bug.

A screenshot from my active project and solution explorer: Code inside the .tt file

This line causes the faulty enums:

    this.GenerationEnvironment.Remove(this.GenerationEnvironment.Length - 3, 1);

This presumably removes generated code characters that were added by the enum generator in order to remove the last , from the enum, as it is unnecessary.

I tested the functionality of this by adding output in front of this line, i tried creating an enum that would output MyEnumMemberName = TEST, and found that the output contained MyEnumMemberName = TES,.

Using this I found that changing the line to:

    this.GenerationEnvironment.Remove(this.GenerationEnvironment.Length - 2, 1);

solves my issue.

Can't currently check if this also works on the machines that were already generating correct code but I hope it helps some of you. Good luck.

4 Comments

sorry but where does this code come from? how do you locate it in VS? do you know if this is part of EF?
I use a model-first approach, in an empty project add a Entity Data Model (.edmx), open the model (Named Model1.edmx) and right click > Add Code Generation Item. This will add a Model1.tt item in your solution explorer tree beneath your Model1.edmx, the code i'm speaking of is inside this Model1.tt file.
I'm not sure which VS plugin injects the code into this Model1.tt file to begin with, it's probably EF. I'm still hoping to find an answer along the lines of 'Update your XX to version XX'
EF is opensource so we should be able to find the code that does this

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.