Skip to content
This repository has been archived by the owner on Sep 13, 2022. It is now read-only.

The type 'Attribute' is defined in an assembly that is not referenced. #474

Closed
Nathan-Ryan opened this issue Aug 28, 2017 · 6 comments
Closed

Comments

@Nathan-Ryan
Copy link

I'm encountering this error when using MSTest and the Microsoft.AspNetCore.TestHost. It all works fine until I call the TestServer to render a view.

I'm using VS2017 15.3 with the .NET Core 2.0 Sdk with my net.core app targeting .NET Framework 4.6.1.
Any advise on how I might fix this?

"Microsoft.AspNetCore.Mvc.Razor.Compilation.CompilationFailedException: One or more compilation failures occurred:\r\ne3s05cht.itf(4,62): error CS0012: The type 'Attribute' is defined in an assembly that is not referenced. You must add a reference to assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.\r\ne3s05cht.itf(4,81): error CS0518: Predefined type 'System.String' is not defined or imported\r\ne3s05cht.itf(4,109): error CS0518: Predefined type 'System.Type' is not defined or imported\r\ne3s05cht.itf(4,11): error CS0518: Predefined type 'System.Void' is not defined or imported\r\ne3s05cht.itf(8,11): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?)\r\ne3s05cht.itf(9,11): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?)\r\ne3s05cht.itf(10,11): error CS0246: The type or namespace name 'System' could not be fou
nd (are you missing a using directive or an assembly reference?)\r\ne3s05cht.itf(11,11): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?)\r\ne3s05cht.itf(14,36): error CS0234: The type or namespace name 'ViewFeatures' does not exist in the namespace 'Microsoft.AspNetCore.Mvc' (are you missing an assembly reference?)\r\ne3s05cht.itf(15,93): error CS1980: Cannot define a class or member that utilizes 'dynamic' because the compiler required type 'System.Runtime.CompilerServices.DynamicAttribute' cannot be found. Are you missing a reference?\r\ne3s05cht.itf(15,93): error CS0518: Predefined type 'System.Boolean' is not defined or imported\r\ne3s05cht.itf(15,44): error CS0012: The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.\r\ne3s05cht.itf(18,67): error CS1983: The return type of an async method mus
t be void, Task or Task<T>\r\ne3s05cht.itf(18,39): error CS0400: The type or namespace name 'System' could not be found in the global namespace (are you missing an assembly reference?)\r\ne3s05cht.itf(70,49): error CS0234: The type or namespace name 'ViewFeatures' does not exist in the namespace 'Microsoft.AspNetCore.Mvc' (are you missing an assembly reference?)\r\ne3s05cht.itf(70,118): error CS0518: Predefined type 'System.Void' is not defined or imported\r\ne3s05cht.itf(72,49): error CS0234: The type or namespace name 'IUrlHelper' does not exist in the namespace 'Microsoft.AspNetCore.Mvc' (are you missing an assembly reference?)\r\ne3s05cht.itf(72,71): error CS0518: Predefined type 'System.Void' is not defined or imported\r\ne3s05cht.itf(74,49): error CS0234: The type or namespace name 'IViewComponentHelper' does not exist in the namespace 'Microsoft.AspNetCore.Mvc' (are you missing an assembly reference?)\r\ne3s05cht.itf(74,87): error CS0518: Predefined type 'System.Void' is not defined or imported\r\ne3s05
cht.itf(76,59): error CS0234: The type or namespace name 'IJsonHelper' does not exist in the namespace 'Microsoft.AspNetCore.Mvc.Rendering' (are you missing an assembly reference?)\r\ne3s05cht.itf(76,83): error CS0518: Predefined type 'System.Void' is not defined or imported\r\ne3s05cht.itf(78,59): error CS0234: The type or namespace name 'IHtmlHelper<>' does not exist in the namespace 'Microsoft.AspNetCore.Mvc.Rendering' (are you missing an assembly reference?)\r\ne3s05cht.itf(78,71): error CS0012: The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.\r\ne3s05cht.itf(78,71): error CS0518: Predefined type 'System.Object' is not defined or imported\r\ne3s05cht.itf(78,71): error CS1980: Cannot define a class or member that utilizes 'dynamic' because the compiler required type 'System.Runtime.CompilerServices.DynamicAttribute' cannot be found. Are you missing a reference?\r\ne3s05ch
t.itf(78,71): error CS0518: Predefined type 'System.Boolean' is not defined or imported\r\ne3s05cht.itf(78,92): error CS0518: Predefined type 'System.Void' is not defined or imported\r\ne3s05cht.itf(18,67): error CS0508: '_Views_PublicApp_cshtml.ExecuteAsync()': return type must be 'Task' to match overridden member 'RazorPageBase.ExecuteAsync()'\r\ne3s05cht.itf(18,67): error CS0012: The type 'Task' is defined in an assembly that is not referenced. You must add a reference to assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.\r\ne3s05cht.itf(69,58): error CS0012: The type 'Attribute' is defined in an assembly that is not referenced. You must add a reference to assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.\r\ne3s05cht.itf(69,10): error CS0518: Predefined type 'System.Void' is not defined or imported\r\ne3s05cht.itf(71,58): error CS0012: The type 'Attribute' is defined in an assembly that is not referenced. You must add a referen
ce to assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.\r\ne3s05cht.itf(71,10): error CS0518: Predefined type 'System.Void' is not defined or imported\r\ne3s05cht.itf(73,58): error CS0012: The type 'Attribute' is defined in an assembly that is not referenced. You must add a reference to assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.\r\ne3s05cht.itf(73,10): error CS0518: Predefined type 'System.Void' is not defined or imported\r\ne3s05cht.itf(75,58): error CS0012: The type 'Attribute' is defined in an assembly that is not referenced. You must add a reference to assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.\r\ne3s05cht.itf(75,10): error CS0518: Predefined type 'System.Void' is not defined or imported\r\ne3s05cht.itf(77,58): error CS0012: The type 'Attribute' is defined in an assembly that is not referenced. You must add a reference to assembly 'netstandard, Version=2.0.0.0, Culture=ne
utral, PublicKeyToken=cc7b13ffcd2ddd51'.\r\ne3s05cht.itf(77,10): error CS0518: Predefined type 'System.Void' is not defined or imported\r\ne3s05cht.itf(20,13): error CS0012: The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.\r\ne3s05cht.itf(20,13): error CS0518: Predefined type 'System.Object' is not defined or imported\r\ne3s05cht.itf(20,26): error CS0518: Predefined type 'System.Int32' is not defined or imported\r\ne3s05cht.itf(20,29): error CS0518: Predefined type 'System.Int32' is not defined or imported\r\ne3s05cht.itf(20,34): error CS0518: Predefined type 'System.Boolean' is not defined or imported\r\ne3s05cht.itf(20,13): error CS0518: Predefined type 'System.Void' is not defined or imported\r\ne3s05cht.itf(21,13): error CS0012: The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'netstandard, Version=2.0.0.0, Culture=
neutral, PublicKeyToken=cc7b13ffcd2ddd51'.\r\ne3s05cht.itf(21,13): error CS0518: Predefined type 'System.Object' is not defined or imported\r\ne3s05cht.itf(21,26): error CS0518: Predefined type 'System.String' is not defined or imported\r\ne3s05cht.itf(21,13): error CS0518: Predefined type 'System.Void' is not defined or imported\r\ne3s05cht.itf(36,13): error CS0012: The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.\r\ne3s05cht.itf(36,13): error CS0518: Predefined type 'System.Object' is not defined or imported\r\ne3s05cht.itf(36,13): error CS0518: Predefined type 'System.Void' is not defined or imported\r\ne3s05cht.itf(43,13): error CS0012: The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.\r\ne3s05cht.itf(43,13): error CS0518: Predefined ty
pe 'System.Object' is not defined or imported\r\ne3s05cht.itf(43,26): error CS0518: Predefined type 'System.Int32' is not defined or imported\r\ne3s05cht.itf(43,31): error CS0518: Predefined type 'System.Int32' is not defined or imported\r\ne3s05cht.itf(43,36): error CS0518: Predefined type 'System.Boolean' is not defined or imported\r\ne3s05cht.itf(43,13): error CS0518: Predefined type 'System.Void' is not defined or imported\r\ne3s05cht.itf(44,13): error CS0012: The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.\r\ne3s05cht.itf(44,13): error CS0518: Predefined type 'System.Object' is not defined or imported\r\ne3s05cht.itf(44,26): error CS0518: Predefined type 'System.String' is not defined or imported\r\ne3s05cht.itf(44,13): error CS0518: Predefined type 'System.Void' is not defined or imported\r\ne3s05cht.itf(48,13): error CS0012: The type 'Object' is defined in an assembl
y that is not referenced. You must add a reference to assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.\r\ne3s05cht.itf(48,13): error CS0518: Predefined type 'System.Object' is not defined or imported\r\ne3s05cht.itf(48,13): error CS0518: Predefined type 'System.Void' is not defined or imported\r\ne3s05cht.itf(56,13): error CS0012: The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.\r\ne3s05cht.itf(56,13): error CS0518: Predefined type 'System.Object' is not defined or imported\r\ne3s05cht.itf(56,26): error CS0518: Predefined type 'System.Int32' is not defined or imported\r\ne3s05cht.itf(56,31): error CS0518: Predefined type 'System.Int32' is not defined or imported\r\ne3s05cht.itf(56,36): error CS0518: Predefined type 'System.Boolean' is not defined or imported\r\ne3s05cht.itf(56,13): error CS0518: Predefined type 'System.Void' is not d
efined or imported\r\ne3s05cht.itf(57,13): error CS0012: The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.\r\ne3s05cht.itf(57,13): error CS0518: Predefined type 'System.Object' is not defined or imported\r\ne3s05cht.itf(57,26): error CS0518: Predefined type 'System.String' is not defined or imported\r\ne3s05cht.itf(57,13): error CS0518: Predefined type 'System.Void' is not defined or imported\r\ne3s05cht.itf(58,13): error CS0012: The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.\r\ne3s05cht.itf(58,13): error CS0518: Predefined type 'System.Object' is not defined or imported\r\ne3s05cht.itf(58,13): error CS0518: Predefined type 'System.Void' is not defined or imported\r\ne3s05cht.itf(64,13): error CS0012: The type 'Object' is defined in an as
sembly that is not referenced. You must add a reference to assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.\r\ne3s05cht.itf(64,13): error CS0518: Predefined type 'System.Object' is not defined or imported\r\ne3s05cht.itf(64,26): error CS0518: Predefined type 'System.Int32' is not defined or imported\r\ne3s05cht.itf(64,32): error CS0518: Predefined type 'System.Int32' is not defined or imported\r\ne3s05cht.itf(64,37): error CS0518: Predefined type 'System.Boolean' is not defined or imported\r\ne3s05cht.itf(64,13): error CS0518: Predefined type 'System.Void' is not defined or imported\r\ne3s05cht.itf(65,13): error CS0012: The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.\r\ne3s05cht.itf(65,13): error CS0518: Predefined type 'System.Object' is not defined or imported\r\ne3s05cht.itf(65,26): error CS0518: Predefined type 'System.String' i
s not defined or imported\r\ne3s05cht.itf(65,13): error CS0518: Predefined type 'System.Void' is not defined or imported\r\ne3s05cht.itf(66,13): error CS0012: The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.\r\ne3s05cht.itf(66,13): error CS0518: Predefined type 'System.Object' is not defined or imported\r\ne3s05cht.itf(66,13): error CS0518: Predefined type 'System.Void' is not defined or imported\r\ne3s05cht.itf(18,67): error CS0161: '_Views_PublicApp_cshtml.ExecuteAsync()': not all code paths return a value\r\ne3s05cht.itf(15,18): error CS0518: Predefined type 'System.Void' is not defined or imported\r\nC:\\Source\\TFS\\ReferenceApp\\RefApp.Web\\Views\\PublicApp.cshtml(15,10): error CS0518: Predefined type 'System.Boolean' is not defined or imported\r\n   at Microsoft.AspNetCore.Mvc.Razor.Internal.RazorViewCompiler.CompileAndEmit(RazorCodeDocument codeDocument, String gener
atedCode)\r\n   at Microsoft.AspNetCore.Mvc.Razor.Internal.RazorViewCompiler.CompileAndEmit(String relativePath)\r\n   at Microsoft.AspNetCore.Mvc.Razor.Internal.RazorViewCompiler.CreateCacheEntry(String normalizedPath)\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at Microsoft.AspNetCore.Mvc.Razor.Internal.DefaultRazorPageFactoryProvider.CreateFactory(String relativePath)\r\n   at Microsoft.AspNetCore.Mvc.Razor.RazorViewEngine.CreateCacheResult(HashSet`1 expirationTokens, String relativePath, Boolean isMainPage)\r\n   at Microsoft.AspNetCore.Mvc.Razor.RazorViewEngine.LocatePageFromPath(String executingFilePath, String pagePath, Boolean isMainPage)\r\n   at Microsoft.AspNetCore.Mvc.Razor.RazorViewEngine.GetView(String executingFilePath, String viewPath, Boolean isMainPage)\r\n   at Micro
soft.AspNetCore.Mvc.ViewEngines.CompositeViewEngine.GetView(String executingFilePath, String viewPath, Boolean isMainPage)\r\n   at Microsoft.AspNetCore.Mvc.ViewFeatures.Internal.ViewResultExecutor.FindView(ActionContext actionContext, ViewResult viewResult)\r\n   at Microsoft.AspNetCore.Mvc.ViewResult.<ExecuteResultAsync>d__26.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.<InvokeResultAsync>d__19.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvo
ker.<InvokeNextResultFilterAsync>d__24.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResultExecutedContext context)\r\n   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)\r\n   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.<InvokeNextResourceFilter>d__22.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context)\r\n   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)\r\n   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.<InvokeFilterPipelineAsync>d__17.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
 task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.<InvokeAsync>d__15.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at Microsoft.AspNetCore.Builder.RouterMiddleware.<Invoke>d__4.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)\r\n   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.<Invoke>d__6.MoveNext()\r\n--- End of stack trace from previous lo
cation where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.<Invoke>d__6.MoveNext()"

@pranavkm
Copy link

@Nathan-Ryan you might be running in to the same sort of issue as aspnet/Razor#1212. There's some guidance in aspnet/Razor#1212 (comment) for fixing this.

@Nathan-Ryan
Copy link
Author

Nathan-Ryan commented Aug 28, 2017

@pranavkm Sounds like it could be the same issue, although I'm using MSTest and not xUnit.
It does seem to be a problem with the dependencies of Razor. The tests for my API endpoints work as expected. Thanks for your help.

@pranavkm
Copy link

Perhaps DeploymentItem would help in this case?

@oferns
Copy link

oferns commented Sep 16, 2017

I am having this issue as well. I am using MSTest and VS2017 15.3 with the .NET Core 2.0 Sdk with my net.core app targeting .NET Framework 4.6.1. I fixed it by adding this to the test project csproj

  <!--
    Work around https://github.com/NuGet/Home/issues/4412. MVC uses DependencyContext.Load()         which looks next to a .dll
    for a .deps.json. Information isn't available elsewhere. Need the .deps.json file for all web site     applications.
  -->
  <Target Name="CopyDepsFiles" AfterTargets="Build" Condition="'$(TargetFramework)'!=''">
    <ItemGroup>
      <DepsFilePaths Include="$([System.IO.Path]::ChangeExtension('%(_ResolvedProjectReferencePaths.FullPath)', '.deps.json'))" />
    </ItemGroup>

    <Copy SourceFiles="%(DepsFilePaths.FullPath)" DestinationFolder="$(OutputPath)" Condition="Exists('%(DepsFilePaths.FullPath)')" />
  </Target>

A

@pranavkm
Copy link

Microsoft.AspNetCore.Mvc.Testing takes care of copying the deps file from the application under test to the test app. See https://docs.microsoft.com/en-us/aspnet/core/test/integration-tests for specifics on how to set it up in your test applications.

@pranavkm pranavkm reopened this Jan 30, 2019
@terrajobst terrajobst added this to the .NET Standard 2.1 milestone Mar 13, 2019
@wtgodbe
Copy link
Member

wtgodbe commented May 30, 2019

Closing as the discussion seems to be resolved

@wtgodbe wtgodbe closed this as completed May 30, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants