如果不添加dll引用,如何从VB.net调用C#方法 [英] Without adding dll reference, how to call C# method from VB.net

查看:102
本文介绍了如果不添加dll引用,如何从VB.net调用C#方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有C#dll包含方法。

我需要在运行时加载这个dll而不添加引用并从VB.net调用C#方法。

I have C# dll which contains method .
I need to load this dll on runtime without adding reference and call C# method from VB.net.

推荐答案

虽然您可以使用反射来执行此操作,但它很慢并且容易出现故障:如果目标DLL被删除或更改,则当您尝试使用它来调用该方法时,您的应用程序将会失败。这可能为时已晚:您可能会丢失用户数据。



这是一个很多,更好的想法使用一个引用:方法和它的必需参数然后在编译时检查,它会工作,或者当你的应用程序试图启动时你会收到无法找到的错误。



有充分的理由吗强迫自己反思?如果可以避免这种情况通常不是一个好主意。
While you can use reflection to do this, it's slow, and prone to failure: if the target DLL is removed or changed, your app will fail when it tries to use it to call the method. This is likely to be too late: you can lose user data.

It's a lot, lot better idea to use a reference: the method and it's required parameters are then checked at compile time, and it will work, or you will get a "could not be found" error when you application tries to start.

Is there a good reason for forcing yourself into reflection? It's not normally a good idea if it can be avoided.


这篇关于如果不添加dll引用,如何从VB.net调用C#方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