2

In the process of unit testing,I tried to read a SQL file which I marked as embedded resource. It works fine in local. But when the unit test runs in the DevOps pipeline, I am getting ArgumentNullexpetion for the stream reader which uses the output of 'GetManifestResourceStream' I tried write in console the list of 'GetManifestResourceNames' it lists all SQL files correctly.

var assembly=Assembly.GetExecutingAssembly();
var filename=MethodBase.GetCurrentMethod().Declaring type.Namesapce+folder name+filename;
var stream= assembly.GetManifestResourceStream(filename);//returns null in pipeline but works perfectly in local.
var reader=new StreamReader(stream)
reader.ReadToEnd()// exception thrown

The code is placed in MSTest project and called in the ClassInitialize method. How to fix this pipeline exception

Samuel A C
  • 406
  • 3
  • 16
  • Is it actually finding the file? The [documentation for GetManifestResourceStream](https://learn.microsoft.com/en-us/dotnet/api/system.reflection.assembly.getmanifestresourcestream?view=net-5.0) says that it returns null if the file is not found. – Robert Harvey Mar 04 '21 at 20:09
  • It would help if you'd show actual code instead of pseudo-code (this wouldn't compile for many reasons) and showed the resource you're trying to load. – Jon Skeet Mar 04 '21 at 20:10
  • @Robert Yes, I also console printed the list of resources through 'GetManifestResourceNames'. It's file name matches with the filename I generated – Samuel A C Mar 04 '21 at 20:12
  • Have you seen this? https://stackoverflow.com/q/21637830 – Robert Harvey Mar 04 '21 at 20:55
  • I was using "Assembly.GetManifestResourceStream()" to get the Embedded file's content in Unit Tests successfully until couple of days back. For some reason while running the tests in azure pipeline, is returning "null" to the call. I am not able to figure out why! – Teddy Oddman Feb 10 '22 at 06:43
  • @SamuelAC, did you resolve this issue? I am facing the same issue. I guess this could be something related to Pipeline changes, as the same code was running successfully on pipeline for several years for me. It started failing just a couple of days back. I must have changed some setting in the pipeline or the running agent. – Teddy Oddman Feb 10 '22 at 07:02

0 Answers0