Vstest: dotnet test fails when trying to execute Assembly.DefinedTypes or Assembly.GetTypes

Created on 5 Feb 2018  路  8Comments  路  Source: microsoft/vstest

_From @derhally on January 1, 2018 15:1_

Description

The following exception occurs when executing Assembly.GetTypes() or Assembly.DefinedTypes inside .net core sdk container

Failed   Test
Error Message:
 System.Reflection.ReflectionTypeLoadException : Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
  ----> System.TypeLoadException : Could not load type 'Microsoft.VisualStudio.TestPlatform.ObjectModel.Navigation.DiaSourceClass' from assembly 'Microsoft.VisualStudio.TestPlatform.ObjectModel, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
Stack Trace:
   at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
   at System.Reflection.RuntimeAssembly.get_DefinedTypes()
   at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.MoveNext()
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source)
   at TestIssue.TestClass.Test() in /temp/TestIssue/TestIssue/Class1.cs:line 16
--TypeLoadException

Steps to reproduce

  1. Copy the project to a container image of microsoft/dotnet:sdk
    TestIssue.zip

  2. Run dotnet build -c Release

  3. Run dotnet test -c Release

Expected behavior

All tests pass

Actual behavior

Exception is thrown

System.Reflection.ReflectionTypeLoadException : Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
  ----> System.TypeLoadException : Could not load type 'Microsoft.VisualStudio.TestPlatform.ObjectModel.Navigation.DiaSourceClass' from assembly 'Microsoft.VisualStudio.TestPlatform.ObjectModel, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.

Environment

Container using sdk image

_Copied from original issue: Microsoft/testfx#341_

bug

Most helpful comment

@derhally @jmeline
Looks like issue due to code in Microsoft.VisualStudio.TestPlatform.ObjectModel.dll using ComImport. I have filed issue on corefx(https://github.com/dotnet/corefx/issues/26851).

Workarounds:

  • Don't reflect types from "Microsoft.VisualStudio.TestPlatform.ObjectModel" assembly.
    OR
  • Downgrading Microsoft.NET.Test.Sdk to 15.3.0.

All 8 comments

_From @derhally on January 27, 2018 18:32_

@smadala any thoughts or updates on this?

@derhally Sorry for leave you hanging, I didn't get change to investigate this, Will get back to you soon.
Adding Microsoft.VisualStudio.TestPlatform.ObjectModel:15.5.0 package reference explicitly helps?

_From @jmeline on January 29, 2018 18:36_

I'm running into the same issue. I tried the TestIssue.zip and was met with the same error. I'm interested in any updates to this issue.

Microsoft.VisualStudio.TestPlatform.ObjectModel:15.5.0 doesn't exist in Nuget. The available version 14.0.0 and still complains about not having 15.0.0

.NET Command Line Tools (2.1.4)

Product Information:
 Version:            2.1.4
 Commit SHA-1 hash:  5e8add2190

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  10.12
 OS Platform: Darwin
 RID:         osx.10.12-x64
 Base Path:   /usr/local/share/dotnet/sdk/2.1.4/

Microsoft .NET Core Shared Framework Host

  Version  : 2.0.5
  Build    : 17373eb129b3b05aa18ece963f8795d65ef8ea54

_From @derhally on January 29, 2018 22:16_

@smadala did you mean to say "Microsoft.TestPlatform.ObjectModel" ?

I tried that and still get the same error

 System.Reflection.ReflectionTypeLoadException : Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
  ----> System.TypeLoadException : Could not load type 'Microsoft.VisualStudio.TestPlatform.ObjectModel.Navigation.DiaSourceClass' from assembly 'Microsoft.VisualStudio.TestPlatform.ObjectModel, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
Stack Trace:
   at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
   at System.Reflection.RuntimeAssembly.get_DefinedTypes()

@derhally @jmeline
Looks like issue due to code in Microsoft.VisualStudio.TestPlatform.ObjectModel.dll using ComImport. I have filed issue on corefx(https://github.com/dotnet/corefx/issues/26851).

Workarounds:

  • Don't reflect types from "Microsoft.VisualStudio.TestPlatform.ObjectModel" assembly.
    OR
  • Downgrading Microsoft.NET.Test.Sdk to 15.3.0.

@smadala Thanks. Downgrading to Downgrading Microsoft.NET.Test.Sdk to 15.3.0 worked for me.

@derhally , we have identified the root cause for this issue, which is because we are using ComImport Attribute on certain classes in our ObjectModel dll. We need this to create certain Com Objects, & then use P/Invoke to get relevant data regarding Navigation of test case object.

It's fair that these object cannot be initialized on dotnet core in Unix, but we were expecting dotnet to allow users to atleast reflect upon types. We have filed a bug on dotnet, please monitor it for further details. I'll be closing this issue.

@derhally Updated workarounds here
/cc @dukeofharen @david-x-chen @FrankSzendzielarz You might facing same issue. From https://github.com/Microsoft/testfx/issues/203#issuecomment-354124177 https://github.com/Microsoft/testfx/issues/203#issuecomment-347289293
https://github.com/Microsoft/testfx/issues/203#issuecomment-360442789

Was this page helpful?
0 / 5 - 0 ratings