SharePoint Online theme error – There was an error while attempting to get the themes

Microsoft SharePoint Logo Recently when I was trying to change the theme of a SharePoint online site collection, it threw an error “There was an error while attempting to get the themes”

The error looks like the one shown below (Taken from Microsoft Tech Community)

There was an error while attempting to get the themes

To fix this error, the easiest method as of March 2020 is do the following.

  1. Click on “Classic change the look options” menu item shown in the screenshot above.
  2. Choose one of the theme.
  3. Preview it by clicking on “Try it out”.
  4. Then click on “Yes, keep it”
  5. Again load the home page
  6. Try changing the theme, and the error should be gone.

Thanks to Rob for providing the work around here.

SharePoint Error – Code blocks are not allowed in this file

When I was adding an in-line code into master page I was getting the following error.

An error occurred during the processing of /sites/<collection>/SitePages/Welcome.master. Code blocks are not allowed in this file.

The fix is add the following code to the web.config of the web application which hosts the site collection.



The Controls collection cannot be modified because the control contains code blocks (i.e. ).

While I was writing an in-line code with javascript inside the master page I was constantly facing the following exception.

The Controls collection cannot be modified because the control contains code blocks (i.e. <% … %>).

Welcome, <script type=”text/javascript”>var loginName = “<%= SPContext.Current.Web.CurrentUser.Name %>”;document.write(loginName);</script>

Found out that the javascript with c# code needs to be out of the tag which has runat=”server”. After checking the code I re-wrote the code into 2 pieces

<script type=”text/javascript”>var loginName = “<%= Microsoft.SharePoint.SPContext.Current.Web.CurrentUser.Name %>”;</script>

The above code I moved out of the “<form runat=”server”…” code and the below code inside the required location.

<span>Welcome, <script type=”text/javascript”>document.write(loginName);</script></span>

Now the page is rendered properly.

 

SharePoint Error – An unexpected error has occurred

While I was modifying SharePoint’s master page to put an inline code, I was constantly redirected to SharePoint Error Page “An unexpected error has occurred”.

After spending nearly an hour to get a clue from EventLog and other sources, I found out that by adding the following config codes to web.config of the web application where the site collection resides, we can see the ASP.NET error page with detailed information.

<SafeMode MaxControls=”200″ CallStack=”true”>
<customErrors mode=”Off”/>