Newbie question

  • Thread starter Thread starter Mike
  • Start date Start date
M

Mike

I'm a VB .NET programmer and I have a C# class that I'd like to use in VB.
Can I compile the class into a DLL that can be utilized by VB .NET?
 
Mike,

Yes, you can. VB.NET, C#, basically any .NET language will compile to
IL, which the Common Language Runtime (CLR) will then execute.

Hope this helps.
 
Thanks for Nicholas and Vanessa's quick response.

Hi Mike,

Thank you for posting in the community!

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to utilize an assembly that
was programmed with C# in VB.NET. If there is any misunderstanding, please
feel free to let me know.

This is possible in .NET. Actually, this is one of the coolest features
..NET has. As Nicholas mentioned, all the languages are compiled into
Intermediate Language (IL). If you want to use that DLL in your VB.NET
project, just select Add Reference from the Project menu in IDE. Browse to
that DLL and reference it. In fact, all .NET assemblies can be utilized in
any .NET project, in spite of the language that DLL as written with.

Here is a link with more information about compiling to MSIL.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/htm
l/cpconmicrosoftintermediatelanguagemsil.asp

HTH. If anything is unclear, please feel free to reply to the post.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
Someone wrote a class in C# that I would like to use in VB. It is available
here: http://www.alexfeinman.com/download.asp?doc=DataGridEvenOddRows.zip

I tried compiling the C# class into a DLL and referencing it from VB, but I
then get the following errors when building my project (Smart Device
Project):
------ Build started: Project: Pharm, Configuration: Debug Pocket PC ------

Preparing resources...

Updating references...

Error: The dependency 'mscorlib, Version=1.0.5000.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089' in project 'Pharm' cannot be copied to the
run directory because it would conflict with dependency 'mscorlib,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=969db8053d3322ac'.

Error: The dependency 'mscorlib, Version=1.0.5000.0, Culture=neutral,
PublicKeyToken=969db8053d3322ac' in project 'Pharm' cannot be copied to the
run directory because it would conflict with dependency 'mscorlib,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.

I've never built a DLL in C# before, so I probably did something wrong.
 
Hi Mike,

Based on the error message you have provided, it seems that the problem has
nothing to do with the C# dll. I think this is related with the device. I
don't quite understand why the deployment needs to replace mscorlib on your
smart device, as this is a part of .NET compact framework. Could you
reproduce it on another clean device?

If anything is unclear, please feel free to reply to the post.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
I think the problem has everything to do with the C# dll: when I remove the
reference to the C# dll, the error message goes away. There is no device
connected to my computer when I select "Build Solution" from the Build menu
and I receive the following messages in the Output window:

------ Build started: Project: Pharm, Configuration: Debug Pocket PC ------

Preparing resources...

Updating references...

Error: The dependency 'mscorlib, Version=1.0.5000.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089' in project 'Pharm' cannot be copied to the
run directory because it would conflict with dependency 'mscorlib,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=969db8053d3322ac'.

Error: The dependency 'mscorlib, Version=1.0.5000.0, Culture=neutral,
PublicKeyToken=969db8053d3322ac' in project 'Pharm' cannot be copied to the
run directory because it would conflict with dependency 'mscorlib,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.

Performing main compilation...

Building satellite assemblies...

Visual Studio is ready to deploy Pharm





---------------------- Done ----------------------

Build: 0 succeeded, 1 failed, 0 skipped



It is not doing a deployment, just a build.
 
Hi Mike,

To resolved the problem more quickly, could you please send me a package
that can reproduce the problem? Remove 'online' from the no spam email is
my real email address. Thanks for your cooperation!

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
Hi Mike,

I have checked the code and found that you are trying to build the DLL as a
windows class library assembly. As we know, the smart device application
can only consume a smart device class library assembly. The two kinds of
class libraries references different versions of mscorlib.dll in .NET
framework. The windows class library references mscorlib in .NET framework
while the Smart Device Application references mscorlib in .NET compact
framework. As the DLL cannot find the corresponding mscorlib file on the
compact framework and result in the error.

So please try to build the DLL as a smart device assembly. Here are the
steps:

1. Start VS.NET and click New Project.
2. In the left tree select Visual C# Projects. In the right pane, select
Smart Device Applications. Click OK.
3. In the Smart Device Application Wizard, choose Pocket PC as the platform
and select Class Library as project type. Click OK. The new project will be
created.
4. Copy file GridEvenOddHandler.cs to the newly created project folder.
5. In the Solution Explorer, right click the project name
"SmartDeviceApplication1" and select Add / Add Existing Item.
6. Click on GridEvenOddHandler and click open button. Thus we add the C#
code to the class library.
7. Select Project / Add Reference from the main menu.
8. Add references to System.Drawing, System.Windows.Forms,
System.Windows.Forms.DataGrid, and click OK. The C# code use classes in
these namespaces, while these assemblies are not referenced by default. So
we have to add them manually.
9. Rebuild the solution, and now, the new DLL can be comsumed by other
Smart Device Applications.

HTH. If anything is unclear, please feel free to reply to the post.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
You're welcome, Mike. Thanks again for sharing your experience with us. If
you have any questions, please feel free to post them in the community. We
will try our best to help you.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
Back
Top