Calling C# delegate from Python
I am trying to call c# delegate function (updateTextBox) from python code .
Below is what I tried so far.
My .net code is:
namespace DynamicCS
{
public class Test
{
public delegate void updateTextBoxDelegate(String textBoxString); // delegate type
public updateTextBoxDelegate updateTextBox; // delegate object
public void M()
{
updateTextBox("Hello From delegate");
}
public string hello()
{
return "Hello from C#";
}
}
}
And my Python code is:
from types import *
from System import Action,EventHandler, EventArgs
sys.path.append(r'C:\Users\appadmin\source\repos\DynamicCS\DynamicCS\bin\Debug\')
clr.AddReference(r"DynamicCS")
def updateTextBox(res):
print(res)
from DynamicCS import Test
test = Test()
msg = test.hello()
print(msg)
test.updateTextBox =Action[str](updateTextBox)
test.M()
I am getting the below error while running the python code,
test.updateTextBox =Action[str](updateTextBox)
TypeError: value cannot be converted to DynamicCS.Test+updateTextBoxDelegate
I really appreciate if anyone can point out the mistakes in my code.
c# python-3.x
add a comment |
I am trying to call c# delegate function (updateTextBox) from python code .
Below is what I tried so far.
My .net code is:
namespace DynamicCS
{
public class Test
{
public delegate void updateTextBoxDelegate(String textBoxString); // delegate type
public updateTextBoxDelegate updateTextBox; // delegate object
public void M()
{
updateTextBox("Hello From delegate");
}
public string hello()
{
return "Hello from C#";
}
}
}
And my Python code is:
from types import *
from System import Action,EventHandler, EventArgs
sys.path.append(r'C:\Users\appadmin\source\repos\DynamicCS\DynamicCS\bin\Debug\')
clr.AddReference(r"DynamicCS")
def updateTextBox(res):
print(res)
from DynamicCS import Test
test = Test()
msg = test.hello()
print(msg)
test.updateTextBox =Action[str](updateTextBox)
test.M()
I am getting the below error while running the python code,
test.updateTextBox =Action[str](updateTextBox)
TypeError: value cannot be converted to DynamicCS.Test+updateTextBoxDelegate
I really appreciate if anyone can point out the mistakes in my code.
c# python-3.x
If it python for .net that you are using?
– ctrl-alt-delor
Nov 14 '18 at 12:31
1
Notes: you should not putr
in-front of string and escape ``. File path in line 4 in not portable (most OSs don't use back slash, slash should work on all/most. (File path is not portable on same OS as it may change.)
– ctrl-alt-delor
Nov 14 '18 at 12:36
Are you using IronPython?
– dymanoid
Nov 14 '18 at 12:39
I am using normal python (not IronPython). The import of dll is working fine and i am able to call hello() method of C# from my python code as given above. My concern is to define handler of C# delegate in my python code. I have searched but so far no success on it. Any idea how to get this working.
– Sakeer
Nov 15 '18 at 3:52
add a comment |
I am trying to call c# delegate function (updateTextBox) from python code .
Below is what I tried so far.
My .net code is:
namespace DynamicCS
{
public class Test
{
public delegate void updateTextBoxDelegate(String textBoxString); // delegate type
public updateTextBoxDelegate updateTextBox; // delegate object
public void M()
{
updateTextBox("Hello From delegate");
}
public string hello()
{
return "Hello from C#";
}
}
}
And my Python code is:
from types import *
from System import Action,EventHandler, EventArgs
sys.path.append(r'C:\Users\appadmin\source\repos\DynamicCS\DynamicCS\bin\Debug\')
clr.AddReference(r"DynamicCS")
def updateTextBox(res):
print(res)
from DynamicCS import Test
test = Test()
msg = test.hello()
print(msg)
test.updateTextBox =Action[str](updateTextBox)
test.M()
I am getting the below error while running the python code,
test.updateTextBox =Action[str](updateTextBox)
TypeError: value cannot be converted to DynamicCS.Test+updateTextBoxDelegate
I really appreciate if anyone can point out the mistakes in my code.
c# python-3.x
I am trying to call c# delegate function (updateTextBox) from python code .
Below is what I tried so far.
My .net code is:
namespace DynamicCS
{
public class Test
{
public delegate void updateTextBoxDelegate(String textBoxString); // delegate type
public updateTextBoxDelegate updateTextBox; // delegate object
public void M()
{
updateTextBox("Hello From delegate");
}
public string hello()
{
return "Hello from C#";
}
}
}
And my Python code is:
from types import *
from System import Action,EventHandler, EventArgs
sys.path.append(r'C:\Users\appadmin\source\repos\DynamicCS\DynamicCS\bin\Debug\')
clr.AddReference(r"DynamicCS")
def updateTextBox(res):
print(res)
from DynamicCS import Test
test = Test()
msg = test.hello()
print(msg)
test.updateTextBox =Action[str](updateTextBox)
test.M()
I am getting the below error while running the python code,
test.updateTextBox =Action[str](updateTextBox)
TypeError: value cannot be converted to DynamicCS.Test+updateTextBoxDelegate
I really appreciate if anyone can point out the mistakes in my code.
c# python-3.x
c# python-3.x
edited Nov 14 '18 at 12:20
Uwe Keim
27.5k32130212
27.5k32130212
asked Nov 14 '18 at 12:18
SakeerSakeer
76531035
76531035
If it python for .net that you are using?
– ctrl-alt-delor
Nov 14 '18 at 12:31
1
Notes: you should not putr
in-front of string and escape ``. File path in line 4 in not portable (most OSs don't use back slash, slash should work on all/most. (File path is not portable on same OS as it may change.)
– ctrl-alt-delor
Nov 14 '18 at 12:36
Are you using IronPython?
– dymanoid
Nov 14 '18 at 12:39
I am using normal python (not IronPython). The import of dll is working fine and i am able to call hello() method of C# from my python code as given above. My concern is to define handler of C# delegate in my python code. I have searched but so far no success on it. Any idea how to get this working.
– Sakeer
Nov 15 '18 at 3:52
add a comment |
If it python for .net that you are using?
– ctrl-alt-delor
Nov 14 '18 at 12:31
1
Notes: you should not putr
in-front of string and escape ``. File path in line 4 in not portable (most OSs don't use back slash, slash should work on all/most. (File path is not portable on same OS as it may change.)
– ctrl-alt-delor
Nov 14 '18 at 12:36
Are you using IronPython?
– dymanoid
Nov 14 '18 at 12:39
I am using normal python (not IronPython). The import of dll is working fine and i am able to call hello() method of C# from my python code as given above. My concern is to define handler of C# delegate in my python code. I have searched but so far no success on it. Any idea how to get this working.
– Sakeer
Nov 15 '18 at 3:52
If it python for .net that you are using?
– ctrl-alt-delor
Nov 14 '18 at 12:31
If it python for .net that you are using?
– ctrl-alt-delor
Nov 14 '18 at 12:31
1
1
Notes: you should not put
r
in-front of string and escape ``. File path in line 4 in not portable (most OSs don't use back slash, slash should work on all/most. (File path is not portable on same OS as it may change.)– ctrl-alt-delor
Nov 14 '18 at 12:36
Notes: you should not put
r
in-front of string and escape ``. File path in line 4 in not portable (most OSs don't use back slash, slash should work on all/most. (File path is not portable on same OS as it may change.)– ctrl-alt-delor
Nov 14 '18 at 12:36
Are you using IronPython?
– dymanoid
Nov 14 '18 at 12:39
Are you using IronPython?
– dymanoid
Nov 14 '18 at 12:39
I am using normal python (not IronPython). The import of dll is working fine and i am able to call hello() method of C# from my python code as given above. My concern is to define handler of C# delegate in my python code. I have searched but so far no success on it. Any idea how to get this working.
– Sakeer
Nov 15 '18 at 3:52
I am using normal python (not IronPython). The import of dll is working fine and i am able to call hello() method of C# from my python code as given above. My concern is to define handler of C# delegate in my python code. I have searched but so far no success on it. Any idea how to get this working.
– Sakeer
Nov 15 '18 at 3:52
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53300090%2fcalling-c-sharp-delegate-from-python%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
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53300090%2fcalling-c-sharp-delegate-from-python%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
If it python for .net that you are using?
– ctrl-alt-delor
Nov 14 '18 at 12:31
1
Notes: you should not put
r
in-front of string and escape ``. File path in line 4 in not portable (most OSs don't use back slash, slash should work on all/most. (File path is not portable on same OS as it may change.)– ctrl-alt-delor
Nov 14 '18 at 12:36
Are you using IronPython?
– dymanoid
Nov 14 '18 at 12:39
I am using normal python (not IronPython). The import of dll is working fine and i am able to call hello() method of C# from my python code as given above. My concern is to define handler of C# delegate in my python code. I have searched but so far no success on it. Any idea how to get this working.
– Sakeer
Nov 15 '18 at 3:52