Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only send Coverlet in proc datacollector dll to testhost #2226

Merged
merged 2 commits into from
Oct 17, 2019
Merged

Only send Coverlet in proc datacollector dll to testhost #2226

merged 2 commits into from
Oct 17, 2019

Conversation

mayankbansal018
Copy link
Contributor

@mayankbansal018 mayankbansal018 commented Oct 16, 2019

Bug: https://developercommunity.visualstudio.com/content/problem/738856/could-not-load-file-or-assembly-microsoftintellitr.html

RC: Earlier we were loading all datacollector dll's in testhost process. In case of netcore test where dotnet is launched, we started loading FullCLR dlls inside testhost process. Now loading dlls was okay, but the moment user did

AppDomain.CurrentDomain.GetAssemblies().First(asm => asm.DefinedTypes.Any(t => t.FullName == "foo")) it would fail

This was because the above line would cause dependent dll of FullCLR dll's to be loaded, which if not found would throw FileNotFoundException, & user code/test code would start failing.

We are white-listing coverlet inproc dll to be loaded in testhost process. Please see code comments to understand why, & how it should be fixed

@@ -261,7 +267,9 @@ private void LogMessage(TestMessageLevel testMessageLevel, string message)
private void InitializeExtensions(IEnumerable<string> sources)
{
var extensions = TestPluginCache.Instance.GetExtensionPaths(TestPlatformConstants.TestAdapterEndsWithPattern, this.skipDefaultAdapters);
extensions = extensions.Concat(TestPluginCache.Instance.GetExtensionPaths(TestPlatformConstants.DataCollectorEndsWithPattern, true)).ToList();

// remove this line once we figure out why coverlet inrpoc DC is not initialized via runsetting inproc node.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: inproc

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

extensions = extensions.Concat(TestPluginCache.Instance.GetExtensionPaths(TestPlatformConstants.DataCollectorEndsWithPattern, true)).ToList();

// remove this line once we figure out why coverlet inrpoc DC is not initialized via runsetting inproc node.
extensions = extensions.Concat(TestPluginCache.Instance.GetExtensionPaths(ProxyExecutionManager.CoverletDataCollector, true)).ToList();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assuming the LUT inproc data collector gets initialized via runsettings

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this code was recently added, so LUT should not be dependent on it, will double check though

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LUT inproc datacollector would be providing full codebase path in runsettings, which wouldn't depend on this flow.

// Only send coverlet inproc datacollector dll to be initialized via testhost,
// ideally this should get initialized via InProcessDC Node in runsettings, but
// somehow it is failing, hence putting this ugly HACK, to fix issues like
// https://developercommunity.visualstudio.com/content/problem/738856/could-not-load-file-or-assembly-microsoftintellitr.html
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the runsettings, we do not send the complete codebase path for coverlet. We send just the dll name (coverlet.collector.dll). Later, in test host while initializing the inproc data collector, we look for all directories from where (datacollector)extensions were loaded and try to find the coverlet.collector.dll in those paths. (https://github.com/microsoft/vstest/blob/master/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/InProcDataCollectionExtensionManager.cs#L69)

If there's a way we can add the full codebase in runsettings, then this can be avoided.

@mayankbansal018 mayankbansal018 merged commit ca987de into microsoft:master Oct 17, 2019
@shvez
Copy link

shvez commented Oct 25, 2019

hi, there.
I have a similar issue with tests, but I do not do any of the reflection magic in my code. Actually it even does not start my code. In trace logs I managed to find next thing:

TpTrace Warning: 0 : 4396, 5, 2019/10/25, 11:07:12.231, 7602709763045, testhost.dll, TestPluginDiscoverer: Failed to get types from assembly 'Microsoft.VisualStudio.TraceDataCollector, Version=16.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.  Skipping test extension scan for this assembly.  Error: System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types.
Could not load file or assembly 'Microsoft.IntelliTrace.Core, Version=16.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
   at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
   at System.Reflection.RuntimeModule.GetTypes()
   at System.Reflection.Assembly.GetTypes()
   at Microsoft.VisualStudio.TestPlatform.Common.ExtensionFramework.TestPluginDiscoverer.GetTestExtensionsFromAssembly[TPluginInfo,TExtension](Assembly assembly, Dictionary`2 pluginInfos)
System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.IntelliTrace.Core, Version=16.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
File name: 'Microsoft.IntelliTrace.Core, Version=16.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

It fails to get type Microsoft.VisualStudio.TraceDataCollector.

Do I miss something?

I'm using MSVS Communitiy 16.3.6.

My tests assembly refers:
NUnit3TestAdapter" Version="3.15.1",
"nunit" Version="3.12.0",
"Microsoft.NET.Test.Sdk" Version="16.3.0"

It is built for netcoreapp3 and netframework 4.6.1. Tests are able to start for netframework version. but not able to netcoreapp 3.0

@emumanu
Copy link

emumanu commented Nov 8, 2019

I've got a similar error using:
NUnit3TestAdapter" Version="3.15.1",
"nunit" Version="3.12.0",
"Microsoft.NET.Test.Sdk" Version="16.4.0"

wiht VS2019 community 16.4.0 preview 4 and VS2019 community 16.3.8:

In a netcoreapp 3.0 nunit test project:

System.Reflection.ReflectionTypeLoadException
HResult=0x80131602
Message=Unable to load one or more of the requested types.
Could not load file or assembly 'Microsoft.IntelliTrace.Core, Version=16.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
Source=System.Private.CoreLib
StackTrace:
at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
at System.Reflection.RuntimeModule.GetTypes()
at System.Reflection.Assembly.GetTypes()
at Manu.Utils.TypeHelpers.GetDerivedTypes(Assembly assembly, Type baseType)
at Manu.Data.AuditableDbContext.OnModelCreating(DbModelBuilder modelBuilder) in D:\Tiedra\codigo\Serializacion\Manu.Data\Manu.Data\AuditableDbContext.cs:line 119
at System.Data.Entity.DbContext.CallOnModelCreating(DbModelBuilder modelBuilder)
at System.Data.Entity.Internal.LazyInternalContext.CreateModelBuilder()
at System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext internalContext)
at System.Data.Entity.Internal.RetryLazy2.GetValue(TInput input) at System.Data.Entity.Internal.LazyInternalContext.InitializeContext() at System.Data.Entity.Internal.InternalContext.Initialize() at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType) at System.Data.Entity.Internal.Linq.InternalSet1.Initialize()
at System.Data.Entity.Internal.Linq.InternalSet1.GetEnumerator() at System.Data.Entity.Infrastructure.DbQuery1.System.Collections.Generic.IEnumerable.GetEnumerator()
at System.Collections.Generic.List1..ctor(IEnumerable1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable1 source) at Manu.Data.CachedRepository2.GetAll() in D:\Tiedra\codigo\Serializacion\Manu.Data\Manu.Data\CachedRepository.cs:line 66
at Manu.Data.Tests.BaseDbTest.EnsureDivisionsCreated(IDivisionRepository divisionRepository) in D:\Tiedra\codigo\Serializacion\Manu.Data\Manu.Data.Tests\BaseDbTest.cs:line 88
at Manu.Data.Tests.BaseDbTest.OneTimeSetUp() in D:\Tiedra\codigo\Serializacion\Manu.Data\Manu.Data.Tests\BaseDbTest.cs:line 83

Please help

@AbhitejJohn
Copy link
Contributor

@mayankbansal018 , @singhsarab , @vagisha-nidhi : Wouldn't the same error be thrown if any of the adapter assemblies supplied are full framework too?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants