-
-
Notifications
You must be signed in to change notification settings - Fork 231
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
GetAssemblyTypesWithDynamicLinqTypeAttribute fails to type load failures #702
Comments
@philr Did you encounter this issue in your application, or did you check the source code? Because the logic in the code is that if an assembly cannot be loaded, the |
I encountered this in a .NET Framework 4.7.2 application. System.Linq.Dynamic.Core is being called from within a sandboxed application domain where the not all of the dependencies of an assembly are available. None of the types marked with
The fix seems to be to use I've created a custom provider as a workaround for now: class CustomDynamicLinqCustomTypeProvider : DefaultDynamicLinqCustomTypeProvider
{
private HashSet<Type> _customTypes;
public CustomDynamicLinqCustomTypeProvider() : base(false)
{
}
public override HashSet<Type> GetCustomTypes()
{
if (_customTypes == null)
{
var customTypes = base.GetCustomTypes();
Type[] types;
try
{
types = typeof(TypeFromMyAssembly).Assembly.GetTypes();
}
catch (ReflectionTypeLoadException e)
{
types = e.Types;
}
foreach (var type in types.Where(t => t != null && t.IsPublic && t.GetCustomAttribute<DynamicLinqTypeAttribute>() != null))
{
customTypes.Add(type);
}
_customTypes = customTypes;
}
return _customTypes;
}
}
ParsingConfig.Default.CustomTypeProvider = new CustomDynamicLinqCustomTypeProvider(); |
@philr |
@StefH I've added a review to the PR with a few comments. |
For .NET Framework,
AbstractDynamicLinqCustomTypeProvider.GetAssemblyTypesWithDynamicLinqTypeAttribute()
callsAssembly.GetExportedTypes()
and handles a resultingReflectionTypeLoadException
.Assembly.GetExportedTypes()
will actually throwFileNotFoundException
if an assembly cannot be loaded.ReflectionTypeLoadException
is only thrown byAssembly.GetTypes()
.As a result, if there's a failure loading a type caused by a missing assembly, none of the types marked with
DynamicLinqTypeAttribute
in the assembly will be returned.The text was updated successfully, but these errors were encountered: