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

Fix nullable references #168

Merged
merged 10 commits into from
Nov 6, 2023
Merged

Fix nullable references #168

merged 10 commits into from
Nov 6, 2023

Conversation

mikeebowen
Copy link
Collaborator

This pull request fixes nullable reference errors in the samples and makes them executable with command line arguments.

@mikeebowen
Copy link
Collaborator Author

@twsouthwick, please review and make sure everything looks OK.

Copy link
Contributor

Learn Build status updates of commit ec2b10f:

✅ Validation status: passed

File Status Preview URL Details
samples/presentation/create_by_providing_a_file_name/cs/Program.cs ✅Succeeded
samples/presentation/retrieve_the_number_of_slides/cs/Program.cs ✅Succeeded
samples/spreadsheet/insert_a_new_worksheet/cs/Program.cs ✅Succeeded
samples/spreadsheet/merge_two_adjacent_cells/cs/Program.cs ✅Succeeded
samples/spreadsheet/open_for_read_only_access/cs/Program.cs ✅Succeeded
samples/spreadsheet/open_from_a_stream/cs/Program.cs ✅Succeeded
samples/spreadsheet/parse_and_read_a_large_spreadsheet/cs/Program.cs ✅Succeeded
samples/spreadsheet/retrieve_a_dictionary_of_all_named_ranges/cs/Program.cs ✅Succeeded
samples/spreadsheet/retrieve_a_list_of_the_hidden_rows_or_columns/cs/Program.cs ✅Succeeded
samples/spreadsheet/retrieve_a_list_of_the_hidden_worksheets/cs/Program.cs ✅Succeeded
samples/spreadsheet/retrieve_a_list_of_the_worksheets/cs/Program.cs ✅Succeeded
samples/word/accept_all_revisions/cs/Program.cs ✅Succeeded
samples/word/add_tables/cs/Program.cs ✅Succeeded
samples/word/change_text_a_table/cs/Program.cs ✅Succeeded
samples/word/change_the_print_orientation/cs/Program.cs ✅Succeeded
samples/word/convert_from_the_docm_to_the_docx_file_format/cs/Program.cs ✅Succeeded
samples/word/create_and_add_a_character_style/cs/Program.cs ✅Succeeded
samples/word/create_and_add_a_paragraph_style/cs/Program.cs ✅Succeeded
samples/word/delete_comments_by_all_or_a_specific_author/cs/Program.cs ✅Succeeded
samples/word/extract_styles/cs/Program.cs ✅Succeeded
samples/word/insert_a_comment/cs/Program.cs ✅Succeeded
samples/word/insert_a_picture/cs/Program.cs ✅Succeeded
samples/word/insert_a_table/cs/Program.cs ✅Succeeded
samples/word/remove_hidden_text/cs/Program.cs ✅Succeeded
samples/word/remove_the_headers_and_footers/cs/Program.cs ✅Succeeded

This comment lists only the first 25 files in the pull request.
For more details, please refer to the build report.

For any questions, please:

Copy link
Collaborator

@twsouthwick twsouthwick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - a few thoughts for patterns me want to do for later


private static void CreatePresentationParts(PresentationPart presentationPart)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is private removed?

Copy link
Collaborator Author

@mikeebowen mikeebowen Nov 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because with private set I get "CS0106: The modifier 'private' is not valid for this item" error from Visual Studio.

