OdeToFood icon indicating copy to clipboard operation
OdeToFood copied to clipboard

CS0579 - Duplicate 'System.Reflection.Assembly[something]Attribute Errors

Open believelifeisfun opened this issue 5 years ago • 5 comments

Hi Scott,

I'm enjoying the instruction, but I must have missed an instruction, or "fixed" something I should not have fixed along the way through your ASP.Net Core lesson, but I've run upon this CS0579 error twice now getting up to section 3.8 "linking to the details."

The first time I ran into this error, I was able to add a series of "false" <GenerateAssembly[something]Attribute> statements to the .csproj file and the duplication error cleared itself. The errors started popping up again around section 3.8 and even though I back out of the changes for several modules, I keep getting the error.

Originally I thought the problem was caused because I created the OdeToFood project with the target framework of ".Net Core 2.1" and then failed to do the same for the "OdeToFood.Core" and "OdeToFood.Data" projects. And I switched all three to 2.1, and then to 3.1 trying to see if there was some reason why the compiler is trying to build these assemblies multiple times. Setting the "generate" flags to false for all of them in each .csproj file doesn't seem to eliminate the errors either.

I'm just going to archive the solution and start over again and not try to be clever by using 2.1, and follow the added instructions for 3.0+ here on github. But, I figured I would pass this along in case others were having the same problem.

Good Fortune, Richard

believelifeisfun avatar Apr 30 '20 18:04 believelifeisfun

Going through the second time, I think I know "where" the issue started. In section 2, "Building a Data Access Service" intellisense is not finding the class "Restaurant" in OdeToFood.Core. The error CS0246: The type or Namespace name 'Restaurant' could not be found (are you missing a using directive or an assembly reference?). Unfortunately it also doesn't offer the option to add the namespace to OdeToFood.Core. I tried adding the namespace manually, but it doesn't seem to see the other project in the same solution.

Note that this is where these reference errors begin.

Good Fortune, Richard

believelifeisfun avatar Apr 30 '20 20:04 believelifeisfun

I right-clicked on each project adding project references to both "OdeToFood" and "OdeToFood.Core" in the "OdeToFood.Data.csproj" file. Then I also added a single project reference to "OdeToFood" in the "OdeToFood.Core.csproj" file. I removed the problem line:

IEnumerable<Restaurant> GetAll();

And did a build on the solution. Everything works up to that point. But reading the line above, I can't seem to get this project to use the Restaurant class in "OdeToFood.Core".

Good Fortune, Richard

believelifeisfun avatar Apr 30 '20 20:04 believelifeisfun

Note: to move on with the lesson, I moved the files in the OdeToFood.Core and OdeToFood.Data projects into folders under OdeToFood/Pages/.. and now intelisense easily finds the class and I'm able to move on. I would still appreciate any advice about why I couldn't reference the class from the separate projects.

Good Fortune, Richard

believelifeisfun avatar Apr 30 '20 20:04 believelifeisfun

Unfortunately, Mr. Scott Allen has passed away recently.

CePur avatar May 05 '20 21:05 CePur

I just ran into the same Problem and needed to reference them manually. Also when trying to add them via Intellisense my Visual Studio went into an (probably) infinite loop.

Solution was also just to right click on the Projects and add the References manually. I think there are some shenanigans going on with IntelliSense.

Rip Mr. Scott

StayFN avatar Jan 19 '21 00:01 StayFN