Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I now write a .net application in VB.NET in Visual Studio 2003.NET (but for the .net compact framework). But I also have a ready C# file that I want to use-integrate and use it in my application. But the project only accepts .vb files and not .cs. So I figured I should make a dll file out of the .cs so as to use it in my app. (I used csc.exe to do that).

 

The dll contains a namespace and a class.

How do I integrate it with my project so that I can create a new object with the class in the dll file?

I tried adding the dll in the Referenced but it still shows this line wrong:

Dim nn

nn = new NamespaceInDll.ClassInDll()

 

 

What's wrong? And how do I use the dlls? Plz, give me simple vb.net help cause the help topics are very complex.

 

Thx for any responses!

Posted

No no. The problem is not with declaring i think. It's public though. I don't know how to make Vstudio recognize the class so that I can create an object with the class freely.

I can write code but I dunno how to relate the dll with the application...

Posted

Your current way should work, because my application also work similar with you (work with external dll files), the only different is they are same languages.

 

But now you have not let me know what is the error message, maybe it is only due to your simple mistake

Posted

I tried adding the dll in the Referenced but it still shows this line wrong:

Dim nn

nn = new NamespaceInDll.ClassInDll()

 

Ok, after you reference your dll, you've gone over to the References folder in your Solution Explorer and verified that your NameSpace is showing up there?

 

When you type the NamespaceInDll and type a . (dot), does intelisense pick it up?

Posted

Well I think I found the error. When I reference the dll the class viewer browser finds the dll and shows the namespace and the class. And finally the editor recognizes the Dim line. But now, when I try to start the application it shows the following two errors upon build (only when I reference the dll):

 

Error: The dependency 'mscorlib, Version=1.0.5000.0,

Culture=neutral, PublicK

project 'PocketImageEdit

directory because it wou

Version=1.0.5000.0, Culture=neutral,

PublicKeyToken=b77a5c561934e089'.

 

Error: The dependency 'mscorlib, Version=1.0.5000.0,

Culture=neutral, PublicKeyToken=b77a5c561934e089' in

project 'PocketImageEditor' cannot be copied to the run

directory because it would conflict with dependency 'mscorlib

Version=1.0.5000.0, Culture=neutral,

PublicKeyToken=969db8053d3322ac'.

 

Well I think it has to do with the dll compiling from the C# code script. But how do I fix this?

Posted
Well I think I found the error. When I reference the dll the class viewer browser finds the dll and shows the namespace and the class. And finally the editor recognizes the Dim line. But now, when I try to start the application it shows the following two errors upon build (only when I reference the dll):

 

Error: The dependency 'mscorlib, Version=1.0.5000.0,

Culture=neutral, PublicK

project 'PocketImageEdit

directory because it wou

Version=1.0.5000.0, Culture=neutral,

PublicKeyToken=b77a5c561934e089'.

 

Error: The dependency 'mscorlib, Version=1.0.5000.0,

Culture=neutral, PublicKeyToken=b77a5c561934e089' in

project 'PocketImageEditor' cannot be copied to the run

directory because it would conflict with dependency 'mscorlib

Version=1.0.5000.0, Culture=neutral,

PublicKeyToken=969db8053d3322ac'.

 

Well I think it has to do with the dll compiling from the C# code script. But how do I fix this?

 

When you create a dll (or any program) you have to include its' dependancies with it. When you create a dependancy (like to winforms or whatever) it creates a dependancy, but since the version becomes part of the files name, it knows that you're supposed to reference mscorlib v1.0.5000.0 which is in the CLR (.net framework) 1.1

 

Do you not have .net framework 1.1? Was the project (PocketImageEditor) started when you hade the framework 1.0?

 

I don't know what the issue on your machine is, but the dll is dependant on CLR 1.1.

 

If you're not using 1.1 you may need to recompile it using 1.0 (or whatever version you're using) so that it references the other version.

Posted
When you create a dll (or any program) you have to include its' dependancies with it. When you create a dependancy (like to winforms or whatever) it creates a dependancy, but since the version becomes part of the files name, it knows that you're supposed to reference mscorlib v1.0.5000.0 which is in the CLR (.net framework) 1.1

 

Do you not have .net framework 1.1? Was the project (PocketImageEditor) started when you hade the framework 1.0?

 

I don't know what the issue on your machine is, but the dll is dependant on CLR 1.1.

 

If you're not using 1.1 you may need to recompile it using 1.0 (or whatever version you're using) so that it references the other version.

My project works for smartphone 2003, so it uses .net compact framework 1.0. The program is ran in the emulator. But on my PC i have installed .net framework 1.1 (from the beginning). So, how do I define the dependancy for the dll file when I compille it?

Posted
You are correct in your original statement about the project only accepting vb files, but you can have a VB project and a C# project in the same solution. Then you can set a reference in your VB project to your C# project. Your C# DLL will compile and be automatically copied to your VB project \bin directory. This should take care of your dependency error.
Posted

You were partially right. I did the following thing (that was more simple, but hardly to be found):

I compliled the C# project in a class library and not as a Windows Application. Then I copied the .dll file that was created when the project was built and referenced it in my project. And it works fine now.

  • *Experts*
Posted

With your current "solution", Kingherc, you should be able to use akiaz's suggestion and make your life a lot simpler.

 

1. From the solution that has your VB project, right click the solution and select "Add Existing Project" and point it to the C# project file.

 

2. Remove the reference to the C# DLL in your VB project.

 

3. Add a new reference in the VB project (right click References). Click the "Projects" tab and you should see the C# project.

 

Assuming the C# project is still set as "Class Library", it should work fine.

 

-Nerseus

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...