dspace-group/dscom

RegisterTypeForComClients fails when Type does not have a GuidAttribute

SWibbeke opened this issue · 1 comments

Using the method fails when the provided Type element has no CustomAttribute GuidAttribute.

RegisterTypeForComClients(Type type, ComTypes.RegistrationClassContext classContext, ComTypes.RegistrationConnectionType flags) 

An empty sequence exception is thrown by this line.

var guid = new Guid(type.GetCustomAttributes<GuidAttribute>().First().Value);

Using the RegistrationServices from System.Runtime.InteropServices the method works, the passed type object is the same and does also not contain a CustomAttribute GuidAttribute.

I did observer that the Type object has an assembly property. Looking into it the provided assembly has a GuidAttribute. Adjusting the code as such:

var guid = new Guid(type.Assembly.GetCustomAttributes<GuidAttribute>().First().Value);

The code works, and cross referencing with the source code the GUID is also correct.

The code should also check the Assembly for the GUID.
A more fitting Exception would be helpful if the GUID cannot be retrieved at all.