How to fix a System.Runtime.InteropServices.COMException error










0















I have created a C# WinForms project which calculates numerical values and writes them to an open Excel spreadsheet. The program works by allowing the user to open a spreadsheet in the Excel program. The writing is carried out by one method called private void updateExcel_Click(object sender, EventArgs e) which writes like so:



if (*in range*)
MySheet.Cells[activeRow, activeColumn].Value = total;


This approach works like a charm, except when there is an unsubmitted change made in the. By unsubmitted change I mean when the user goes directly into the spreadsheet and changes the number in the active cell without finalizing the change with one of:



  • pressing enter

  • pressing tab

  • pressing an arrow key

  • clicking elsewhere

When I write to the affected cell once more with the program I get a System.Runtime.InteropServices.COMException error. The full text being:




Exception thrown: 'System.Runtime.InteropServices.COMException' in System.Dynamic.dll
An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in System.Dynamic.dll
Call was rejected by callee. (Exception from HRESULT: 0x80010001 (RPC_E_CALL_REJECTED))




Oddly enough, when the direct user change is finalized with one of the bulleted methods I get no error when I rewrite to the cell with the program.
How do I remedy my program to avoid the COMException error?



I already tried following the msdn link: How to fix 'Call was rejected by callee' error. I called the C# method updateCell_Click from the space labeled "Insert your automation code here."










share|improve this question






















  • Using the Excel interop feature while also making the UI visible is in general a pretty bad idea. Now there are two programs that demand what the UI look like. You can easily tell who is the bigger boss. And deal with it with try/catch.

    – Hans Passant
    Nov 15 '18 at 1:12











  • Yes, Hans is right. The Excel interface will take precedence over the .Net stuff interacting with it. You could of course use something like Application.Interactive = false, which should prevent the user from making changes to the Excel UI

    – steveo40
    Nov 16 '18 at 12:22











  • @steveo40 My problem is that I need the user to be able to click in the Excel UI so that they can easily choose the right cell to write. This error has been very rare ( < 1/200 times), but I'll try implementing some try-catch statements and other error checks

    – InigoMontoyaJr
    Nov 16 '18 at 16:40











  • Yep, try/catch is the only solution then as far as I know

    – steveo40
    Nov 16 '18 at 16:43















0















I have created a C# WinForms project which calculates numerical values and writes them to an open Excel spreadsheet. The program works by allowing the user to open a spreadsheet in the Excel program. The writing is carried out by one method called private void updateExcel_Click(object sender, EventArgs e) which writes like so:



if (*in range*)
MySheet.Cells[activeRow, activeColumn].Value = total;


This approach works like a charm, except when there is an unsubmitted change made in the. By unsubmitted change I mean when the user goes directly into the spreadsheet and changes the number in the active cell without finalizing the change with one of:



  • pressing enter

  • pressing tab

  • pressing an arrow key

  • clicking elsewhere

When I write to the affected cell once more with the program I get a System.Runtime.InteropServices.COMException error. The full text being:




Exception thrown: 'System.Runtime.InteropServices.COMException' in System.Dynamic.dll
An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in System.Dynamic.dll
Call was rejected by callee. (Exception from HRESULT: 0x80010001 (RPC_E_CALL_REJECTED))




Oddly enough, when the direct user change is finalized with one of the bulleted methods I get no error when I rewrite to the cell with the program.
How do I remedy my program to avoid the COMException error?



I already tried following the msdn link: How to fix 'Call was rejected by callee' error. I called the C# method updateCell_Click from the space labeled "Insert your automation code here."










share|improve this question






















  • Using the Excel interop feature while also making the UI visible is in general a pretty bad idea. Now there are two programs that demand what the UI look like. You can easily tell who is the bigger boss. And deal with it with try/catch.

    – Hans Passant
    Nov 15 '18 at 1:12











  • Yes, Hans is right. The Excel interface will take precedence over the .Net stuff interacting with it. You could of course use something like Application.Interactive = false, which should prevent the user from making changes to the Excel UI

    – steveo40
    Nov 16 '18 at 12:22











  • @steveo40 My problem is that I need the user to be able to click in the Excel UI so that they can easily choose the right cell to write. This error has been very rare ( < 1/200 times), but I'll try implementing some try-catch statements and other error checks

    – InigoMontoyaJr
    Nov 16 '18 at 16:40











  • Yep, try/catch is the only solution then as far as I know

    – steveo40
    Nov 16 '18 at 16:43













0












0








0








I have created a C# WinForms project which calculates numerical values and writes them to an open Excel spreadsheet. The program works by allowing the user to open a spreadsheet in the Excel program. The writing is carried out by one method called private void updateExcel_Click(object sender, EventArgs e) which writes like so:



if (*in range*)
MySheet.Cells[activeRow, activeColumn].Value = total;


This approach works like a charm, except when there is an unsubmitted change made in the. By unsubmitted change I mean when the user goes directly into the spreadsheet and changes the number in the active cell without finalizing the change with one of:



  • pressing enter

  • pressing tab

  • pressing an arrow key

  • clicking elsewhere

When I write to the affected cell once more with the program I get a System.Runtime.InteropServices.COMException error. The full text being:




Exception thrown: 'System.Runtime.InteropServices.COMException' in System.Dynamic.dll
An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in System.Dynamic.dll
Call was rejected by callee. (Exception from HRESULT: 0x80010001 (RPC_E_CALL_REJECTED))




Oddly enough, when the direct user change is finalized with one of the bulleted methods I get no error when I rewrite to the cell with the program.
How do I remedy my program to avoid the COMException error?



I already tried following the msdn link: How to fix 'Call was rejected by callee' error. I called the C# method updateCell_Click from the space labeled "Insert your automation code here."










share|improve this question














I have created a C# WinForms project which calculates numerical values and writes them to an open Excel spreadsheet. The program works by allowing the user to open a spreadsheet in the Excel program. The writing is carried out by one method called private void updateExcel_Click(object sender, EventArgs e) which writes like so:



if (*in range*)
MySheet.Cells[activeRow, activeColumn].Value = total;


This approach works like a charm, except when there is an unsubmitted change made in the. By unsubmitted change I mean when the user goes directly into the spreadsheet and changes the number in the active cell without finalizing the change with one of:



  • pressing enter

  • pressing tab

  • pressing an arrow key

  • clicking elsewhere

When I write to the affected cell once more with the program I get a System.Runtime.InteropServices.COMException error. The full text being:




Exception thrown: 'System.Runtime.InteropServices.COMException' in System.Dynamic.dll
An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in System.Dynamic.dll
Call was rejected by callee. (Exception from HRESULT: 0x80010001 (RPC_E_CALL_REJECTED))




Oddly enough, when the direct user change is finalized with one of the bulleted methods I get no error when I rewrite to the cell with the program.
How do I remedy my program to avoid the COMException error?



I already tried following the msdn link: How to fix 'Call was rejected by callee' error. I called the C# method updateCell_Click from the space labeled "Insert your automation code here."







c# excel excel-interop






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 14 '18 at 18:57









InigoMontoyaJrInigoMontoyaJr

235




235












  • Using the Excel interop feature while also making the UI visible is in general a pretty bad idea. Now there are two programs that demand what the UI look like. You can easily tell who is the bigger boss. And deal with it with try/catch.

    – Hans Passant
    Nov 15 '18 at 1:12











  • Yes, Hans is right. The Excel interface will take precedence over the .Net stuff interacting with it. You could of course use something like Application.Interactive = false, which should prevent the user from making changes to the Excel UI

    – steveo40
    Nov 16 '18 at 12:22











  • @steveo40 My problem is that I need the user to be able to click in the Excel UI so that they can easily choose the right cell to write. This error has been very rare ( < 1/200 times), but I'll try implementing some try-catch statements and other error checks

    – InigoMontoyaJr
    Nov 16 '18 at 16:40











  • Yep, try/catch is the only solution then as far as I know

    – steveo40
    Nov 16 '18 at 16:43

















  • Using the Excel interop feature while also making the UI visible is in general a pretty bad idea. Now there are two programs that demand what the UI look like. You can easily tell who is the bigger boss. And deal with it with try/catch.

    – Hans Passant
    Nov 15 '18 at 1:12











  • Yes, Hans is right. The Excel interface will take precedence over the .Net stuff interacting with it. You could of course use something like Application.Interactive = false, which should prevent the user from making changes to the Excel UI

    – steveo40
    Nov 16 '18 at 12:22











  • @steveo40 My problem is that I need the user to be able to click in the Excel UI so that they can easily choose the right cell to write. This error has been very rare ( < 1/200 times), but I'll try implementing some try-catch statements and other error checks

    – InigoMontoyaJr
    Nov 16 '18 at 16:40











  • Yep, try/catch is the only solution then as far as I know

    – steveo40
    Nov 16 '18 at 16:43
















Using the Excel interop feature while also making the UI visible is in general a pretty bad idea. Now there are two programs that demand what the UI look like. You can easily tell who is the bigger boss. And deal with it with try/catch.

– Hans Passant
Nov 15 '18 at 1:12





Using the Excel interop feature while also making the UI visible is in general a pretty bad idea. Now there are two programs that demand what the UI look like. You can easily tell who is the bigger boss. And deal with it with try/catch.

– Hans Passant
Nov 15 '18 at 1:12













Yes, Hans is right. The Excel interface will take precedence over the .Net stuff interacting with it. You could of course use something like Application.Interactive = false, which should prevent the user from making changes to the Excel UI

– steveo40
Nov 16 '18 at 12:22





Yes, Hans is right. The Excel interface will take precedence over the .Net stuff interacting with it. You could of course use something like Application.Interactive = false, which should prevent the user from making changes to the Excel UI

– steveo40
Nov 16 '18 at 12:22













@steveo40 My problem is that I need the user to be able to click in the Excel UI so that they can easily choose the right cell to write. This error has been very rare ( < 1/200 times), but I'll try implementing some try-catch statements and other error checks

– InigoMontoyaJr
Nov 16 '18 at 16:40





@steveo40 My problem is that I need the user to be able to click in the Excel UI so that they can easily choose the right cell to write. This error has been very rare ( < 1/200 times), but I'll try implementing some try-catch statements and other error checks

– InigoMontoyaJr
Nov 16 '18 at 16:40













Yep, try/catch is the only solution then as far as I know

– steveo40
Nov 16 '18 at 16:43





Yep, try/catch is the only solution then as far as I know

– steveo40
Nov 16 '18 at 16:43












0






active

oldest

votes











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%2f53307026%2fhow-to-fix-a-system-runtime-interopservices-comexception-error%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















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%2f53307026%2fhow-to-fix-a-system-runtime-interopservices-comexception-error%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

Use pre created SQLite database for Android project in kotlin

Darth Vader #20

Ondo