473,395 Members | 1,348 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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 1651
Works for me:

Put this in a Class Library project called StXLib:

using System;
using System.Collections.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.Collections.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.Collections.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.WriteLine(d.ToString());
Console.WriteLine("Press a Enter to continue ...");
Console.ReadLine();
}
}
}

Build it and run it. It should be fine.

Peter
"Dave" <be******@netvision.co.ilwrote in message
news:%2****************@TK2MSFTNGP03.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****************@TK2MSFTNGP04.phx.gbl...
Works for me:

Put this in a Class Library project called StXLib:

using System;
using System.Collections.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.Collections.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.Collections.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.WriteLine(d.ToString());
Console.WriteLine("Press a Enter to continue ...");
Console.ReadLine();
}
}
}

Build it and run it. It should be fine.

Peter
"Dave" <be******@netvision.co.ilwrote in message
news:%2****************@TK2MSFTNGP03.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******@netvision.co.ilwrote in message
news:%2****************@TK2MSFTNGP03.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.comwrote in message
news:en**************@TK2MSFTNGP06.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
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. ...
6
by: Patrick | last post by:
Following earlier discussions about invoking a .NET class library via ..NET-COM Interop (using regasm /tlb) at...
4
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...
3
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...
5
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...
0
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...
5
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...
5
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...
0
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...
4
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...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...

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.