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

Try set custom clipboard format with string data might lead to exception due to ClipCorrespondingTypeAttribute is null #389

Closed
zhuxb711 opened this issue Apr 14, 2023 · 1 comment

Comments

@zhuxb711
Copy link

Example:

IDataObject DataObject = NativeClipboard.CreateEmptyDataObject();
DataObject.SetData("MyCustomFormat", "My Custom String"); //Throw in here
NativeClipboard.SetDataObject(DataObject);

private static Encoding GetEncoding(ClipCorrespondingTypeAttribute attr) => (Encoding)Activator.CreateInstance(attr.EncodingType ?? typeof(UnicodeEncoding));

Replace "attr.EncodingType" with "attr?.EncodingType" should help fix this issue. Variable "attr" might be null in this case.

private static Encoding GetEncoding(ClipCorrespondingTypeAttribute attr) => (Encoding)Activator.CreateInstance(attr?.EncodingType ?? typeof(UnicodeEncoding)); 
@zhuxb711
Copy link
Author

Looking forward to your new version 3.4.14~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants