MonoGame icon indicating copy to clipboard operation
MonoGame copied to clipboard

Fixed _isRunningOnNetCore bug in ContentTypeReaderManager.cs

Open eosxff opened this issue 3 years ago • 6 comments

System.Private.CoreLib is an assembly, so Type.GetType("System.Private.CoreLib") always returned null. typeof(object).Assembly.GetName().Name == "System.Private.CoreLib" should fulfill the role the other line had intended to accomplish.

This should close #7872

eosxff avatar Aug 02 '22 02:08 eosxff

I guess my IDE also picked up on some trailing whitespace in comments and removed those as well

eosxff avatar Aug 02 '22 02:08 eosxff

I suspect that Assembly.GetName() might not work with NativeAOT and will crash, it's a case where Assembly or Name might be null on that runtime.

ThomasFOG avatar Aug 02 '22 06:08 ThomasFOG

We should probably also reverse the check, that is have the condition be by default true, otherwise if mscorlib is available, set it to false.

harry-cpp avatar Aug 02 '22 06:08 harry-cpp

typeof(object).Assembly.GetName().Name works as intended in NativeAOT

eosxff avatar Aug 02 '22 06:08 eosxff

@harry-cpp if it's not System.Private.CoreLib shouldn't it be mscorlib then? Is there a reason reversing it is better?

eosxff avatar Aug 02 '22 07:08 eosxff

If I had originally written Type.GetType("mscorlib") == null instead, it would be forward compatible in case the check itself failed, tho now that I think about it, I do remembered why I chose to check for System.Private.CoreLib originally, it was to ensure I don't break something on the console side.

You don't need to reverse the condition, it'll be fine.

harry-cpp avatar Aug 02 '22 10:08 harry-cpp