using a VB.net DLL in a C# app

if there was a .net section, I'd put the topic there!

Page 1 of 1

9 Replies - 5177 Views - Last Post: 05 August 2010 - 07:07 AM Rate Topic: -----

#1 atraub  Icon User is offline

  • Pythoneer
  • member icon

Reputation: 756
  • View blog
  • Posts: 1,990
  • Joined: 23-December 08

using a VB.net DLL in a C# app

Posted 03 August 2010 - 07:09 PM

Hey everyone, here's an interesting, although probably not a new issue. I'm trying to use a class I wrote in VB.net in a C# application. To keep things simple, I've made it a very simple class.

VB class: vbUtil (projUtilVB.vb)

Public Class vbUtil

    Public Shared Function displayMessageBox(ByVal msg As String) As Integer
        Return MsgBox(msg.ToString())
    End Function
End Class


I've tested this little function in the code-behind of an aspx page to make sure it works properly, albeit a little ugly:
vbUtil.displayMessageBox("I work!")

Posted Image

For part 2 of this project, I made an asp.net web app on C#. I then added a reference to the DLL created from building the VB class found in bin -> debug -> projUtilVB.dll.

using System;
using ProjUtilVB;

namespace PhentrakCS
{
    public static class projUtil
    {
        public static void testc()
        {
            vbUtil.displayMessageBox("hi");
        }
    }
}

The error I get is:
'ProjUtilVB.vbUtil' does not contain a definition for 'displayMessageBox'


I know I've used funny names, but it's half a test, half a side project i'm working on. Somewhere along the line there's a disconnect. It can clearly see the file, it can even see the class within the file, but it can't seem to hit that function.



UPDATE:
I rebuilt the solution and tried it again, and now it works. I can't explain it. Thanks to anyone who read it.

This post has been edited by atraub: 03 August 2010 - 07:34 PM


Is This A Good Question/Topic? 1
  • +

Replies To: using a VB.net DLL in a C# app

#2 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: using a VB.net DLL in a C# app

Posted 03 August 2010 - 07:44 PM

Glad you were able to solve the problem you were having. And thanks for sharing!
Was This Post Helpful? 0
  • +
  • -

#3 atraub  Icon User is offline

  • Pythoneer
  • member icon

Reputation: 756
  • View blog
  • Posts: 1,990
  • Joined: 23-December 08

Re: using a VB.net DLL in a C# app

Posted 03 August 2010 - 07:52 PM

Thanks, I know this is more of a vb.net question, but any ideas on how to make that box less ugly? It looks pretty bad lol.

This post has been edited by atraub: 03 August 2010 - 07:53 PM

Was This Post Helpful? 0
  • +
  • -

#4 Curtis Rutland  Icon User is online

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 4314
  • View blog
  • Posts: 7,472
  • Joined: 08-June 10

Re: using a VB.net DLL in a C# app

Posted 03 August 2010 - 09:12 PM

You'd just need to make a custom form, and design it the way you want. Then create an instance of it and .ShowDialog().
Was This Post Helpful? 1
  • +
  • -

#5 atraub  Icon User is offline

  • Pythoneer
  • member icon

Reputation: 756
  • View blog
  • Posts: 1,990
  • Joined: 23-December 08

Re: using a VB.net DLL in a C# app

Posted 04 August 2010 - 09:14 PM

View PostinsertAlias, on 03 August 2010 - 08:12 PM, said:

You'd just need to make a custom form, and design it the way you want. Then create an instance of it and .ShowDialog().


Sometimes the best answers are the simplest. Good thinking.
Was This Post Helpful? 0
  • +
  • -

#6 Curtis Rutland  Icon User is online

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 4314
  • View blog
  • Posts: 7,472
  • Joined: 08-June 10

Re: using a VB.net DLL in a C# app

Posted 04 August 2010 - 09:37 PM

Ha, I've done a few custom dialogs in my day. It's actually pretty easy to make an extensible dialog, with messages and variable numbers of buttons with variable text, using the "params" array in C#. I'm not sure what its counterpart in VB.NET is.

You can even make it behave like a MessageBox, that is, statically. Create a static method called ShowMyDialog or something that creates an instance, shows it, and returns its dialog result.
Was This Post Helpful? 0
  • +
  • -

#7 demausdauth  Icon User is online

  • D.I.C Addict
  • member icon

Reputation: 174
  • View blog
  • Posts: 629
  • Joined: 03-February 10

Re: using a VB.net DLL in a C# app

Posted 05 August 2010 - 12:50 AM

@atraub, I think you might run into problems using windows.forms controls with a web application. You might want to rethink the whole MsgBox thing. Not 100% sure but I thought I was reading about that in the ASP.NET forum.
Was This Post Helpful? 0
  • +
  • -

#8 Curtis Rutland  Icon User is online

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 4314
  • View blog
  • Posts: 7,472
  • Joined: 08-June 10

Re: using a VB.net DLL in a C# app

Posted 05 August 2010 - 06:18 AM

I don't see anything about this being a web application. But if it were, you absolutely would have problems using Windows Forms controls. Simply put, you can't use a messagebox or the like in ASP.NET, because all ASP.NET is executed on the server.
Was This Post Helpful? 0
  • +
  • -

#9 demausdauth  Icon User is online

  • D.I.C Addict
  • member icon

Reputation: 174
  • View blog
  • Posts: 629
  • Joined: 03-February 10

Re: using a VB.net DLL in a C# app

Posted 05 August 2010 - 06:21 AM

View Postatraub, on 03 August 2010 - 07:09 PM, said:

I've tested this little function in the code-behind of an aspx page to make sure it works properly, albeit a little ugly:


View Postatraub, on 03 August 2010 - 07:09 PM, said:

For part 2 of this project, I made an asp.net web app on C#. I then added a reference to the DLL created from building the VB class found in bin -> debug -> projUtilVB.dll.

Was This Post Helpful? 1
  • +
  • -

#10 Curtis Rutland  Icon User is online

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 4314
  • View blog
  • Posts: 7,472
  • Joined: 08-June 10

Re: using a VB.net DLL in a C# app

Posted 05 August 2010 - 07:07 AM

I fail at reading.

So yes, this entire idea must be scrapped.

The only reason it is showing up on your computer is because your computer is both the client and the server. If you were to host this ASPX page on another computer, you wouldn't see a popup at all.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1