You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

Outlook Web Add-in清单添加Events扩展点后触发‘Invalid xsi:type=Event’错误

Fixing "Invalid xsi:type=Event" Error for Outlook Web Add-in ItemSend Extension Point

Let’s break down how to resolve this issue step by step—this is a common gotcha with Outlook add-in manifest structure, especially when working with event-based extensions like ItemSend.

Why You’re Seeing the Error

The Invalid xsi:type=Event error happens because the Events extension point isn’t placed correctly in the manifest. Outlook requires event handlers to be nested within VersionOverrides blocks (specifically VersionOverridesV1_1 for modern clients), rather than directly in the base manifest. Adding a top-level VersionOverrides tag is the right first step, but improper nesting or missing namespace declarations often cause follow-up compile issues.

Step 1: Correct Manifest Structure

Here’s the proper way to embed the ItemSend event in your manifest, with all required namespace and nesting rules:

<?xml version="1.0" encoding="UTF-8"?>
<OfficeApp xmlns="http://schemas.microsoft.com/office/appforoffice/1.1"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:bt="http://schemas.microsoft.com/office/officeappbasictypes/1.0"
  xsi:type="MailApp">

  <!-- Your base manifest config (ID, name, version, permissions, etc.) -->

  <VersionOverrides xmlns="http://schemas.microsoft.com/office/mailappversionoverrides" xsi:type="VersionOverridesV1_0">
    <VersionOverrides xmlns="http://schemas.microsoft.com/office/mailappversionoverrides/1.1" xsi:type="VersionOverridesV1_1">
      <Hosts>
        <Host xsi:type="MailHost">
          <DesktopFormFactor>
            <!-- Add other extension points (like CommandSurface) here if needed -->
            <ExtensionPoints>
              <ExtensionPoint xsi:type="Events">
                <Event Type="ItemSend" FunctionExecution="synchronous" FunctionName="validateBody" />
              </ExtensionPoint>
            </ExtensionPoints>
          </DesktopFormFactor>
        </Host>
      </Hosts>
    </VersionOverrides>
  </VersionOverrides>
</OfficeApp>

Key things to note:

  • The Events extension point lives inside VersionOverridesV1_1HostsMailHostDesktopFormFactorExtensionPoints.
  • Ensure the root OfficeApp tag includes the xsi namespace (xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"), which is required for validating xsi:type attributes.

Step 2: Troubleshoot Compilation Issues

If adding the correct VersionOverrides structure breaks compilation, check these common culprits:

  1. XML Syntax Errors

    • Double-check for unclosed tags, typos in attribute names (e.g., FunctionExectuion instead of FunctionExecution), or missing quotes around values.
    • Use an XML validator (many code editors have built-in tools) to catch syntax issues.
  2. Missing Function Implementation

    • Confirm the validateBody function exists in your specified JavaScript file (usually commands.js for Yeoman-generated projects) and has the correct signature:
      function validateBody(event) {
        // Your validation logic goes here
        const mailboxItem = Office.context.mailbox.item;
        
        // Example: Check if body contains forbidden text
        mailboxItem.body.getAsync("text", (asyncResult) => {
          if (asyncResult.status === Office.AsyncResultStatus.Succeeded) {
            if (asyncResult.value.includes("confidential")) {
              event.completed({ allowEvent: false }); // Block send
            } else {
              event.completed({ allowEvent: true }); // Allow send
            }
          } else {
            event.completed({ allowEvent: true }); // Fallback to allow send
          }
        });
      }
      
    • Even though the manifest specifies synchronous, Outlook Web Add-ins require you to call event.completed() to signal the end of your validation logic.
  3. Manifest Validation Failures

    • If you’re using the Yeoman Outlook Add-in template, run npm run validate to check for manifest compliance with Office’s schema.
    • For manual builds, use the Office Add-in Manifest Validator tool to catch schema violations.

Final Checks

  • Ensure your add-in’s permissions include ReadWriteItem (required to access the email body during ItemSend).
  • Test the add-in in Outlook Web App to confirm the ItemSend trigger works as expected.

内容的提问来源于stack exchange,提问作者Jaydev Solanki

火山引擎 最新活动