473,789 Members | 2,740 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Class library

hi,
I wrote class library that contain a struct stX and a new class library that
get the first class library as referance and implement a function foo that
one of its parametrs is of type of the struct stX;

I wrote an application(exe ) that get the first class library as a referance
and have a member of type stX and have a referance of the second class
library and caled to its function foo.

The problem is when i pass the exe member of type stX to the class library
the compiler thinks it a diffrent type of the type the function foo needs
why???

Can i share types between dll and exe in diffrent way???
Thanks
Dec 1 '06 #1
4 1669
Works for me:

Put this in a Class Library project called StXLib:

using System;
using System.Collecti ons.Generic;
using System.Text;

namespace StXLib
{
public struct StX
{
public int i;
public double d;
}
}

Put this in a Class Library project called DoFooLib:

using System;
using System.Collecti ons.Generic;
using System.Text;

namespace DoFooLib
{
public class DoFoo
{
public double foo(StXLib.StX stx) {
return stx.d * stx.i;
}
}
}

Put this in a Console project called RefTest:

using System;
using System.Collecti ons.Generic;
using System.Text;

namespace RefTest
{
class RefTestExe
{
static void Main(string[] args)
{
StXLib.StX stx = new StXLib.StX();
DoFooLib.DoFoo df = new DoFooLib.DoFoo( );
stx.d = 11.1;
stx.i = 3;
double d = df.foo(stx);
Console.WriteLi ne(d.ToString() );
Console.WriteLi ne("Press a Enter to continue ...");
Console.ReadLin e();
}
}
}

Build it and run it. It should be fine.

Peter
"Dave" <be******@netvi sion.co.ilwrote in message
news:%2******** ********@TK2MSF TNGP03.phx.gbl. ..
hi,
I wrote class library that contain a struct stX and a new class library
that get the first class library as referance and implement a function foo
that one of its parametrs is of type of the struct stX;

I wrote an application(exe ) that get the first class library as a
referance and have a member of type stX and have a referance of the second
class library and caled to its function foo.

The problem is when i pass the exe member of type stX to the class library
the compiler thinks it a diffrent type of the type the function foo needs
why???

Can i share types between dll and exe in diffrent way???
Thanks

Dec 1 '06 #2
Ooops! Forgot to say about the references:

The StXLib project has no additional references over and above the standard
ones.

The DoFooLib references StXLib.

The RefTest project references DoFooLib and StXLib.

Apologies.

Peter

"Peter Bradley" <pb******@uwic. ac.ukwrote in message
news:%2******** ********@TK2MSF TNGP04.phx.gbl. ..
Works for me:

Put this in a Class Library project called StXLib:

using System;
using System.Collecti ons.Generic;
using System.Text;

namespace StXLib
{
public struct StX
{
public int i;
public double d;
}
}

Put this in a Class Library project called DoFooLib:

using System;
using System.Collecti ons.Generic;
using System.Text;

namespace DoFooLib
{
public class DoFoo
{
public double foo(StXLib.StX stx) {
return stx.d * stx.i;
}
}
}

Put this in a Console project called RefTest:

using System;
using System.Collecti ons.Generic;
using System.Text;

namespace RefTest
{
class RefTestExe
{
static void Main(string[] args)
{
StXLib.StX stx = new StXLib.StX();
DoFooLib.DoFoo df = new DoFooLib.DoFoo( );
stx.d = 11.1;
stx.i = 3;
double d = df.foo(stx);
Console.WriteLi ne(d.ToString() );
Console.WriteLi ne("Press a Enter to continue ...");
Console.ReadLin e();
}
}
}

Build it and run it. It should be fine.

Peter
"Dave" <be******@netvi sion.co.ilwrote in message
news:%2******** ********@TK2MSF TNGP03.phx.gbl. ..
>hi,
I wrote class library that contain a struct stX and a new class library
that get the first class library as referance and implement a function
foo that one of its parametrs is of type of the struct stX;

I wrote an application(exe ) that get the first class library as a
referance and have a member of type stX and have a referance of the
second class library and caled to its function foo.

The problem is when i pass the exe member of type stX to the class
library the compiler thinks it a diffrent type of the type the function
foo needs why???

Can i share types between dll and exe in diffrent way???
Thanks


Dec 1 '06 #3
PS

"Dave" <be******@netvi sion.co.ilwrote in message
news:%2******** ********@TK2MSF TNGP03.phx.gbl. ..
hi,
I wrote class library that contain a struct stX and a new class library
that get the first class library as referance and implement a function foo
that one of its parametrs is of type of the struct stX;

I wrote an application(exe ) that get the first class library as a
referance and have a member of type stX and have a referance of the second
class library and caled to its function foo.

The problem is when i pass the exe member of type stX to the class library
the compiler thinks it a diffrent type of the type the function foo needs
why???

