To ensure coding standards I have a couple of unit test which uses reflection to see that nothing is wrong. One of those looks like this:
[Test]
public void All_structs_should_be_immutable()
{
var mutableStructs = typeof (Product).Assembly
.GetTypes()
.Where(type =>
type.IsValueType && !type.IsCompilerGenerated() &&
!type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).All(
field => field.IsInitOnly))
.OrderBy(type => type.FullName);
foreach (var mutableStruct in mutableStructs)
{
Console.WriteLine(mutableStruct.FullName);
}
Assert.AreEqual("", string.Join(", ", mutableStructs.Select(x => x.FullName).ToArray()));
Assert.AreEqual(0, mutableStructs.Count());
}
The Product class is within my own assembly which has nothing to do with Jetbrains/Teamcity.
This works fine when running the tests with Resharper. But when I run it in Teamcity, I get this error:
Test(s) failed. Expected string length 0 but was 51. Strings differ at index 0.
Expected:
But was: “JetBrains.Profiler.Core.Instrumentation.DataOnStack”
———–^
at NUnit.Framework.Assert.That(Object actual, IResolveConstraint expression, String message, Object[] args)
at NUnit.Framework.Assert.AreEqual(Object expected, Object actual)
at Litium.Kamakura.UnitTest.CodingStandards.ImmutableStructs.All_structs_should_be_immutable() in c:\TeamCity\buildAgent\work\99395abb82d2a3b3\Test\Litium.Kamakura.UnitTest\CodingStandards\ImmutableStructs.cs:line 26
——- Stdout: ——-
JetBrains.Profiler.Core.Instrumentation.DataOnStack
How and why does Teamcity modify my assembly?
It seems as Teamcity’s test runner (NUnit test runner?) was configured to run with dotCover / dotTrace. One of the profilers above has edited your code (remember that they are .net profilers, and they can inject code at JIT compile time, among others).
According to this bug track, Jetbrains use this structure and will not remove it, so you will have to use a workaround.
See also Teamcity documentation – you can try running with a different runner, or collecting coverage with NCover, or disable coverage altogether.