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

Type.IsSubclassOf throws TypeLoadException #11123

Closed
rjvdboon opened this issue Oct 12, 2018 · 1 comment

Comments

@rjvdboon
Copy link
Contributor

@rjvdboon rjvdboon commented Oct 12, 2018

Steps to Reproduce

file.txt

  1. Save the attached file as file.cs
  2. Compile A.dll, B.dll, and Prog.exe as specified in the header of the file.
  3. Run mono Prog.exe, observe no exception
  4. rm A.dll
  5. Run mono Prog.exe again, should have no exception, has a TypeLoadException.

While the steps to reproduce obviously cause runtime failure, this is also a problem in more legitimate scenarios, see Stacktrace section below for the exception we get in our testsuite.

Current Behavior

On Mono 5.16.0.179 I get the following output with a TypeLoadException

.
Assembly mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
  contains 0 types
Assembly Prog, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
  contains 0 types
Assembly B, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
Caught UNexpected: System.TypeLoadException: Could not load type of field 'B.Two.Derived:myOne' (0) due to: Could not load file or assembly 'A, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies.
  at (wrapper managed-to-native) System.RuntimeTypeHandle.is_subclass_of(intptr,intptr)
  at System.RuntimeTypeHandle.IsSubclassOf (System.RuntimeType childType, System.RuntimeType baseType) [0x00016] in <406b9a7e0e504a4289a76df450bd6eef>:0
  at System.RuntimeType.IsSubclassOf (System.Type type) [0x00020] in <406b9a7e0e504a4289a76df450bd6eef>:0
  at Program.C+<>c__DisplayClass0_0.<Main>b__0 (System.Type t) [0x00000] in <3daa97e0a49f4911953cec2221f49a83>:0
  at System.Linq.Enumerable+WhereArrayIterator`1[TSource].GetCount (System.Boolean onlyIfCheap) [0x0001a] in <b7a52c68d5a5436ab599e3e3f31ab4b2>:0
  at System.Linq.Enumerable.Count[TSource] (System.Collections.Generic.IEnumerable`1[T] source) [0x00029] in <b7a52c68d5a5436ab599e3e3f31ab4b2>:0
  at Program.C.Main () [0x00076] in <3daa97e0a49f4911953cec2221f49a83>:0

Expected Behavior

No exception, or at worst a ReflectionTypeLoadException on the GetTypes().

On .Net framework and on Mono upto and including 5.14.0.177 the output was:

.
Assembly mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
  contains 0 types
Assembly Prog, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
  contains 0 types
Assembly B, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
  contains 0 types
Assembly System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
  contains 0 types

On which platforms did you notice this

[ ] macOS
[ X ] Linux
[ ] Windows

Version Used:

5.16.0.179

Stacktrace

   System.TypeLoadException : Could not load type of field 'Microsoft.Owin.Security.DataProtection.DpapiDataProtector:_protector' (0) due to: Could not resolve type with token 0100000a from typeref (expected class 'System.Security.Cryptography.DpapiDataProtector' in assembly 'System.Security, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a') assembly:System.Security, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a type:System.Security.Cryptography.DpapiDataProtector member:(null)
  at (wrapper managed-to-native) System.RuntimeTypeHandle.is_subclass_of(intptr,intptr)
  at System.RuntimeTypeHandle.IsSubclassOf (System.RuntimeType childType, System.RuntimeType baseType) [0x00000] in /work/rpmbuild/BUILD/mono-5.16.0.179/mcs/class/corlib/System/RuntimeTypeHandle.cs:255
  at System.RuntimeType.IsSubclassOf (System.Type type) [0x00020] in /work/rpmbuild/BUILD/mono-5.16.0.179/mcs/class/corlib/ReferenceSources/RuntimeType.cs:825
  at CoFlow.Sdk.Utility.TypeTree+<GetAllSubclassesInAppDomain>c__AnonStorey0.<>m__0 (System.Type type) [0x00007] in /scratch/CoFlow/Src/Extensibility/CoFlow.Sdk/Utility/TypeTree.cs:82
  at System.Linq.Enumerable+WhereArrayIterator`1[TSource].ToList () [0x00019] in /work/rpmbuild/BUILD/mono-5.16.0.179/external/corefx/src/System.Linq/src/System/Linq/Where.cs:281
  at System.Linq.Enumerable.ToList[TSource] (System.Collections.Generic.IEnumerable`1[T] source) [0x0000e] in /work/rpmbuild/BUILD/mono-5.16.0.179/external/corefx/src/System.Linq/src/System/Linq/ToCollection.cs:30
  at Code.Reflect.GetAllDerivedClasses (System.Type baseType) [0x0005e] in <reflector>:82
  at Code.Reflect.Test.GetAllDerivedClasses () [0x00022] in <reflectorTest>:188
  at (wrapper managed-to-native) System.Reflection.MonoMethod.InternalInvoke(System.Reflection.MonoMethod,object,object[],System.Exception&)
  at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x0003b] in /work/rpmbuild/BUILD/mono-5.16.0.179/mcs/class/corlib/System.Reflection/MonoMethod.cs:305

