ArgumentNullException when performing AspNetCore Integration Tests using `Microsoft.AspNetCore.TestHost.TestServer`
See original GitHub issueDescribe the bug
ArgumentNullException when performing AspNetCore Integration Tests using Microsoft.AspNetCore.TestHost.TestServer
Value cannot be null.
Parameter name: operatingAssembly (See inner exception for details.) --->
System.ArgumentNullException: Value cannot be null.
Parameter name: operatingAssembly

at RazorLight.Compilation.RoslynCompilationService..ctor(IMetadataReferenceManager referenceManager, Assembly operatingAssembly)

at RazorLight.RazorLightEngineBuilder.Build()

at Services.Contract.IoC.ContractDomainModule.<>c.<Load>b__0_0(IComponentContext x)

To reproduce: Run a test class library targeting .NET Framework 4.7.1. but running a .NETCore api. Inject the RazorlightEngine in a controller, query the controller end point and wait for it to throw.
Information (please complete the following information):
- OS: Windows 10
- Platform .NET Framework 4.x
- RazorLight version: 2.0.0-beta1
Issue Analytics
- State:
- Created 5 years ago
- Reactions:11
- Comments:9
Top Results From Across the Web
ASP.NET Core TestHost Integration Testing 'System. ...
System.ArgumentNullException : String reference not set to an instance of a String. Parameter name: s. Stack Trace: at System.Text.Encoding.
Read more >The curious case of ASP.NET Core integration test deadlock
One of the common approaches to testing ASP.NET Core applications is to use the integration testing available via the Microsoft.AspNetCore.
Read more >Integration tests in ASP.NET Core
ASP.NET Core supports integration tests using a unit test framework with a test web host and an in-memory test server.
Read more >Integration Testing - ASP.NET Core Documentation
AspNetCore.TestHost package is included in the project, you will be able to create and configure a TestServer in your tests. The following test...
Read more >ASP.NET Core Integration Tests With TestServer - How Did I ...
The test project references the Web API project. And I'm adding a few NuGet packages: Microsoft.AspNetCore.TestHost v3.1.21; Newtonsoft.Json ( ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop 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
Top GitHub Comments
I’m getting the same exception in a .NET Framework 4.6.1 MSTest project – but not when I’m running the ASP.NET Core project…
operatingAssembly must be null from a test project?
I have a .netframework project and I had a similar issue. You need to call “SetOperatingAssembly” and pass the assembly where you actually use the razor engine. To make this work I created a factory that is easily injectable and it can create the razor engine wherever and whenever I need it. Example of the factory:
Just inject this factory and use it to create the razor engine instead of directly injecting the engine. By the way, i am using the filesystem resource type, just change it to embedded as you need.