471,325 Members | 1,790 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,325 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 1282
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Alexander Kervero | last post: by
reply views Thread by Eric Chaves | last post: by
reply views Thread by AntonB | last post: by
9 posts views Thread by viz | last post: by
6 posts views Thread by Bob Weiner | last post: by

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.