Random assembly references fail (“Are you missing a using directive or an assembly reference?”)

后端 未结 7 856
时光说笑
时光说笑 2020-12-15 16:52

My application has a mixture of 3.5 and 4.0-targeted assemblies. I\'m working on a new Windows service targeting 4.0 and the project suddenly seems unable to see some of th

相关标签:
7条回答
  • 2020-12-15 17:28

    I was adding projects to a Solution that utilized .net 4.5. The projects I had added were defaulting to 4.5.1. This rendered 4.5 libraries incompatible with the new projects. I went into the properties of my new projects and had them target 4.5 instead of the default 4.5.1. After I had done that, my solution was able to build.

    0 讨论(0)
  • 2020-12-15 17:28

    This problem happened to me once I solved it by deleting all the using statements on top and manually writing them again.

    0 讨论(0)
  • 2020-12-15 17:33

    I had a similar issue, an assembly reference fail (“Are you missing a using directive or an assembly reference?”) and the VS intellisense gave me the opportunity to add the using but in the solution the reference had the yellow icon and the build was failing.

    I solved this looking at the project property Target Framework and changing the .net version to the reference solution version and this solved all problems.

    Note: The .net versions should be compatible between projects.

    0 讨论(0)
  • 2020-12-15 17:37

    Please also note it can happen if you change the namespace but you did not changed the Assembly name in the project properties.

    0 讨论(0)
  • 2020-12-15 17:39

    Check the target platform of the new project and make sure it's not targeting .NET 4 Client Profile. If it is, change it to regular .NET 4

    0 讨论(0)
  • 2020-12-15 17:39

    Are the dependencies set correctly in the solution? I have seen more than one occasion where Project A depends on Project B, but because the dependency between the two was not set the build fails sporadically.

    The underlying cause in this case is that the build is order is not deterministic and success/failure depends on things like which projects build (based on what changed) and which builds first (when more than one builds).

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