Trying to test on netcore 2.0
See original GitHub issueIf I use from a .netcore 2.0 app I get:
when trying to parse (I think this is compile errors when compiling the template)
How does the compiler know which assemblies to use?
RazorLight.TemplateCompilationException: 'Failed to compile generated Razor template:
- The type or namespace name 'Linq' does not exist in the namespace 'System' (are you missing an assembly reference?)
- The type or namespace name 'Threading' does not exist in the namespace 'System' (are you missing an assembly reference?)
- 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?
- Predefined type 'System.Boolean' is not defined or imported
- The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
- The return type of an async method must be void, Task or Task<T>
- The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
- Predefined type 'System.Object' is not defined or imported
- The type or namespace name 'Task' could not be found (are you missing a using directive or an assembly reference?)
- 'ArmLinkerScriptTemplate_template.ExecuteAsync()': return type must be 'Task' to match overridden member 'TemplatePage.ExecuteAsync()'
- The type 'Task' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Threading.Tasks, Version=4.0.10.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
- Predefined type 'System.Void' is not defined or imported
Issue Analytics
- State:
- Created 6 years ago
- Comments:8 (2 by maintainers)
Top Results From Across the Web
Testing in .NET Core 2.0. Unit and Integration tests with xUnit
Try creating a test for one of the methods in the OperationsController . We should be able to instance it directly on your...
Read more >Targeting a .NET Core 2.0.1 web project from a C# Test ...
The test project is targeting .NET Framework 4.7 and the web project targets .NET Core App 2.1. You cannot add a reference from...
Read more >Unit testing C# code in .NET Core using dotnet test and xUnit
Learn unit test concepts in C# and .NET Core through an interactive experience building a sample solution step-by-step using dotnet test and ...
Read more >Unit Testing Asp.NET Core 2.0 Web API : r/dotnet
I'm using Moq and Xunit. I'm very simply trying to write unit tests for my controllers. I may be over-thinking this whole process...
Read more >Testing in .NET
This article gives a brief overview of testing concepts, terminology, and tools for testing in .NET.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Just confirming this is still the case with 2.0.0-beta1
var engine = new RazorLightEngineBuilder() .UseMemoryCachingProvider() .Build(); string result = await engine.CompileRenderAsync(“templateKey”, “Name escaped = @Uri.EscapeDataString(@Model.Name)”, new { Name = “bob”} );
throws this error:
Response bodyDownloadSystem.AggregateException: One or more errors occurred. (Failed to compile generated Razor template: - (0:16) The name ‘Uri’ does not exist in the current context
Old version 1 code worked fine:
var eng = EngineFactory.CreatePhysical(@“/”); string result = eng.ParseString(templateText, model);
Including the System namespace in the .cshtml file fixed this problem for me.
@using System;