473,412 Members | 2,284 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,412 software developers and data experts.

using duplicated class

Two assemblies both referenced by application contain same class (created by
script):

namespace Script
{
public class Class1 { }
}
Compiling application

class Program
{
static void Main()
{
var t = new Script.Class1();
}
}
causes error

The type 'Script.Class1' exists in both
'c:\myapp\Project1\bin\Release\Project1.dll' and
'c:\myapp\Project2\bin\Release\Project2.dll'
How to force compiler to use specific assembly, like

var t = new Script.Class1@",
Assembly=C:\Users\Andrus\Temp\TempAssembly.dll"
();

Andrus.

Aug 4 '08 #1
3 1360
On Aug 3, 7:17*pm, "Andrus" <kobrule...@hot.eewrote:
Two assemblies both referenced by application contain same class (createdby
script):

namespace Script
{
* * public class Class1 { }

}

Compiling application

class Program
{
* * static void Main()
* * {
* * * * var t = new Script.Class1();
* * }

}

causes error

The type 'Script.Class1' exists in both
'c:\myapp\Project1\bin\Release\Project1.dll' and
'c:\myapp\Project2\bin\Release\Project2.dll'

How to force compiler to use *specific assembly, like

*var t = new Script.Class1@",
Assembly=C:\Users\Andrus\Temp\TempAssembly.dll"
();
Go into Properties of each reference (in Solution Explorer, expand
References under your project, right-click on a specific reference,
and select Properties). There is a property called "Aliases" - change
it so that it is different for references to Project1 and to Project2
- simplest is just to use "Project1" and "Project2". Now you can use
the "extern alias" directive in the .cs file where you need to
disambiguate:

extern alias Project1;
extern alias Project2;

and disambiguate as needed using double-colon operator:

Project1::Script.Class1
Project2::Script.Class2
Aug 4 '08 #2
Pavel has given the answer to the specific question (extern alias),
but note that it is worth trying to avoid this scenario where-ever
possible. Perhaps consider making the namespace specific for each
script? So you have

Project1.Script.Class1 in Project1.dll
and
Project2.Script.Class1 in Project2.dll

Much simpler and more maintainable.

Marc
Aug 4 '08 #3
Marc,
Perhaps consider making the namespace specific for each
script? So you have

Project1.Script.Class1 in Project1.dll
and
Project2.Script.Class1 in Project2.dll

Much simpler and more maintainable.
I'm planning to allow end users to override entity objects for custom
default values and validation using scripting.
Custom entity classes are created dynamically by entity factory. For
example, user can create the following script:

namespace MyApp.Script {
public class Invoice : MyApp.Business.Invoice {
public override void OnCreated(object sender, CreateEventArgs e) {
// set default customer for new invoice
this.CustomerId = "123";
}
}
}

Another, Query creation script which returns only some properties which we
discussed earlier refers to this object by using "MyApp.Script.Invoice".

User can also modify script at runtime, for example change CustomerId to
"456".
In this cases entity factory creates new type but it has same namespace and
name:

After that compiler error occurs in query creation script since script
engine adds references to all assemblies referenced by application to
compiler.

Possible solutions:

1. How I can use global aliases or different namespaces in this case ?

2. Create all other class creation scripts so that they take entity type as
generic type parameter.
In this case application can pass entity to type created by script using
MakeGenericType()

3. Should I create Linq expression insted of script ? I need to modify your
earlier selected property selection sample but
I do'nt know how to make such modification.

4. Should I use delegates and static methods insted of entity class dynamic
override ?

5. Modify script engine to add reference only to latest entity assembly to
compiler.

I don't know which is best solution. I will try solution 2 first since this
seems to be simplest to implement.

Andrus.

Aug 4 '08 #4

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

Similar topics

1
by: Alexander Kervero | last post by:
Hi ,today i was reading diveinto python book,in chapter 5 it has a very generic module to get file information,html,mp3s ,etc. The code of the example is here :...
3
by: Mirek Rusin | last post by:
....what is the best way to force duplicated unique or primary key'ed row inserts not to raise errors? duplicated rows can be ignored or updated as well - it really doesn't matter. to be...
1
by: Iain | last post by:
I'm struggling to create a typed data set (with xsd.exe) with 4 tables and 3 layers orders -> Items Items->ItemAtts1 Items->ItemAtts2 if you follow me. it's kind of working, but I don't...
0
by: Eric Chaves | last post by:
Hi Folks I'm tryingto use the EventLog class to wrote info on my own log (ie, not in Application). If I use the same text for Source and LogName, everything goes right. If I try to use asource...
0
by: AntonB | last post by:
I am using Visual Studio 2005 Beta1 and get the following errors when building a .NET class library (called TryDLLPr in the example below). Any advice on what's wrong will be greatly appreciated. ...
4
by: Jeff | last post by:
We have multiple ASP.Net web apps in development. As a standard we are looking to go with SQL Server to hold state information. Can we have the multiple apps all point to a single State DB? Or...
9
by: viz | last post by:
hi, i have written a class for session handling, and i want to use it to keep track of the user. After authenticating the user in login page i am storing the session info like uname etc.. in a...
6
by: Ryan Liu | last post by:
Hi, If I have tens of thousands DataRow in a DataTable and allow the end user to pick any DataColumn(s) to check for duplicated lines, the data is so large, is there a better API, algorithm can...
6
by: Bob Weiner | last post by:
I have a few dll's that return their own version of Account objects. In the asp code I am writing now I would like to define an interface, called IAccount, and convert each of these objects (...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.