TypeFactory.CreateTypeByCLRName cannot create resolved DataContractAttribute.

Hello. Trying to add DataContract attribute annotation to class via Quick fix, but it cannot resolve it and then create.

TypeFactory.CreateTypeByCLRName(new ClrTypeName(System.Runtime.Serialization.DataContractAttribute), provider.PsiModule);

This code returns object IsResolved = false so I cant create type with element factory. Same thing happens with DataMemberAttribute. But with somethins else like Object it works good. Whats wrong?

protected override Action<ITextControl> ExecutePsiTransaction(ISolution solution, IProgressIndicator progress)
{
var attributeType = typeof(DataContractAttribute);
var attributeDeclaredType = TypeFactory.CreateTypeByCLRName(new ClrTypeName(attributeType.FullName), provider.PsiModule);

var typeElement = attributeDeclaredType.GetTypeElement();

if (typeElement == null)
{
return null;
}

var attribute = elementFactory.CreateAttribute(typeElement);

selectedClass.AddAttributeBefore(attribute, null);

return null;
}
3 comments
Comment actions Permalink
Official comment

Alexander, necessary type must be in specified psi module or it's references closure.
Object is almost always is referenced from mscorlib.dll,
DataContractAttribute, which is from System.Runtime.Serialization.Primitives.dll, is not referenced in provided psi module.

Comment actions Permalink

So how can i reference it? Just adding nuget package is not working, how can reference it to use in unit tests on context actions and in plugin itself?

0
Comment actions Permalink

You mean not in test data but in tests themselves? 
Like any other regular nuget package.

0

Please sign in to leave a comment.