“Missing compiler required member” error being thrown multiple times with almost no changes to code

后端 未结 12 1212
既然无缘
既然无缘 2020-12-13 22:46

Today after deploying some changes to a C# MVC site that I run, I went back to make some more modifications and came across this error:

Missing compil

相关标签:
12条回答
  • 2020-12-13 23:18

    I don't know if anyone else has experienced this, but I suddenly rain into this error after adding some code utilizing dynamic types and incorporating WebAPI into a project that originated as a TypeScript application in VS2013. Simply adding a reference to Microsoft.CSharp resolved my issue.

    Hope this helps someone else.

    0 讨论(0)
  • 2020-12-13 23:18

    I don't have a correct solution, but I'll add my data point:

    In my case the error is caused by referencing GoogleSearchAPINet20

    Here is what happens:

    • I close the solution that builds
    • I open the solution again. It still builds
    • As soon as I make any change and try to build, I get 19 "Missing compiler required member ..." errors
    • I remove the reference to GoogleSearchAPINet20
    • I add back the reference to GoogleSearchAPINet20
    • I build the solution. It builds without errors
    • I can now make code changes, build or perform any other actions with solution correctly as long as my Visual Studio is open
    • I close Visual Studio
    • Repeat from step one

    I'm not referencing System.Core.dll in my solution at all and my target framework is .NET 4.

    I'm a bit annoyed at this point ...

    0 讨论(0)
  • 2020-12-13 23:19

    The actual error comes from the fact that your 2.0 assembly that causes the error contains this code:

    namespace System.Runtime.CompilerServices
    {
        public class ExtensionAttribute : Attribute { }
    }
    

    The Code Above allows the .NET 2.0 Assembly to use extension methods (see Using extension methods in .NET 2.0?). While it confuses the compiler if you target .NET 4.0 and reference a 2.0 Assembly (containing above code) as the mscorlib.dll(4.0) contains the same class in the same namespace.

    I fixed this

    • by compiling the original 2.0 assembly again without the attribute targeting 4.0
    • by removing the assembly (obviously)
    • by adding a third Extension Attribute in the target you compile (it seems to overrule the referenced definitions)
    0 讨论(0)
  • 2020-12-13 23:21

    Writing this code somewhere in your project may solve your problem. It works for me

    namespace System.Runtime.CompilerServices
    {
        public class ExtensionAttribute : Attribute { }
    }
    
    0 讨论(0)
  • 2020-12-13 23:22

    For me, the problem occure when I add asynchronous method with async Task await in my .net4.0 project !

    With previous versions of the .NET-Framework 4.5, you must install this package:

    Install-package Microsoft.Bcl.Async –pre
    

    or

    Install-Package Microsoft.CompilerServices.AsyncTargetingPack
    

    more info on Nuget or Nuget

    0 讨论(0)
  • 2020-12-13 23:23

    I ran into this situation as well today. In my case I was referencing the Newton.Json.Net dll v3.5 in my .NET 4.0 application. I realized that I wasnt even using this library, thus once I removed it from my references, it no longer gave me the compiler error.

    Problem solved!!!

    0 讨论(0)
提交回复
热议问题