Kingherc Posted April 29, 2004 Posted April 29, 2004 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! Quote
Administrators PlausiblyDamp Posted April 29, 2004 Administrators Posted April 29, 2004 Dim nn as new NamespaceInDll.ClassINDll() should work. Is the class in the cs file declared as public class ClassInDll though? If not it will need to be public Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
bungpeng Posted April 29, 2004 Posted April 29, 2004 You should let us know what error message you got Quote
Kingherc Posted April 29, 2004 Author Posted April 29, 2004 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... Quote
bungpeng Posted April 29, 2004 Posted April 29, 2004 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 Quote
Kingherc Posted April 29, 2004 Author Posted April 29, 2004 The error message says that the Type is not defined. (hell of a specific error eh?) Quote
Administrators PlausiblyDamp Posted April 29, 2004 Administrators Posted April 29, 2004 Is the dll listed under the references correctly? Is the namespace correct? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Denaes Posted April 29, 2004 Posted April 29, 2004 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? Quote
Kingherc Posted April 29, 2004 Author Posted April 29, 2004 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? Quote
Denaes Posted April 29, 2004 Posted April 29, 2004 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. Quote
Kingherc Posted April 29, 2004 Author Posted April 29, 2004 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? Quote
akiaz Posted April 29, 2004 Posted April 29, 2004 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. Quote
Kingherc Posted April 29, 2004 Author Posted April 29, 2004 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. Quote
*Experts* Nerseus Posted April 30, 2004 *Experts* Posted April 30, 2004 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 Quote "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
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.