Note: Microsoft.Owin.Security.DataProtection.DpapiDataProtector can't be used at runtime, that is why we Dependency Inject it away with a replacement when running on mono.

@marek-safar

This comment has been minimized.

Copy link
Member

@marek-safar marek-safar commented Oct 12, 2018

@lambdageek please investigate the regression

lambdageek added a commit to lambdageek/mono that referenced this issue Oct 17, 2018
…ss_of

We must not get a TLE if referenced types are in an assembly that can't be
loaded.

Fixes mono#11123
luhenry added a commit that referenced this issue Oct 19, 2018
…ss_of (#11227)

We must not get a TLE if referenced types are in an assembly that can't be
loaded.

Fixes #11123
@marek-safar marek-safar reopened this Oct 19, 2018
lambdageek added a commit to lambdageek/mono that referenced this issue Oct 19, 2018
…ss_of

We must not get a TLE if referenced types are in an assembly that can't be
loaded.

Backported fix of mono#11123
monojenkins added a commit to monojenkins/mono that referenced this issue Oct 19, 2018
…ss_of

We must not get a TLE if referenced types are in an assembly that can't be
loaded.

Backported fix of mono#11123
monojenkins added a commit to monojenkins/mono that referenced this issue Oct 19, 2018
…ss_of

We must not get a TLE if referenced types are in an assembly that can't be
loaded.

Backported fix of mono#11123
marek-safar added a commit that referenced this issue Oct 22, 2018
…ss_of

We must not get a TLE if referenced types are in an assembly that can't be
loaded.

Backported fix of #11123
marek-safar added a commit that referenced this issue Oct 22, 2018
…ss_of

We must not get a TLE if referenced types are in an assembly that can't be
loaded.

Backported fix of #11123
marek-safar added a commit that referenced this issue Oct 22, 2018
…ss_of

We must not get a TLE if referenced types are in an assembly that can't be
loaded.

Backported fix of #11123
lambdageek added a commit to lambdageek/mono that referenced this issue Oct 22, 2018
Loading a type that has a field from an assembly that cannot be loaded should
still leave the type usable for some operations such as IsSubclassOf.
akoeplinger added a commit that referenced this issue Oct 24, 2018
Loading a type that has a field from an assembly that cannot be loaded should
still leave the type usable for some operations such as IsSubclassOf.
jonpryor added a commit to xamarin/xamarin-android that referenced this issue Oct 25, 2018
Fixes: mono/mono#11123
Fixes: mono/mono#11202
Fixes: mono/mono#6352
Fixes: xamarin/xamarin-macios#4984

Brings fixes to build 32-bit LLVM on 64-bit Linux hosts.
jonpryor added a commit to xamarin/xamarin-android that referenced this issue Dec 6, 2018
Bumps to mono/api-snapshot@b99fc87.
Bumps to mono/bockbuild@5af573e.
Bumps to mono/boringssl@41221b4.
Bumps to mono/corefx@23d0b58.
Bumps to mono/corert@af496fc.
Bumps to mono/linker@7af03ce.
Bumps to mono/NUnitLite@00e259a.
Bumps to mono/reference-assemblies@9325826.
Bumps to mono/roslyn-binaries@249709f.
Bumps to mono/xunit-binaries@bb58347.

	$ git diff --shortstat b63e5378..23f2024a      # mono 
	 1630 files changed, 50926 insertions(+), 92212 deletions(-)

Fixes: mono/mono#6352
Fixes: mono/mono#6947
Fixes: mono/mono#6992
Fixes: mono/mono#7615
Fixes: mono/mono#8340
Fixes: mono/mono#8407
Fixes: mono/mono#8575
Fixes: mono/mono#8627
Fixes: mono/mono#8707
Fixes: mono/mono#8766
Fixes: mono/mono#8848
Fixes: mono/mono#8866
Fixes: mono/mono#8935
Fixes: mono/mono#9010
Fixes: mono/mono#9023
Fixes: mono/mono#9031
Fixes: mono/mono#9033
Fixes: mono/mono#9106
Fixes: mono/mono#9109
Fixes: mono/mono#9155
Fixes: mono/mono#9179
Fixes: mono/mono#9232
Fixes: mono/mono#9234
Fixes: mono/mono#9262
Fixes: mono/mono#9277
Fixes: mono/mono#9292
Fixes: mono/mono#9318
Fixes: mono/mono#9318
Fixes: mono/mono#9332
Fixes: mono/mono#9407
Fixes: mono/mono#9421
Fixes: mono/mono#9505
Fixes: mono/mono#9542
Fixes: mono/mono#9581
Fixes: mono/mono#9623
Fixes: mono/mono#9684
Fixes: mono/mono#9750
Fixes: mono/mono#9753
Fixes: mono/mono#9772
Fixes: mono/mono#9839
Fixes: mono/mono#9869
Fixes: mono/mono#9921
Fixes: mono/mono#9943
Fixes: mono/mono#9947
Fixes: mono/mono#9973
Fixes: mono/mono#9996
Fixes: mono/mono#10000
Fixes: mono/mono#10031
Fixes: mono/mono#10035
Fixes: mono/mono#10227
Fixes: mono/mono#10243
Fixes: mono/mono#10303
Fixes: mono/mono#10448
Fixes: mono/mono#10483
Fixes: mono/mono#10488
Fixes: mono/mono#10863
Fixes: mono/mono#11123
Fixes: mono/mono#11138
Fixes? mono/mono#11146
Fixes: mono/mono#11202
Fixes: mono/mono#11378
Fixes: mono/mono#11479
Fixes: mono/mono#11613
Fixes: #1951
Fixes: xamarin/xamarin-macios#4347
Fixes: xamarin/xamarin-macios#4617
Fixes: xamarin/xamarin-macios#4984
jonpryor added a commit to xamarin/xamarin-android that referenced this issue Apr 24, 2019
Bumps to mono/api-snapshot@ae01378
Bumps to mono/reference-assemblies@e5173a5
Bumps to mono/bockbuild@d30329d
Bumps to mono/boringssl@3d87996
Bumps to mono/corefx@72f7d76
Bumps to mono/corert@1b7d4a1
Bumps to mono/helix-binaries@7e893ea
Bumps to mono/illinker-test-assets@f21ff68
Bumps to mono/linker@13d864e
Bumps to mono/llvm@1aaaaa5 [mono]
Bumps to mono/llvm@2c2cffe [xamarin-android]
Bumps to mono/NUnitLite@0029561
Bumps to mono/roslyn-binaries@0bbc9b4
Bumps to mono/xunit-binaries@8f6e62e

	$ git diff --shortstat 886c4901..e66c7667      # mono
        3597 files changed, 350850 insertions(+), 91128 deletions(-)
	$ git diff --shortstat 349752c464c5fc93b32e7d45825f2890c85c8b7d..2c2cffedf01e0fe266b9aaad2c2563e05b750ff4
	 240 files changed, 18562 insertions(+), 6581 deletions(-)

Context: dotnet/coreclr#22046

Fixes: CVE 2018-8292 on macOS
Fixes: http://work.devdiv.io/737323
Fixes: dotnet/corefx#33965
Fixes: dotnet/standard#642
Fixes: mono/mono#6997
Fixes: mono/mono#7326
Fixes: mono/mono#7517
Fixes: mono/mono#7750
Fixes: mono/mono#7859
Fixes: mono/mono#8360
Fixes: mono/mono#8460
Fixes: mono/mono#8766
Fixes: mono/mono#8922
Fixes: mono/mono#9418
Fixes: mono/mono#9507
Fixes: mono/mono#9951
Fixes: mono/mono#10024
Fixes: mono/mono#10030
Fixes: mono/mono#10038
Fixes: mono/mono#10448
Fixes: mono/mono#10735
Fixes: mono/mono#10735
Fixes: mono/mono#10737
Fixes: mono/mono#10743
Fixes: mono/mono#10834
Fixes: mono/mono#10837
Fixes: mono/mono#10838
Fixes: mono/mono#10863
Fixes: mono/mono#10945
Fixes: mono/mono#11020
Fixes: mono/mono#11021
Fixes: mono/mono#11021
Fixes: mono/mono#11049
Fixes: mono/mono#11091
Fixes: mono/mono#11095
Fixes: mono/mono#11123
Fixes: mono/mono#11138
Fixes: mono/mono#11146
Fixes: mono/mono#11202
Fixes: mono/mono#11214
Fixes: mono/mono#11317
Fixes: mono/mono#11326
Fixes: mono/mono#11378
Fixes: mono/mono#11385
Fixes: mono/mono#11478
Fixes: mono/mono#11479
Fixes: mono/mono#11488
Fixes: mono/mono#11489
Fixes: mono/mono#11527
Fixes: mono/mono#11529
Fixes: mono/mono#11596
Fixes: mono/mono#11603
Fixes: mono/mono#11613
Fixes: mono/mono#11623
Fixes: mono/mono#11663
Fixes: mono/mono#11681
Fixes: mono/mono#11684
Fixes: mono/mono#11693
Fixes: mono/mono#11697
Fixes: mono/mono#11779
Fixes: mono/mono#11809
Fixes: mono/mono#11858
Fixes: mono/mono#11895
Fixes: mono/mono#11898
Fixes: mono/mono#11898
Fixes: mono/mono#11965
Fixes: mono/mono#12182
Fixes: mono/mono#12193
Fixes: mono/mono#12218
Fixes: mono/mono#12235
Fixes: mono/mono#12263
Fixes: mono/mono#12307
Fixes: mono/mono#12331
Fixes: mono/mono#12362
Fixes: mono/mono#12374
Fixes: mono/mono#12402
Fixes: mono/mono#12421
Fixes: mono/mono#12461
Fixes: mono/mono#12479
Fixes: mono/mono#12479
Fixes: mono/mono#12552
Fixes: mono/mono#12603
Fixes: mono/mono#12747
Fixes: mono/mono#12831
Fixes: mono/mono#12843
Fixes: mono/mono#12881
Fixes: mono/mono#13030
Fixes: mono/mono#13284
Fixes: mono/mono#13297
Fixes: mono/mono#13455
Fixes: mono/mono#13460
Fixes: mono/mono#13478
Fixes: mono/mono#13479
Fixes: mono/mono#13522
Fixes: mono/mono#13607
Fixes: mono/mono#13610
Fixes: mono/mono#13610
Fixes: mono/mono#13639
Fixes: mono/mono#13672
Fixes: mono/mono#13834
Fixes: mono/mono#13878
Fixes: mono/mono#6352
Fixes: mono/monodevelop#6898
Fixes: xamarin/maccore#1069
Fixes: xamarin/maccore#1407
Fixes: xamarin/maccore#604
Fixes: xamarin/xamarin-macios#4984
Fixes: xamarin/xamarin-macios#5289
Fixes: xamarin/xamarin-macios#5363
Fixes: xamarin/xamarin-macios#5381
Fixes: https://issuetracker.unity3d.com/issues/editor-crashes-with-g-logv-when-entering-play-mode-with-active-flowcanvas-script
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.