Can i share types between dll and exe in diffrent way???
Perhaps you have declared stX in the exe and in the dll so they are in
different namespaces and are therefore considered to be different types.

PS

Dec 1 '06 #4
*Declaring* it in different namespaces shouldn't be a problem (see my reply
earlier in the thread). *Defining* it in more than one place (regardless of
namespace) would be a problem, but I can't see how the OP could have done
that. I've come across it in remoting code where soaputil is used to
generate a proxy: unless you use the -gc option, this will provide a
definition of every class used by the file, within the generated dll and so
will cause the problem described. We aren't talking about anything as
esoteric as that, though, I don't think.

Something else that can be a problem would be if the assembly containing the
struct had been given a strong name, but the version had not been fixed in
the AssemblyInfo.cs file. This can mean that two references that look
identical are actually pointing to different versions if there's been a
recompile between setting the references. This would give the symptoms
described.

But unless and until the OP replies, we're just guessing.
Peter
"PS" <ec***********@ hotmail.comwrot e in message
news:en******** ******@TK2MSFTN GP06.phx.gbl...
>
Perhaps you have declared stX in the exe and in the dll so they are in
different namespaces and are therefore considered to be different types.

PS

Dec 4 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
1963
by: syd | last post by:
In my project, I've got dozens of similar classes with hundreds of description variables in each. In my illustrative example below, I have a Library class that contains a list of Nation classes. In one case, I might want a Library class with only Nations of with the continent variable "Europe", and so I'll do something like library.getContinent('Europe') which will return a Library() instance with only European nations. Similarly, I...
6
6181
by: Patrick | last post by:
Following earlier discussions about invoking a .NET class library via ..NET-COM Interop (using regasm /tlb) at http://groups.google.com/groups?hl=en&lr=&threadm=%23Van7eSrEHA.4004%40TK2MSFTNGP10.phx.gbl&rnum=1&prev=/groups%3Fhl%3Den%26lr%3D%26selm%3D%2523Van7eSrEHA.4004%2540TK2MSFTNGP10.phx.gbl I have concluded that my .NET class library (following the suggestions. namely setting the marshall type, etc.) , I can 1) Invoke public methods...
4
1771
by: Brian Shannon | last post by:
I am playing around with class libraries trying to understand how they work. I created a class library, library.vb. I placed the library.dll into the bin directory and set my reference. If I update the library.dll can I Just place the new .dll in the bin directory or do I need to recompile my program. During testing I am just placing the new library.dll in the bin directory and don't get any of the updates I made until I re-reference...
3
1642
by: eBob.com | last post by:
I have several applications which mine web sites for personal information which they publish. They publish the info in one form, I transform the info into Excel spreadsheets. So all these programs pick up name, telephone number, age, sex, etc.. And as they pick up the information they display it in text boxes. The text boxes are display only, and the info is displayed only for debugging purposes. Right now I have a lot of duplicate...
5
1947
by: Tony Johansson | last post by:
Hello! I have one solution file that consist of three project. One project that build the exe file called A One project that build a user control dll. Here we have a class called B One project that build a class library dll. Here we have a class called C We have one dependency and that is from the user control to the class library because in the constructor for class B in the user control we have a call to
0
1756
by: tony | last post by:
Hello! I have one solution file that consist of three project. One project that build the exe file called A One project that build a user control dll. In this user control we have a class called B One project that build a class library dll. In this class library we have a class called C In the user control project I have a project reference to the class library.
5
1999
by: tony | last post by:
Hello! This is a rather long mail but it's a very interesting one. I hope you read it. I have tried several times to get an answer to this mail but I have not get any answer saying something like this is a bug or that .NET doesn't support what I trying to do. I hope that one that is is microsoft certified read this because this must be a bug.
5
8614
by: Rainer Queck | last post by:
Hello NG, Is it possible to share the settings of an application with a class libreary? In my case I have a application and a set of different reports (home made) put into a class library. The plan is to delivere different report.dlls with the main app. But it is essentially importent, that the reports and the app use the same settings.
0
2410
by: drawing in aspnet | last post by:
Question about putting the data layer in a separate class library. I keep reading that the data layer should be separated from the presentation layer and put in its own class library. I am trying to do this but running into a problem. I'm hoping someone can point me in the right direction. I first create a class library (all code in C#) and within this class library create a very simple Sql Server Express database (.mdb) file. It's...
4
1391
by: Steve Baer | last post by:
I've already tested this with C# and it works, but I'm being paranoid and I wanted to also check here. Our application has a large class library written in C++/CLI for plug-in projects. The original library was written in C++ and the general rule for not breaking our SDK is to not change the class size by adding member variables and to not add virtual functions because this will change the vtable for the class. This is fine and we know...
0
10410
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10200
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9984
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9020
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5418
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5551
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4093
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3701
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2909
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.