wordDoc.MainDocumentPart.WordprocessingCommentsPart;
if (wordDoc.MainDocumentPart is null || wordDoc.MainDocumentPart.WordprocessingCommentsPart is null)
{
throw new System.NullReferenceException("MainDocumentPart and/or WordprocessingCommentsPart is null.");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of nullreferenceexception, should throw InvalidOperation

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Collaborator

@twsouthwick twsouthwick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

throwing nullreferenceexception is probably not the right exception to throw when checking - maybe invalidoperationexception?

Copy link
Contributor

Learn Build status updates of commit 06a0984:

✅ Validation status: passed

File Status Preview URL Details
samples/presentation/create_by_providing_a_file_name/cs/Program.cs ✅Succeeded
samples/presentation/retrieve_the_number_of_slides/cs/Program.cs ✅Succeeded
samples/spreadsheet/insert_a_new_worksheet/cs/Program.cs ✅Succeeded
samples/spreadsheet/merge_two_adjacent_cells/cs/Program.cs ✅Succeeded
samples/spreadsheet/open_for_read_only_access/cs/Program.cs ✅Succeeded
samples/spreadsheet/open_from_a_stream/cs/Program.cs ✅Succeeded
samples/spreadsheet/parse_and_read_a_large_spreadsheet/cs/Program.cs ✅Succeeded
samples/spreadsheet/retrieve_a_dictionary_of_all_named_ranges/cs/Program.cs ✅Succeeded
samples/spreadsheet/retrieve_a_list_of_the_hidden_rows_or_columns/cs/Program.cs ✅Succeeded
samples/spreadsheet/retrieve_a_list_of_the_hidden_worksheets/cs/Program.cs ✅Succeeded
samples/spreadsheet/retrieve_a_list_of_the_worksheets/cs/Program.cs ✅Succeeded
samples/word/accept_all_revisions/cs/Program.cs ✅Succeeded
samples/word/add_tables/cs/Program.cs ✅Succeeded
samples/word/change_text_a_table/cs/Program.cs ✅Succeeded
samples/word/change_the_print_orientation/cs/Program.cs ✅Succeeded
samples/word/convert_from_the_docm_to_the_docx_file_format/cs/Program.cs ✅Succeeded
samples/word/create_and_add_a_character_style/cs/Program.cs ✅Succeeded
samples/word/create_and_add_a_paragraph_style/cs/Program.cs ✅Succeeded
samples/word/delete_comments_by_all_or_a_specific_author/cs/Program.cs ✅Succeeded
samples/word/extract_styles/cs/Program.cs ✅Succeeded
samples/word/insert_a_comment/cs/Program.cs ✅Succeeded
samples/word/insert_a_picture/cs/Program.cs ✅Succeeded
samples/word/insert_a_table/cs/Program.cs ✅Succeeded
samples/word/remove_hidden_text/cs/Program.cs ✅Succeeded
samples/word/remove_the_headers_and_footers/cs/Program.cs ✅Succeeded

This comment lists only the first 25 files in the pull request.
For more details, please refer to the build report.

For any questions, please:

@twsouthwick
Copy link
Collaborator

@mikeebowen I think the only blocking thing here is to remove the manual throwing of the NullReferenceExceptions. It would be nice to add using System. so we don't end up with System.ArgumentNullException as well

@mikeebowen
Copy link
Collaborator Author

Do you want to change all the NullReferenceExceptions to ArgumentNullException? Many of them are not null arguments, but possibly null parts and elements of the document.

@twsouthwick
Copy link
Collaborator

Do you want to change all the NullReferenceExceptions to ArgumentNullException? Many of them are not null arguments, but possibly null parts and elements of the document.

It is a big code smell to throw NullReferenceExceptions - you are supposed to throw ArgumentNullExceptions if you have something that should not be null but is. If you don't think that's appropriate, then you'll want to refactor things so that you don't need to throw either.

@lindalu-MSFT
Copy link
Collaborator

@twsouthwick Please ping me when all comments are resolved and you're ready to merge this PR! Thanks, Linda

Copy link
Contributor

Learn Build status updates of commit cac8345:

✅ Validation status: passed

File Status Preview URL Details
samples/presentation/add_comment/cs/Program.cs ✅Succeeded
samples/presentation/create_by_providing_a_file_name/cs/Program.cs ✅Succeeded
samples/presentation/retrieve_the_number_of_slides/cs/Program.cs ✅Succeeded
samples/spreadsheet/insert_a_new_worksheet/cs/Program.cs ✅Succeeded
samples/spreadsheet/merge_two_adjacent_cells/cs/Program.cs ✅Succeeded
samples/spreadsheet/open_for_read_only_access/cs/Program.cs ✅Succeeded
samples/spreadsheet/open_from_a_stream/cs/Program.cs ✅Succeeded
samples/spreadsheet/parse_and_read_a_large_spreadsheet/cs/Program.cs ✅Succeeded
samples/spreadsheet/retrieve_a_dictionary_of_all_named_ranges/cs/Program.cs ✅Succeeded
samples/spreadsheet/retrieve_a_list_of_the_hidden_rows_or_columns/cs/Program.cs ✅Succeeded
samples/spreadsheet/retrieve_a_list_of_the_hidden_worksheets/cs/Program.cs ✅Succeeded
samples/spreadsheet/retrieve_a_list_of_the_worksheets/cs/Program.cs ✅Succeeded
samples/word/accept_all_revisions/cs/Program.cs ✅Succeeded
samples/word/add_tables/cs/Program.cs ✅Succeeded
samples/word/change_text_a_table/cs/Program.cs ✅Succeeded
samples/word/change_the_print_orientation/cs/Program.cs ✅Succeeded
samples/word/convert_from_the_docm_to_the_docx_file_format/cs/Program.cs ✅Succeeded
samples/word/create_and_add_a_character_style/cs/Program.cs ✅Succeeded
samples/word/create_and_add_a_paragraph_style/cs/Program.cs ✅Succeeded
samples/word/delete_comments_by_all_or_a_specific_author/cs/Program.cs ✅Succeeded
samples/word/extract_styles/cs/Program.cs ✅Succeeded
samples/word/insert_a_comment/cs/Program.cs ✅Succeeded
samples/word/insert_a_picture/cs/Program.cs ✅Succeeded
samples/word/insert_a_table/cs/Program.cs ✅Succeeded
samples/word/remove_hidden_text/cs/Program.cs ✅Succeeded

This comment lists only the first 25 files in the pull request.
For more details, please refer to the build report.

For any questions, please:

Copy link
Contributor

Learn Build status updates of commit c9a56a3:

✅ Validation status: passed

File Status Preview URL Details
samples/presentation/add_comment/cs/Program.cs ✅Succeeded
samples/presentation/create_by_providing_a_file_name/cs/Program.cs ✅Succeeded
samples/presentation/retrieve_the_number_of_slides/cs/Program.cs ✅Succeeded
samples/spreadsheet/insert_a_new_worksheet/cs/Program.cs ✅Succeeded
samples/spreadsheet/merge_two_adjacent_cells/cs/Program.cs ✅Succeeded
samples/spreadsheet/open_for_read_only_access/cs/Program.cs ✅Succeeded
samples/spreadsheet/open_from_a_stream/cs/Program.cs ✅Succeeded
samples/spreadsheet/parse_and_read_a_large_spreadsheet/cs/Program.cs ✅Succeeded
samples/spreadsheet/retrieve_a_dictionary_of_all_named_ranges/cs/Program.cs ✅Succeeded
samples/spreadsheet/retrieve_a_list_of_the_hidden_rows_or_columns/cs/Program.cs ✅Succeeded
samples/spreadsheet/retrieve_a_list_of_the_hidden_worksheets/cs/Program.cs ✅Succeeded
samples/spreadsheet/retrieve_a_list_of_the_worksheets/cs/Program.cs ✅Succeeded
samples/word/accept_all_revisions/cs/Program.cs ✅Succeeded
samples/word/add_tables/cs/Program.cs ✅Succeeded
samples/word/change_text_a_table/cs/Program.cs ✅Succeeded
samples/word/change_the_print_orientation/cs/Program.cs ✅Succeeded
samples/word/convert_from_the_docm_to_the_docx_file_format/cs/Program.cs ✅Succeeded
samples/word/create_and_add_a_character_style/cs/Program.cs ✅Succeeded
samples/word/create_and_add_a_paragraph_style/cs/Program.cs ✅Succeeded
samples/word/delete_comments_by_all_or_a_specific_author/cs/Program.cs ✅Succeeded
samples/word/extract_styles/cs/Program.cs ✅Succeeded
samples/word/insert_a_comment/cs/Program.cs ✅Succeeded
samples/word/insert_a_picture/cs/Program.cs ✅Succeeded
samples/word/insert_a_table/cs/Program.cs ✅Succeeded
samples/word/remove_hidden_text/cs/Program.cs ✅Succeeded

This comment lists only the first 25 files in the pull request.
For more details, please refer to the build report.

For any questions, please:

Copy link
Contributor

Learn Build status updates of commit dd2e343:

✅ Validation status: passed

File Status Preview URL Details
samples/presentation/add_comment/cs/Program.cs ✅Succeeded
samples/presentation/create_by_providing_a_file_name/cs/Program.cs ✅Succeeded
samples/presentation/retrieve_the_number_of_slides/cs/Program.cs ✅Succeeded
samples/spreadsheet/insert_a_new_worksheet/cs/Program.cs ✅Succeeded
samples/spreadsheet/merge_two_adjacent_cells/cs/Program.cs ✅Succeeded
samples/spreadsheet/open_for_read_only_access/cs/Program.cs ✅Succeeded
samples/spreadsheet/open_from_a_stream/cs/Program.cs ✅Succeeded
samples/spreadsheet/parse_and_read_a_large_spreadsheet/cs/Program.cs ✅Succeeded
samples/spreadsheet/retrieve_a_dictionary_of_all_named_ranges/cs/Program.cs ✅Succeeded
samples/spreadsheet/retrieve_a_list_of_the_hidden_rows_or_columns/cs/Program.cs ✅Succeeded
samples/spreadsheet/retrieve_a_list_of_the_hidden_worksheets/cs/Program.cs ✅Succeeded
samples/spreadsheet/retrieve_a_list_of_the_worksheets/cs/Program.cs ✅Succeeded
samples/word/accept_all_revisions/cs/Program.cs ✅Succeeded
samples/word/add_tables/cs/Program.cs ✅Succeeded
samples/word/change_text_a_table/cs/Program.cs ✅Succeeded
samples/word/change_the_print_orientation/cs/Program.cs ✅Succeeded
samples/word/convert_from_the_docm_to_the_docx_file_format/cs/Program.cs ✅Succeeded
samples/word/create_and_add_a_character_style/cs/Program.cs ✅Succeeded
samples/word/create_and_add_a_paragraph_style/cs/Program.cs ✅Succeeded
samples/word/delete_comments_by_all_or_a_specific_author/cs/Program.cs ✅Succeeded
samples/word/extract_styles/cs/Program.cs ✅Succeeded
samples/word/insert_a_comment/cs/Program.cs ✅Succeeded
samples/word/insert_a_picture/cs/Program.cs ✅Succeeded
samples/word/insert_a_table/cs/Program.cs ✅Succeeded
samples/word/remove_hidden_text/cs/Program.cs ✅Succeeded

This comment lists only the first 25 files in the pull request.
For more details, please refer to the build report.

For any questions, please:

Copy link
Collaborator

@twsouthwick twsouthwick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM thanks for responding to the feedback!

@lindalu-MSFT this can be merged now

@twsouthwick
Copy link
Collaborator

@lindalu-MSFT is there a staging build we can use to see the final output as we work through the items in #159 ?

@lindalu-MSFT
Copy link
Collaborator

lindalu-MSFT commented Nov 2, 2023

@twsouthwick is there a staging build we can use to see the final output as we work through the items in #159 ?

I don't know about .cs code, but for docs, you go to the live location you want to review the changes and insert "review." at the front of the URL. For example, https://learn.microsoft.com/en-us/office/open-xml/open-xml-sdk becomes https://review.learn.microsoft.com/en-us/office/open-xml/open-xml-sdk.

@twsouthwick
Copy link
Collaborator

@twsouthwick is there a staging build we can use to see the final output as we work through the items in #159 ?

I don't know about .cs code, but for docs, you go to the live location you want to review the changes and insert "review." at the front of the URL. For example, https://learn.microsoft.com/en-us/office/open-xml/open-xml-sdk becomes https://review.learn.microsoft.com/en-us/office/open-xml/open-xml-sdk.

Perfect! The code gets pulled in via includes, so they'll show up there and we can validate things actually look right (we can only get so far with the docfx cli)

@twsouthwick twsouthwick merged commit 31df81d into OfficeDev:main Nov 6, 2023
2 checks passed
@lindalu-MSFT
Copy link
Collaborator

@twsouthwick Please resolve these merge conflicts then I will merge to live.
#174

@mikeebowen mikeebowen deleted the fix-nullable-references branch November 14, 2023 17:46
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

Successfully merging this pull request may close these issues.

4 participants