locked
CS0144: Cannot create an instance of the abstract class or interface RRS feed

  • Question

  • User-718146471 posted

    Hey guys, I'm trying to create a word auto-filler application from some source code a friend gave me. It starts to compile but runs into this error:

    CS0144: Cannot create an instance of the abstract class or interface 'Microsoft.Office.Interop.Word.Application'

    I really don't see what is wrong so any advice here would be most appreciated. Here is the code:

    Code behind page:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Microsoft.Office.Interop.Word;
    
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
    
        }
        protected void MyDropDownList_SelectedIndexChanged(object sender, EventArgs e)
        {
    
    // Lines that mention ap is where it complains
    Application ap = new Application();
            ap.Visible = true; 
            Document doc = ap.Documents.Add(@"C:\Quick Look Template.dotx", Visible: true);
            doc.Activate();
    
            string document1 = ((DropDownList)FindControl("Document1")).SelectedValue;
            Range oRng = doc.Bookmarks.get_Item("bookmark1").Range;
            oRng.Text = "Bookmark #1";
    
            string document2 = ((DropDownList)FindControl("Document2")).SelectedValue;
            Range oRng2 = doc.Bookmarks.get_Item("bookmark2").Range;
            oRng.Text = "Bookmark #2";
    
            string document3 = ((DropDownList)FindControl("Document3")).SelectedValue;
    
            Range oRng3 = doc.Bookmarks.get_Item("bookmark3").Range;
            oRng.Text = "Bookmark #3";
    
        }
    }


     

    UI:

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:DropDownList ID="MyDropDownList" runat="server" AutoPostBack="True" 
                onselectedindexchanged="MyDropDownList_SelectedIndexChanged">
                <asp:ListItem Selected="True">Choose Document</asp:ListItem>
                <asp:ListItem Value="Document1">Document1</asp:ListItem>
                <asp:ListItem Value="Document2">Document2</asp:ListItem>
                <asp:ListItem Value="Document3">Document3</asp:ListItem>
            </asp:DropDownList>
        </div>
        </form>
    </body>
    </html>
    


     

    Friday, October 8, 2010 9:52 AM

Answers

  • User-1178707375 posted

    I believe you will not get this error if you use:

    ApplicationClass app = new ApplicationClass();

    instead of Application ap = new Application();  

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, October 12, 2010 2:08 PM

All replies

  • User-1178707375 posted

    I believe you will not get this error if you use:

    ApplicationClass app = new ApplicationClass();

    instead of Application ap = new Application();  

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, October 12, 2010 2:08 PM
  • User-718146471 posted

    It was the version of the word interop that I was using. I ended up using the older one and I didn't get the error anymore. Thanks.

    Thursday, October 14, 2010 7:32 AM