ServiceStack: Upgrade to 5.4.1 gives me Reflection

2019-07-31 11:13发布

问题:

I was running ServiceStack 5.2.0, until I upgraded due to this answer.

After doing that, and running the application again, I now get ReflectionTypeLoadException, when processing the Assembly ServiceStack.Common, Version=5.0.0.0, Culture=neutral, PublicKeyToken=02c12cbda47e6587.

In my code, for some reason irrelevant to this question, I do the following:

Type[] typeArray = assembly.GetTypes();

and when I do, I get this error:

{"Method 'GetKeyValuePairs' in type 'ServiceStack.SimpleAppSettings' from assembly 'ServiceStack.Common, Version=5.0.0.0, Culture=neutral, PublicKeyToken=02c12cbda47e6587' does not have an implementation.":"ServiceStack.SimpleAppSettings"}

I thought "lets avoid processing Servicestack, as its not really what Im after anyway here, so I changed it to:

if (!assembly.DefinedTypes.Any(x => x.FullName.StartsWith("SomeThing")))

but I still get the same error when execution hits this line.

UPDATE

After upgrading, I actually see LoaderExceptions elsewhere too =(

System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information. at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module) at System.Reflection.RuntimeModule.GetTypes() at System.Reflection.Assembly.GetTypes() at tWorks.Core.CoreServerCommons.RequestProcessing.RequestProcessorFactory`2.<>c.b__8_0(Assembly assembly) in ....RequestProcessorFactory.cs:line 105

Something happened to some underlying library? Hmm.

回答1:

As Mythz said in the comments here, all that was needed to do, was to clear the NuGet cache:

VS --> Tools --> NuGet Packet Manager --> Packet Manager Settings --> Clear All NuGet Caches(s)