我花了很多时间在我的开发箱上编写该程序,将其移至生产箱后,出现以下错误。仅供引用,我对安装的内容和可以安装的内容没有任何控制权,我该如何进行这项工作?在两台计算机上的两个框架下,我们都有v1.0.3705,v1.1.4322,v2.0.50727,v3.0,v3.5、4.0.30319。我用来创建应用程序的程序也是Visual Studio 2013 Pro。

谢谢


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using Word = Microsoft.Office.Interop.Word;
using Microsoft.Office.Interop.Word;


namespace C_Sharp_version
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void FindAndReplace(Microsoft.Office.Interop.Word.Application doc, object findText, object replaceWithText)
        {
            //options
            object matchCase = false;
            object matchWholeWord = true;
            object matchWildCards = false;
            object matchSoundsLike = false;
            object matchAllWordForms = false;
            object forward = true;
            object format = false;
            object matchKashida = false;
            object matchDiacritics = false;
            object matchAlefHamza = false;
            object matchControl = false;
            object read_only = false;
            object visible = true;
            object replace = 2;
            object wrap = 1;
            //execute find and replace
            doc.Selection.Find.Execute(ref findText, ref matchCase, ref matchWholeWord,
                ref matchWildCards, ref matchSoundsLike, ref matchAllWordForms, ref forward, ref wrap, ref format, ref replaceWithText, ref replace,
                ref matchKashida, ref matchDiacritics, ref matchAlefHamza, ref matchControl);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog openInfDoc = new OpenFileDialog();

            if (openInfDoc.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                string strInfDocLocation = openInfDoc.FileName;

                MessageBox.Show(strInfDocLocation);
                InfDocLocationtxt.Text = strInfDocLocation;
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            OpenFileDialog openNetdoc = new OpenFileDialog();
            if (openNetdoc.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                string strNetDocLocation = openNetdoc.FileName;

                MessageBox.Show(strNetDocLocation);
                NetDocLocationtxt.Text = strNetDocLocation;
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            OpenFileDialog openChkdoc = new OpenFileDialog();
            if (openChkdoc.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                string strChkDocLocation = openChkdoc.FileName;

                MessageBox.Show(strChkDocLocation);
                ChkDocLocationtxt.Text = strChkDocLocation;
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            object fileName = Path.Combine(System.Windows.Forms.Application.StartupPath, InfDocLocationtxt.Text);
            Microsoft.Office.Interop.Word.Application wordApp = new Microsoft.Office.Interop.Word.Application { Visible = true };
            Microsoft.Office.Interop.Word.Document aDoc = wordApp.Documents.Open(ref fileName, ReadOnly: false, Visible: true);
            aDoc.Activate();
            FindAndReplace(wordApp, "<ServerName>", textBox1.Text);
            FindAndReplace(wordApp, "<Domain>", textBox2.Text);
            FindAndReplace(wordApp, "<Ip>", textBox3.Text);
            FindAndReplace(wordApp, "<Engineer>", textBox4.Text);
            FindAndReplace(wordApp, "<Date>", textBox5.Text);
            FindAndReplace(wordApp, "<Project>", textBox6.Text);
            FindAndReplace(wordApp, "<Cluster>", textBox7.Text);
            FindAndReplace(wordApp, "<DocNumber>", textBox8.Text);
            FindAndReplace(wordApp, "<Author>", textBox9.Text);


        }

        private void button7_Click(object sender, EventArgs e)
        {

        }

        private void button5_Click(object sender, EventArgs e)
        {
            object fileName = Path.Combine(System.Windows.Forms.Application.StartupPath, NetDocLocationtxt.Text);
            Microsoft.Office.Interop.Word.Application wordApp = new Microsoft.Office.Interop.Word.Application { Visible = true };
            Microsoft.Office.Interop.Word.Document aDoc = wordApp.Documents.Open(ref fileName, ReadOnly: false, Visible: true);
            aDoc.Activate();
            FindAndReplace(wordApp, "<ServerName>", textBox1.Text);
            FindAndReplace(wordApp, "<Domain>", textBox2.Text);
            FindAndReplace(wordApp, "<Ip>", textBox3.Text);
            FindAndReplace(wordApp, "<Engineer>", textBox4.Text);
            FindAndReplace(wordApp, "<Date>", textBox5.Text);
            FindAndReplace(wordApp, "<Project>", textBox6.Text);
            FindAndReplace(wordApp, "<Cluster>", textBox7.Text);
            FindAndReplace(wordApp, "<DocNumber>", textBox8.Text);
            FindAndReplace(wordApp, "<Author>", textBox9.Text);
        }

        private void button6_Click(object sender, EventArgs e)
        {
            object fileName = Path.Combine(System.Windows.Forms.Application.StartupPath, ChkDocLocationtxt.Text);
            Microsoft.Office.Interop.Word.Application wordApp = new Microsoft.Office.Interop.Word.Application { Visible = true };
            Microsoft.Office.Interop.Word.Document aDoc = wordApp.Documents.Open(ref fileName, ReadOnly: false, Visible: true);
            aDoc.Activate();
            FindAndReplace(wordApp, "<ServerName>", textBox1.Text);
            FindAndReplace(wordApp, "<Domain>", textBox2.Text);
            FindAndReplace(wordApp, "<Ip>", textBox3.Text);
            FindAndReplace(wordApp, "<Engineer>", textBox4.Text);
            FindAndReplace(wordApp, "<Date>", textBox5.Text);
            FindAndReplace(wordApp, "<Project>", textBox6.Text);
            FindAndReplace(wordApp, "<Cluster>", textBox7.Text);
            FindAndReplace(wordApp, "<DocNumber>", textBox8.Text);
            FindAndReplace(wordApp, "<Author>", textBox9.Text);
        }


    }
}

最佳答案

在我看来,这是一个.NET Framework compatibility问题。

问题:您已经在本地计算机上使用更高版本的.NET Framework开发了应用程序,并在具有更低版本.NET Framework的远程计算机上运行了该应用程序。

注意:如果您将应用程序定位为在Heigher版本上运行.NET Framework版本,则它将不会在较低版本上运行。

解决方案:,您需要将其定位为远程PC上可用的.NET Framework Lower Version才能在远程PC上运行。

步骤1:右键单击project-选择properties
步骤2:Target Framework.NET Framework x.x更改为.NET Framework x.y

注意:远程计算机上可用的x.x是高度,而x.y是较低版本,或任何较低版本。

关于c# - 找不到方法: 'System.Type System.Runtime.InteropServices.Marshal.GetTypeFromCLSID(System.Guid)' ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20440822/

10-08 22:25
查看更多