|
-
Sep 7th, 2002, 09:08 PM
#1
how can I use a VB.NET file in C#?
I have a VB.NET class, I added it to a C# project and I tried to make an instance of that class in C#.....
I'm getting this error: "The type or namespace name 'Resizer' could not be found (are you missing a using directive or an assembly reference?)"
Rezier is the name of my VB class and this is my code:
Resizer a;
I dont even know if this is possible or not I just gave it a try....so is it possible? if so, what am I doing wrong?
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB )
VB.NET to C# conversion tips!!
-
Sep 7th, 2002, 10:55 PM
#2
I don't believe you can use it as a class specifically but you could compile it to a dll and then use it in the C# project.
-
Sep 8th, 2002, 01:33 AM
#3
Hyperactive Member
Originally posted by Edneeis
I don't believe you can use it as a class specifically but you could compile it to a dll and then use it in the C# project.
Hmm. I read somewhere that you can mix vb and c# code in the same project (so long as their in different files). I'll go look into it.
-
Sep 8th, 2002, 06:31 AM
#4
Frenzied Member
Make sure that you put the using statement at the top of the forms that you want to use that class in.
eg.
using Resizer;
Dont gain the world and lose your soul
-
Sep 8th, 2002, 05:21 PM
#5
Junior Member
Runtime OK - Dev not sure
Hi,
The IL - Intermediate Language... call it byte code - is definitely interchangeable. I'm not sure this is true for the source code in projects.
What certainly should work (didn't do it yet myself):
- write your VB.Net Class (.vb file)
- compile the assembly
- switch to the C# project
- add the VB assembly to the references of your C# project
- import (or use) the namespace -- not shure this is necessary
- you should now be able to declare a type variable with the VB class and instanciate it
I'll let you know if this works.
-
Sep 8th, 2002, 05:37 PM
#6
-
Sep 8th, 2002, 06:02 PM
#7
Junior Member
Some testing results
Hi,
I did the test and I could make it work as described in my previous post:
- build VB.Net project
- add it to references in my C# project (used the "Projects" tab and then "Browse..." to find the compiled VB assembly - otherwise you should add it to the GAC - good luck with that)
- instantiate it either by fully qualified name or by using a "using" directive at the top of the C# file
Some pitfalls:
- don't use the same name for both projects (.net gets confused then)
- you can't just add the project to the c# solution (I could't get this to work) and defenitely not add the VB file to the C# project (it doesn't even show up as a class in this case)
- beware of upper/lowercase (c# is case sensitive, VB not)
- don't use dashes (-) in any of the names (seems to be valid in VB but not in C#)
I hope this helps.
Bye!
-
Sep 8th, 2002, 06:07 PM
#8
Junior Member
Hi,
To compile - just open the project and hit Build (or Rebuild). You find the DLL (that contains the assembly) in the \bin subfolder of your project folder.
Success!
-
Sep 8th, 2002, 10:05 PM
#9
PowerPoster
And when compiling, make sure you have the word 'Release' in the text box instead of Debug. This will create a folder called release in the \bin folder. That will be your fully compiled dll that doesn't have debug info in it.
You have to make the reference to it before you can use it (early binding). I am sure you can still late bind in VB.Net, but I don't know how yet.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|