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

Improve : throw TypeLoadException on failing to load a type #7851

Merged
merged 2 commits into from
Jul 13, 2022

Conversation

wangjia184
Copy link

@wangjia184 wangjia184 commented Jul 11, 2022

Currently when Orleans fails to load a type, the exception only contains information of missing assembly.
This PR catches exception on Assembly.Load and attach the failed type information in message so it is more helpful.

My grain was throwing a customized type exception, and the exception type cannot be found and caused this error. The improved error message helps to locate the problem.

System.IO.FileNotFoundException: Could not load file or assembly 'XXX, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.

      File name: 'XXX, Culture=neutral, PublicKeyToken=null'
         at System.Reflection.RuntimeAssembly.InternalLoad(ObjectHandleOnStack assemblyName, ObjectHandleOnStack requestingAssembly, StackCrawlMarkHandle stackMark, Boolean throwOnFileNotFound, ObjectHandleOnStack assemblyLoadContext, ObjectHandleOnStack retAssembly)
         at System.Reflection.RuntimeAssembly.InternalLoad(AssemblyName assemblyName, RuntimeAssembly requestingAssembly, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, AssemblyLoadContext assemblyLoadContext)
         at System.Reflection.Assembly.Load(AssemblyName assemblyRef)
         at Orleans.Runtime.CachedTypeResolver.<>c__DisplayClass7_0.<TryPerformUncachedTypeResolution>g__ResolveAssembly|0(AssemblyName assemblyName) in /_/src/Orleans.Core/AssemblyLoader/CachedTypeResolver.cs:line 89
         at System.TypeNameParser.ResolveAssembly(String asmName, Func`2 assemblyResolver, Boolean throwOnError, StackCrawlMark& stackMark)
         at System.TypeNameParser.ConstructType(Func`2 assemblyResolver, Func`4 typeResolver, Boolean throwOnError, Boolean ignoreCase, StackCrawlMark& stackMark)
         at System.TypeNameParser.GetType(String typeName, Func`2 assemblyResolver, Func`4 typeResolver, Boolean throwOnError, Boolean ignoreCase, StackCrawlMark& stackMark)
         at System.Type.GetType(String typeName, Func`2 assemblyResolver, Func`4 typeResolver, Boolean throwOnError)
         at Orleans.Runtime.CachedTypeResolver.TryPerformUncachedTypeResolution(String fullName, Type& type, Assembly[] assemblies) in /_/src/Orleans.Core/AssemblyLoader/CachedTypeResolver.cs:line 62
         at Orleans.Runtime.CachedTypeResolver.TryPerformUncachedTypeResolution(String name, Type& type) in /_/src/Orleans.Core/AssemblyLoader/CachedTypeResolver.cs:line 36
         at Orleans.Runtime.CachedTypeResolver.TryResolveType(String name, Type& type) in /_/src/Orleans.Core/AssemblyLoader/CachedTypeResolver.cs:line 27
         at Orleans.Serialization.TypeSerializer.GetTypeFromName(String assemblyQualifiedTypeName, Boolean throwOnError) in /_/src/Orleans.Core/Serialization/TypeSerializer.cs:line 108
         at Orleans.Serialization.ILBasedExceptionSerializer.Deserialize(Type expectedType, IDeserializationContext outerContext) in /_/src/Orleans.Core/Serialization/ILBasedExceptionSerializer.cs:line 172
         at Orleans.Serialization.SerializationManager.FallbackDeserializer(IDeserializationContext context, Type expectedType) in /_/src/Orleans.Core/Serialization/SerializationManager.cs:line 1686
         at Orleans.Serialization.SerializationManager.DeserializeInner[TContext,TReader](SerializationManager sm, Type expected, TContext context, TReader reader) in /_/src/Orleans.Core/Serialization/SerializationManager.cs:line 1281
         at Orleans.Serialization.BuiltInTypes.DeserializeOrleansResponse(Type expected, IDeserializationContext context) in /_/src/Orleans.Core/Serialization/BuiltInTypes.cs:line 2135
         at Orleans.Serialization.SerializationManager.DeserializeInner[TContext,TReader](SerializationManager sm, Type expected, TContext context, TReader reader) in /_/src/Orleans.Core/Serialization/SerializationManager.cs:line 1349
         at Orleans.Runtime.Messaging.MessageSerializer.OrleansSerializer`1.Deserialize(ReadOnlySequence`1 input, T& value) in /_/src/Orleans.Core/Messaging/MessageSerializer.cs:line 151
         at Orleans.Runtime.Messaging.MessageSerializer.TryRead(ReadOnlySequence`1& input, Message& message) in /_/src/Orleans.Core/Messaging/MessageSerializer.cs:line 76
         at Orleans.Runtime.Messaging.Connection.ProcessIncoming() in /_/src/Orleans.Core/Networking/Connection.cs:line 358
         at Orleans.Internal.OrleansTaskExtentions.<ToTypedTask>g__ConvertAsync|4_0[T](Task`1 asyncTask) in /_/src/Orleans.Core/Async/TaskExtensions.cs:line 101
Microsoft Reviewers: Open in CodeFlow

@ReubenBond ReubenBond self-assigned this Jul 11, 2022
@ReubenBond ReubenBond merged commit be0bc24 into dotnet:3.x Jul 13, 2022
ReubenBond pushed a commit that referenced this pull request Jun 5, 2023
…riendly exception during deserialization (#8463)

Co-authored-by: Emeric Kwemou Ngandeu <emeric.kwemou_ngandeu@siemens.com>
@github-actions github-actions bot locked and limited conversation to collaborators Dec 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants