C# Word SaveAs RPC server is unavailable





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















private void CreateDocument(string date, string name, string phone, string father_name, string address, string village, string post, string taluka, string city, string district, string pincode, string product, int price)
{
string currentPath = System.IO.Path.GetDirectoryName(Application.ExecutablePath);
// Get the Word application object.
Word._Application word_app = new Word.Application();

// Make Word visible (optional).
word_app.Visible = true;

// Create the Word document.
object missing = Type.Missing;
Word._Document word_doc = word_app.Documents.Add(
ref missing, ref missing, ref missing, ref missing);

// Create a header paragraph.
Word.Paragraph para = word_doc.Paragraphs.Add(ref missing);
//para.Range.Text = "Chrysanthemum Curve";
object style_name = "Heading 1";
para.Range.set_Style(ref style_name);
para.Range.InsertParagraphAfter();

// Add more text.
para.Range.Text = "";
para.Range.InsertParagraphAfter();

// Save the current font and start using Courier New.
string old_font = para.Range.Font.Name;
para.Range.Font.Name = "Courier New";

// Add the equations.
para.Range.Font.Bold = 1;
para.Range.Font.Size = 16;
para.Range.Text = "EXPRESS PARCEL WITH COD" +"v" + "ADVANCE PAYMENT" + "v" + "CODE NO 560023100235" + "v" + "BOOKING AT PBC BG 560046" + "v" + "COD FOR RS " + price + "/ -" + "v" + "PLEASE COLLECT CASH " + price + "/-" + "v" + "(" + NumberToWords(price) + ")" + "v" + "BILLER 5792" + Environment.NewLine + Environment.NewLine + Environment.NewLine;


// Start a new paragraph and then
// switch back to the original font.
para.Range.InsertParagraphAfter();
para.Range.Font.Name = "Courier New";
para.Range.Font.Bold = 1;
para.Range.Font.Size = 16;
para.Range.Text = "TOv" + name + father_name + "v" + address + "v" + village + "v" + post + "v" + taluka + "v" + city + "v" + district + "v" + "PINCODE-" + pincode + "v" + "MOBILE-" + phone + Environment.NewLine+Environment.NewLine;


// Start a new paragraph and then
// switch back to the original font.
para.Range.InsertParagraphAfter();
para.Range.Font.Name = "Times New Roman";
para.Range.Font.Size = 12;
para.Range.Text = "FROM" + "v" + "AVK SHOPPING PVT LTD" + "v" + "NO U16, BHUVANESHWARINAGAR" + "v" + "MAGADI ROAD BANGALORE - 23" + Environment.NewLine+Environment.NewLine+ Environment.NewLine+ Environment.NewLine;

// Start a new paragraph and then
// switch back to the original font. para.Range.InsertParagraphAfter();
para.Range.Font.Name = "Times New Roman";
para.Range.Font.Size = 12;
para.Range.Text = "PARCEL CONTAINS" + " (" + product + ") " + "AND THE PARCEL DO" + "v" + "NOT CONTAIN ANY DANGEROUS ARTICLE PROHIBITED BY" + "v" + "POSTAL REGULATIONS";


Thread.Sleep(10000);
//if(!(File.Exists(@currentPath + name + date + ".docx")))
//{

//}
//else
//{
// //File.Create(@currentPath + name + date + ".docx");

//}
string filename = name + "-" + phone + "-" + ".docx";
MessageBox.Show(currentPath);
object ob = @currentPath + filename;
word_doc.SaveAs2(ref ob);
MessageBox.Show("Document created successfully !");

// Close.

Marshal.ReleaseComObject(word_doc);
Marshal.ReleaseComObject(word_app);
}


The above code is working good but some times at word_doc.SaveAs2(ref ob);its giving error The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)' I already checked few suggestion but none of them solved my rpc issue.



Also once the .docx file was creating it is opening automatically. I don't want to open .docx once its created the file because my tool create 100 files at a time. If every doc opens my pc will use so many resources. (Simply I want to save the file silently).



This is windowsforms - vs2017 I am using.










share|improve this question




















  • 1





    Please take a moment to review the site rules about asking questions in the help center. Only one question / Question is allowed. Ask your second question in a new question. And please check that you tag it correctly - read the tag information about what a tag is for.

    – Cindy Meister
    Jan 3 at 20:22











  • What is the context in which this code runs? WPF? Winforms? Web project?

    – mjwills
    Jan 3 at 20:44











  • It is windows forms.

    – nav
    Jan 4 at 2:38


















0















private void CreateDocument(string date, string name, string phone, string father_name, string address, string village, string post, string taluka, string city, string district, string pincode, string product, int price)
{
string currentPath = System.IO.Path.GetDirectoryName(Application.ExecutablePath);
// Get the Word application object.
Word._Application word_app = new Word.Application();

// Make Word visible (optional).
word_app.Visible = true;

// Create the Word document.
object missing = Type.Missing;
Word._Document word_doc = word_app.Documents.Add(
ref missing, ref missing, ref missing, ref missing);

// Create a header paragraph.
Word.Paragraph para = word_doc.Paragraphs.Add(ref missing);
//para.Range.Text = "Chrysanthemum Curve";
object style_name = "Heading 1";
para.Range.set_Style(ref style_name);
para.Range.InsertParagraphAfter();

// Add more text.
para.Range.Text = "";
para.Range.InsertParagraphAfter();

// Save the current font and start using Courier New.
string old_font = para.Range.Font.Name;
para.Range.Font.Name = "Courier New";

// Add the equations.
para.Range.Font.Bold = 1;
para.Range.Font.Size = 16;
para.Range.Text = "EXPRESS PARCEL WITH COD" +"v" + "ADVANCE PAYMENT" + "v" + "CODE NO 560023100235" + "v" + "BOOKING AT PBC BG 560046" + "v" + "COD FOR RS " + price + "/ -" + "v" + "PLEASE COLLECT CASH " + price + "/-" + "v" + "(" + NumberToWords(price) + ")" + "v" + "BILLER 5792" + Environment.NewLine + Environment.NewLine + Environment.NewLine;


// Start a new paragraph and then
// switch back to the original font.
para.Range.InsertParagraphAfter();
para.Range.Font.Name = "Courier New";
para.Range.Font.Bold = 1;
para.Range.Font.Size = 16;
para.Range.Text = "TOv" + name + father_name + "v" + address + "v" + village + "v" + post + "v" + taluka + "v" + city + "v" + district + "v" + "PINCODE-" + pincode + "v" + "MOBILE-" + phone + Environment.NewLine+Environment.NewLine;


// Start a new paragraph and then
// switch back to the original font.
para.Range.InsertParagraphAfter();
para.Range.Font.Name = "Times New Roman";
para.Range.Font.Size = 12;
para.Range.Text = "FROM" + "v" + "AVK SHOPPING PVT LTD" + "v" + "NO U16, BHUVANESHWARINAGAR" + "v" + "MAGADI ROAD BANGALORE - 23" + Environment.NewLine+Environment.NewLine+ Environment.NewLine+ Environment.NewLine;

// Start a new paragraph and then
// switch back to the original font. para.Range.InsertParagraphAfter();
para.Range.Font.Name = "Times New Roman";
para.Range.Font.Size = 12;
para.Range.Text = "PARCEL CONTAINS" + " (" + product + ") " + "AND THE PARCEL DO" + "v" + "NOT CONTAIN ANY DANGEROUS ARTICLE PROHIBITED BY" + "v" + "POSTAL REGULATIONS";


Thread.Sleep(10000);
//if(!(File.Exists(@currentPath + name + date + ".docx")))
//{

//}
//else
//{
// //File.Create(@currentPath + name + date + ".docx");

//}
string filename = name + "-" + phone + "-" + ".docx";
MessageBox.Show(currentPath);
object ob = @currentPath + filename;
word_doc.SaveAs2(ref ob);
MessageBox.Show("Document created successfully !");

// Close.

Marshal.ReleaseComObject(word_doc);
Marshal.ReleaseComObject(word_app);
}


The above code is working good but some times at word_doc.SaveAs2(ref ob);its giving error The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)' I already checked few suggestion but none of them solved my rpc issue.



Also once the .docx file was creating it is opening automatically. I don't want to open .docx once its created the file because my tool create 100 files at a time. If every doc opens my pc will use so many resources. (Simply I want to save the file silently).



This is windowsforms - vs2017 I am using.










share|improve this question




















  • 1





    Please take a moment to review the site rules about asking questions in the help center. Only one question / Question is allowed. Ask your second question in a new question. And please check that you tag it correctly - read the tag information about what a tag is for.

    – Cindy Meister
    Jan 3 at 20:22











  • What is the context in which this code runs? WPF? Winforms? Web project?

    – mjwills
    Jan 3 at 20:44











  • It is windows forms.

    – nav
    Jan 4 at 2:38














0












0








0








private void CreateDocument(string date, string name, string phone, string father_name, string address, string village, string post, string taluka, string city, string district, string pincode, string product, int price)
{
string currentPath = System.IO.Path.GetDirectoryName(Application.ExecutablePath);
// Get the Word application object.
Word._Application word_app = new Word.Application();

// Make Word visible (optional).
word_app.Visible = true;

// Create the Word document.
object missing = Type.Missing;
Word._Document word_doc = word_app.Documents.Add(
ref missing, ref missing, ref missing, ref missing);

// Create a header paragraph.
Word.Paragraph para = word_doc.Paragraphs.Add(ref missing);
//para.Range.Text = "Chrysanthemum Curve";
object style_name = "Heading 1";
para.Range.set_Style(ref style_name);
para.Range.InsertParagraphAfter();

// Add more text.
para.Range.Text = "";
para.Range.InsertParagraphAfter();

// Save the current font and start using Courier New.
string old_font = para.Range.Font.Name;
para.Range.Font.Name = "Courier New";

// Add the equations.
para.Range.Font.Bold = 1;
para.Range.Font.Size = 16;
para.Range.Text = "EXPRESS PARCEL WITH COD" +"v" + "ADVANCE PAYMENT" + "v" + "CODE NO 560023100235" + "v" + "BOOKING AT PBC BG 560046" + "v" + "COD FOR RS " + price + "/ -" + "v" + "PLEASE COLLECT CASH " + price + "/-" + "v" + "(" + NumberToWords(price) + ")" + "v" + "BILLER 5792" + Environment.NewLine + Environment.NewLine + Environment.NewLine;


// Start a new paragraph and then
// switch back to the original font.
para.Range.InsertParagraphAfter();
para.Range.Font.Name = "Courier New";
para.Range.Font.Bold = 1;
para.Range.Font.Size = 16;
para.Range.Text = "TOv" + name + father_name + "v" + address + "v" + village + "v" + post + "v" + taluka + "v" + city + "v" + district + "v" + "PINCODE-" + pincode + "v" + "MOBILE-" + phone + Environment.NewLine+Environment.NewLine;


// Start a new paragraph and then
// switch back to the original font.
para.Range.InsertParagraphAfter();
para.Range.Font.Name = "Times New Roman";
para.Range.Font.Size = 12;
para.Range.Text = "FROM" + "v" + "AVK SHOPPING PVT LTD" + "v" + "NO U16, BHUVANESHWARINAGAR" + "v" + "MAGADI ROAD BANGALORE - 23" + Environment.NewLine+Environment.NewLine+ Environment.NewLine+ Environment.NewLine;

// Start a new paragraph and then
// switch back to the original font. para.Range.InsertParagraphAfter();
para.Range.Font.Name = "Times New Roman";
para.Range.Font.Size = 12;
para.Range.Text = "PARCEL CONTAINS" + " (" + product + ") " + "AND THE PARCEL DO" + "v" + "NOT CONTAIN ANY DANGEROUS ARTICLE PROHIBITED BY" + "v" + "POSTAL REGULATIONS";


Thread.Sleep(10000);
//if(!(File.Exists(@currentPath + name + date + ".docx")))
//{

//}
//else
//{
// //File.Create(@currentPath + name + date + ".docx");

//}
string filename = name + "-" + phone + "-" + ".docx";
MessageBox.Show(currentPath);
object ob = @currentPath + filename;
word_doc.SaveAs2(ref ob);
MessageBox.Show("Document created successfully !");

// Close.

Marshal.ReleaseComObject(word_doc);
Marshal.ReleaseComObject(word_app);
}


The above code is working good but some times at word_doc.SaveAs2(ref ob);its giving error The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)' I already checked few suggestion but none of them solved my rpc issue.



Also once the .docx file was creating it is opening automatically. I don't want to open .docx once its created the file because my tool create 100 files at a time. If every doc opens my pc will use so many resources. (Simply I want to save the file silently).



This is windowsforms - vs2017 I am using.










share|improve this question
















private void CreateDocument(string date, string name, string phone, string father_name, string address, string village, string post, string taluka, string city, string district, string pincode, string product, int price)
{
string currentPath = System.IO.Path.GetDirectoryName(Application.ExecutablePath);
// Get the Word application object.
Word._Application word_app = new Word.Application();

// Make Word visible (optional).
word_app.Visible = true;

// Create the Word document.
object missing = Type.Missing;
Word._Document word_doc = word_app.Documents.Add(
ref missing, ref missing, ref missing, ref missing);

// Create a header paragraph.
Word.Paragraph para = word_doc.Paragraphs.Add(ref missing);
//para.Range.Text = "Chrysanthemum Curve";
object style_name = "Heading 1";
para.Range.set_Style(ref style_name);
para.Range.InsertParagraphAfter();

// Add more text.
para.Range.Text = "";
para.Range.InsertParagraphAfter();

// Save the current font and start using Courier New.
string old_font = para.Range.Font.Name;
para.Range.Font.Name = "Courier New";

// Add the equations.
para.Range.Font.Bold = 1;
para.Range.Font.Size = 16;
para.Range.Text = "EXPRESS PARCEL WITH COD" +"v" + "ADVANCE PAYMENT" + "v" + "CODE NO 560023100235" + "v" + "BOOKING AT PBC BG 560046" + "v" + "COD FOR RS " + price + "/ -" + "v" + "PLEASE COLLECT CASH " + price + "/-" + "v" + "(" + NumberToWords(price) + ")" + "v" + "BILLER 5792" + Environment.NewLine + Environment.NewLine + Environment.NewLine;


// Start a new paragraph and then
// switch back to the original font.
para.Range.InsertParagraphAfter();
para.Range.Font.Name = "Courier New";
para.Range.Font.Bold = 1;
para.Range.Font.Size = 16;
para.Range.Text = "TOv" + name + father_name + "v" + address + "v" + village + "v" + post + "v" + taluka + "v" + city + "v" + district + "v" + "PINCODE-" + pincode + "v" + "MOBILE-" + phone + Environment.NewLine+Environment.NewLine;


// Start a new paragraph and then
// switch back to the original font.
para.Range.InsertParagraphAfter();
para.Range.Font.Name = "Times New Roman";
para.Range.Font.Size = 12;
para.Range.Text = "FROM" + "v" + "AVK SHOPPING PVT LTD" + "v" + "NO U16, BHUVANESHWARINAGAR" + "v" + "MAGADI ROAD BANGALORE - 23" + Environment.NewLine+Environment.NewLine+ Environment.NewLine+ Environment.NewLine;

// Start a new paragraph and then
// switch back to the original font. para.Range.InsertParagraphAfter();
para.Range.Font.Name = "Times New Roman";
para.Range.Font.Size = 12;
para.Range.Text = "PARCEL CONTAINS" + " (" + product + ") " + "AND THE PARCEL DO" + "v" + "NOT CONTAIN ANY DANGEROUS ARTICLE PROHIBITED BY" + "v" + "POSTAL REGULATIONS";


Thread.Sleep(10000);
//if(!(File.Exists(@currentPath + name + date + ".docx")))
//{

//}
//else
//{
// //File.Create(@currentPath + name + date + ".docx");

//}
string filename = name + "-" + phone + "-" + ".docx";
MessageBox.Show(currentPath);
object ob = @currentPath + filename;
word_doc.SaveAs2(ref ob);
MessageBox.Show("Document created successfully !");

// Close.

Marshal.ReleaseComObject(word_doc);
Marshal.ReleaseComObject(word_app);
}


The above code is working good but some times at word_doc.SaveAs2(ref ob);its giving error The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)' I already checked few suggestion but none of them solved my rpc issue.



Also once the .docx file was creating it is opening automatically. I don't want to open .docx once its created the file because my tool create 100 files at a time. If every doc opens my pc will use so many resources. (Simply I want to save the file silently).



This is windowsforms - vs2017 I am using.







c# ms-word






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 4 at 2:37







nav

















asked Jan 3 at 19:25









navnav

226




226








  • 1





    Please take a moment to review the site rules about asking questions in the help center. Only one question / Question is allowed. Ask your second question in a new question. And please check that you tag it correctly - read the tag information about what a tag is for.

    – Cindy Meister
    Jan 3 at 20:22











  • What is the context in which this code runs? WPF? Winforms? Web project?

    – mjwills
    Jan 3 at 20:44











  • It is windows forms.

    – nav
    Jan 4 at 2:38














  • 1





    Please take a moment to review the site rules about asking questions in the help center. Only one question / Question is allowed. Ask your second question in a new question. And please check that you tag it correctly - read the tag information about what a tag is for.

    – Cindy Meister
    Jan 3 at 20:22











  • What is the context in which this code runs? WPF? Winforms? Web project?

    – mjwills
    Jan 3 at 20:44











  • It is windows forms.

    – nav
    Jan 4 at 2:38








1




1





Please take a moment to review the site rules about asking questions in the help center. Only one question / Question is allowed. Ask your second question in a new question. And please check that you tag it correctly - read the tag information about what a tag is for.

– Cindy Meister
Jan 3 at 20:22





Please take a moment to review the site rules about asking questions in the help center. Only one question / Question is allowed. Ask your second question in a new question. And please check that you tag it correctly - read the tag information about what a tag is for.

– Cindy Meister
Jan 3 at 20:22













What is the context in which this code runs? WPF? Winforms? Web project?

– mjwills
Jan 3 at 20:44





What is the context in which this code runs? WPF? Winforms? Web project?

– mjwills
Jan 3 at 20:44













It is windows forms.

– nav
Jan 4 at 2:38





It is windows forms.

– nav
Jan 4 at 2:38












2 Answers
2






active

oldest

votes


















0














If you don't properly release all the COM objects generated in the code then this can happen when code is executed more than once without going out of scope. The error indicates that the Application object (RPC Server) is still being used and therefore cannot be instantiated



The code orphans the object para, for example. So para can "block" the word_app object.



When using C# it's also a good idea to use specific objects instead of dot-notation so that they can be explicitly released, as well. (It's also more efficient.) For example, instead of para.Range.Font



Word.Range paraRange = para.Range;
Word.Font paraFont = paraRange.Font;





share|improve this answer
























  • I tried your suggestion still same issue. Also tried Close(ref save_changes, ref missing, ref missing); and .quick functions still same issue.

    – nav
    Jan 4 at 2:55





















-1














When you encounter this exception, have you closed the document? This severs the connection to Word. Since you encounter this occasionally rather than consistently (and you state that you don't want the documents to open in the first place) I suspect that this is the case.



For what it's worth, I'd recommend not using Word automation for this at all and just using the zipped XML that compose the docx files directly. Unless you have to explicitly support pre-2007 versions of Microsoft Word, I don't know why you couldn't do this given the constraints you posted. When we made that transition in 2007, the documents that required 45 minutes to create via automation took 15 seconds on the same hardware largely because the automation objects have to account for so many things outside of your specific use case.






share|improve this answer



















  • 1





    Whether the document is open or closed, the connection to Word is not severed. Looking at the code it's clear that the document is not closed, nor the Word application exited. The result, as far as visibility is concerned, is that the Word application is open with the document visible. Marshal.ReleaseComObject is what is severing the connections - but not all COM objects are being released.

    – Cindy Meister
    Jan 3 at 20:36












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54028584%2fc-sharp-word-saveas-rpc-server-is-unavailable%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














If you don't properly release all the COM objects generated in the code then this can happen when code is executed more than once without going out of scope. The error indicates that the Application object (RPC Server) is still being used and therefore cannot be instantiated



The code orphans the object para, for example. So para can "block" the word_app object.



When using C# it's also a good idea to use specific objects instead of dot-notation so that they can be explicitly released, as well. (It's also more efficient.) For example, instead of para.Range.Font



Word.Range paraRange = para.Range;
Word.Font paraFont = paraRange.Font;





share|improve this answer
























  • I tried your suggestion still same issue. Also tried Close(ref save_changes, ref missing, ref missing); and .quick functions still same issue.

    – nav
    Jan 4 at 2:55


















0














If you don't properly release all the COM objects generated in the code then this can happen when code is executed more than once without going out of scope. The error indicates that the Application object (RPC Server) is still being used and therefore cannot be instantiated



The code orphans the object para, for example. So para can "block" the word_app object.



When using C# it's also a good idea to use specific objects instead of dot-notation so that they can be explicitly released, as well. (It's also more efficient.) For example, instead of para.Range.Font



Word.Range paraRange = para.Range;
Word.Font paraFont = paraRange.Font;





share|improve this answer
























  • I tried your suggestion still same issue. Also tried Close(ref save_changes, ref missing, ref missing); and .quick functions still same issue.

    – nav
    Jan 4 at 2:55
















0












0








0







If you don't properly release all the COM objects generated in the code then this can happen when code is executed more than once without going out of scope. The error indicates that the Application object (RPC Server) is still being used and therefore cannot be instantiated



The code orphans the object para, for example. So para can "block" the word_app object.



When using C# it's also a good idea to use specific objects instead of dot-notation so that they can be explicitly released, as well. (It's also more efficient.) For example, instead of para.Range.Font



Word.Range paraRange = para.Range;
Word.Font paraFont = paraRange.Font;





share|improve this answer













If you don't properly release all the COM objects generated in the code then this can happen when code is executed more than once without going out of scope. The error indicates that the Application object (RPC Server) is still being used and therefore cannot be instantiated



The code orphans the object para, for example. So para can "block" the word_app object.



When using C# it's also a good idea to use specific objects instead of dot-notation so that they can be explicitly released, as well. (It's also more efficient.) For example, instead of para.Range.Font



Word.Range paraRange = para.Range;
Word.Font paraFont = paraRange.Font;






share|improve this answer












share|improve this answer



share|improve this answer










answered Jan 3 at 20:29









Cindy MeisterCindy Meister

16k102437




16k102437













  • I tried your suggestion still same issue. Also tried Close(ref save_changes, ref missing, ref missing); and .quick functions still same issue.

    – nav
    Jan 4 at 2:55





















  • I tried your suggestion still same issue. Also tried Close(ref save_changes, ref missing, ref missing); and .quick functions still same issue.

    – nav
    Jan 4 at 2:55



















I tried your suggestion still same issue. Also tried Close(ref save_changes, ref missing, ref missing); and .quick functions still same issue.

– nav
Jan 4 at 2:55







I tried your suggestion still same issue. Also tried Close(ref save_changes, ref missing, ref missing); and .quick functions still same issue.

– nav
Jan 4 at 2:55















-1














When you encounter this exception, have you closed the document? This severs the connection to Word. Since you encounter this occasionally rather than consistently (and you state that you don't want the documents to open in the first place) I suspect that this is the case.



For what it's worth, I'd recommend not using Word automation for this at all and just using the zipped XML that compose the docx files directly. Unless you have to explicitly support pre-2007 versions of Microsoft Word, I don't know why you couldn't do this given the constraints you posted. When we made that transition in 2007, the documents that required 45 minutes to create via automation took 15 seconds on the same hardware largely because the automation objects have to account for so many things outside of your specific use case.






share|improve this answer



















  • 1





    Whether the document is open or closed, the connection to Word is not severed. Looking at the code it's clear that the document is not closed, nor the Word application exited. The result, as far as visibility is concerned, is that the Word application is open with the document visible. Marshal.ReleaseComObject is what is severing the connections - but not all COM objects are being released.

    – Cindy Meister
    Jan 3 at 20:36
















-1














When you encounter this exception, have you closed the document? This severs the connection to Word. Since you encounter this occasionally rather than consistently (and you state that you don't want the documents to open in the first place) I suspect that this is the case.



For what it's worth, I'd recommend not using Word automation for this at all and just using the zipped XML that compose the docx files directly. Unless you have to explicitly support pre-2007 versions of Microsoft Word, I don't know why you couldn't do this given the constraints you posted. When we made that transition in 2007, the documents that required 45 minutes to create via automation took 15 seconds on the same hardware largely because the automation objects have to account for so many things outside of your specific use case.






share|improve this answer



















  • 1





    Whether the document is open or closed, the connection to Word is not severed. Looking at the code it's clear that the document is not closed, nor the Word application exited. The result, as far as visibility is concerned, is that the Word application is open with the document visible. Marshal.ReleaseComObject is what is severing the connections - but not all COM objects are being released.

    – Cindy Meister
    Jan 3 at 20:36














-1












-1








-1







When you encounter this exception, have you closed the document? This severs the connection to Word. Since you encounter this occasionally rather than consistently (and you state that you don't want the documents to open in the first place) I suspect that this is the case.



For what it's worth, I'd recommend not using Word automation for this at all and just using the zipped XML that compose the docx files directly. Unless you have to explicitly support pre-2007 versions of Microsoft Word, I don't know why you couldn't do this given the constraints you posted. When we made that transition in 2007, the documents that required 45 minutes to create via automation took 15 seconds on the same hardware largely because the automation objects have to account for so many things outside of your specific use case.






share|improve this answer













When you encounter this exception, have you closed the document? This severs the connection to Word. Since you encounter this occasionally rather than consistently (and you state that you don't want the documents to open in the first place) I suspect that this is the case.



For what it's worth, I'd recommend not using Word automation for this at all and just using the zipped XML that compose the docx files directly. Unless you have to explicitly support pre-2007 versions of Microsoft Word, I don't know why you couldn't do this given the constraints you posted. When we made that transition in 2007, the documents that required 45 minutes to create via automation took 15 seconds on the same hardware largely because the automation objects have to account for so many things outside of your specific use case.







share|improve this answer












share|improve this answer



share|improve this answer










answered Jan 3 at 20:32









mattbbplmattbbpl

627




627








  • 1





    Whether the document is open or closed, the connection to Word is not severed. Looking at the code it's clear that the document is not closed, nor the Word application exited. The result, as far as visibility is concerned, is that the Word application is open with the document visible. Marshal.ReleaseComObject is what is severing the connections - but not all COM objects are being released.

    – Cindy Meister
    Jan 3 at 20:36














  • 1





    Whether the document is open or closed, the connection to Word is not severed. Looking at the code it's clear that the document is not closed, nor the Word application exited. The result, as far as visibility is concerned, is that the Word application is open with the document visible. Marshal.ReleaseComObject is what is severing the connections - but not all COM objects are being released.

    – Cindy Meister
    Jan 3 at 20:36








1




1





Whether the document is open or closed, the connection to Word is not severed. Looking at the code it's clear that the document is not closed, nor the Word application exited. The result, as far as visibility is concerned, is that the Word application is open with the document visible. Marshal.ReleaseComObject is what is severing the connections - but not all COM objects are being released.

– Cindy Meister
Jan 3 at 20:36





Whether the document is open or closed, the connection to Word is not severed. Looking at the code it's clear that the document is not closed, nor the Word application exited. The result, as far as visibility is concerned, is that the Word application is open with the document visible. Marshal.ReleaseComObject is what is severing the connections - but not all COM objects are being released.

– Cindy Meister
Jan 3 at 20:36


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54028584%2fc-sharp-word-saveas-rpc-server-is-unavailable%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Monofisismo

Angular Downloading a file using contenturl with Basic Authentication

Olmecas