OYIon / LiveSharp

Public repository for the LiveSharp project
96 stars 4 forks source link

Use Types-Property of RelfectionTypeLoadException in LiveSharp.ServerClient.KnownTypes.EnsureTypesLoaded() #82

Closed warappa closed 4 years ago

warappa commented 4 years ago

Using LiveSharp 1.5.53

While trying the fix for #79 , I stumbled over an exception message in the output (it was in another repository, not the repo in #79).

If I make a small change (return different string value) in the controller-action of the out-of-the-box api/SampleData/WeatherForecasts route on the host server app, I get an ReflectionTypeLoadException exception and cannot debug this controller-action anymore (as opposed to before the edit):

received C# update
Exception thrown: 'System.Reflection.ReflectionTypeLoadException' in System.Private.CoreLib.dll
error: Failed to load assembly types from IdentityServer4.EntityFramework.Storage, Version=3.0.0.0, Culture=neutral, PublicKeyToken=f294d0afe402bb2b: 
System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types.
Method 'GetAllAsync' in type 'IdentityServer4.EntityFramework.Stores.PersistedGrantStore' from assembly 'IdentityServer4.EntityFramework.Storage, Version=3.0.0.0, Culture=neutral, PublicKeyToken=f294d0afe402bb2b' does not have an implementation.
Method 'FindIdentityResourcesByScopeNameAsync' in type 'IdentityServer4.EntityFramework.Stores.ResourceStore' from assembly 'IdentityServer4.EntityFramework.Storage, Version=3.0.0.0, Culture=neutral, PublicKeyToken=f294d0afe402bb2b' does not have an implementation.
   at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
   at System.Reflection.RuntimeAssembly.get_DefinedTypes()
   at LiveSharp.ServerClient.KnownTypes.EnsureTypesLoaded()
System.TypeLoadException: Method 'GetAllAsync' in type 'IdentityServer4.EntityFramework.Stores.PersistedGrantStore' from assembly 'IdentityServer4.EntityFramework.Storage, Version=3.0.0.0, Culture=neutral, PublicKeyToken=f294d0afe402bb2b' does not have an implementation.
System.TypeLoadException: Method 'FindIdentityResourcesByScopeNameAsync' in type 'IdentityServer4.EntityFramework.Stores.ResourceStore' from assembly 'IdentityServer4.EntityFramework.Storage, Version=3.0.0.0, Culture=neutral, PublicKeyToken=f294d0afe402bb2b' does not have an implementation.
Received update for method MemoryCacheTicketStore..ctor
Received update for method MemoryCacheTicketStore.StoreAsync
Received update for method MemoryCacheTicketStore.RenewAsync
...

I don't know if LiveSharp does even support debugging (hitting breakpoints) after edits, (LiveSharp supports breakpoints after edits 😀) but nonetheless LiveSharp.Runtime.dll's LiveSharp.ServerClient.KnownTypes.EnsureTypesLoaded may take advantage of the Types property in ReflectionTypeLoadException, which contains the types it still was able to load (attention: Types may contain null values!).

While the breakpoint-not-hit is another bug missing feature, I guess he more loaded types the merrier, right? 😉

ionoy commented 4 years ago

Could you send me this sample app? I don't think I have the same project structure in Rider.

Thanks!

ionoy commented 4 years ago

LiveSharp is now loading ReflectionTypeLoadException.Types. But I'm not sure that this will somehow help with the debugging. LiveSharp doesn't support debugging of the updated code since there is no mapping from the compiled Expression Tree to .cs.