Click here to Skip to main content
15,912,400 members
Home / Discussions / C#
   

C#

 
GeneralRe: Invalid Cast exception Pin
Heath Stewart16-Apr-05 10:15
protectorHeath Stewart16-Apr-05 10:15 
GeneralRe: Invalid Cast exception Pin
Heath Stewart16-Apr-05 10:20
protectorHeath Stewart16-Apr-05 10:20 
GeneralRe: Invalid Cast exception Pin
tantiboh16-Apr-05 13:59
tantiboh16-Apr-05 13:59 
GeneralCrystal Report Speed Pin
Kyaw Soe Khaing16-Apr-05 9:20
Kyaw Soe Khaing16-Apr-05 9:20 
GeneralDynamic Assemblies Pin
Pepperman500016-Apr-05 4:45
Pepperman500016-Apr-05 4:45 
GeneralRe: Dynamic Assemblies Pin
Heath Stewart16-Apr-05 8:11
protectorHeath Stewart16-Apr-05 8:11 
GeneralRe: Dynamic Assemblies Pin
Pepperman500016-Apr-05 8:33
Pepperman500016-Apr-05 8:33 
GeneralRe: Dynamic Assemblies Pin
Heath Stewart16-Apr-05 8:43
protectorHeath Stewart16-Apr-05 8:43 
That's to be expected, based on the quote I posted. The reflection-related classes are not MarshalByRefObject implementation and are not serializable so they cannot be remoted across AppDomain boundaries. In the case of Assembly.Load (from where that quote was taken) an Assembly could be returned, but it will cause the assembly you load to be re-loaded into the current AppDomain. In your case, since you're defining a dynamic assembly there is no assembly to return.

As the exception states, too, AssemblyBuilder is not serializable, just like an Assembly reference you're trying to create.

In short, this isn't really possible doing it like you're trying to do.

That's not to say there isn't a way, however. Create an assembly factory class that is remotable (extends MarshalByRefObject and is attributed with SerializableAttribute and load that into a new AppDomain, then make remoted calls on it in order to create a dynamic assembly. Since the factory exists in the new AppDomain, when it calls DefineDynamicAssembly in will be in the scope of the new AppDomain.

Read Accessing Objects in Other Application Domains Using .NET Remoting[^] for more abour remoting. .NET provides a remoting channel for specifically communicating between AppDomains in the same process, so you do not want to specify a TcpChannel or HttpChannel like you'd use to communicate between two disparate processes, potentially on two different machines.

This posting is provided "AS IS" with no warranties, and confers no rights.

Software Design Engineer
Developer Division Customer Product-lifecycle Experience
Microsoft

[My Articles] [My Blog]
GeneralRe: Dynamic Assemblies Pin
Pepperman500016-Apr-05 8:50
Pepperman500016-Apr-05 8:50 
GeneralManaging access in nested classes Pin
matthias s.16-Apr-05 4:17
matthias s.16-Apr-05 4:17 
GeneralRe: Managing access in nested classes Pin
leppie16-Apr-05 5:53
leppie16-Apr-05 5:53 
GeneralRe: Managing access in nested classes Pin
Phil Harding16-Apr-05 14:54
Phil Harding16-Apr-05 14:54 
GeneralCross-Frame access Pin
Anonymous16-Apr-05 4:07
Anonymous16-Apr-05 4:07 
GeneralRe: Cross-Frame access Pin
Heath Stewart16-Apr-05 8:46
protectorHeath Stewart16-Apr-05 8:46 
GeneralRe: Cross-Frame access Pin
Anonymous16-Apr-05 9:33
Anonymous16-Apr-05 9:33 
GeneralRe: Cross-Frame access Pin
Heath Stewart16-Apr-05 9:37
protectorHeath Stewart16-Apr-05 9:37 
GeneralRe: Cross-Frame access Pin
Anonymous16-Apr-05 10:05
Anonymous16-Apr-05 10:05 
GeneralRe: Cross-Frame access Pin
Heath Stewart16-Apr-05 10:32
protectorHeath Stewart16-Apr-05 10:32 
GeneralRe: Cross-Frame access Pin
Anonymous16-Apr-05 10:52
Anonymous16-Apr-05 10:52 
Generalhelp me plz Pin
fekra16-Apr-05 4:03
fekra16-Apr-05 4:03 
GeneralRe: help me plz Pin
Colin Angus Mackay16-Apr-05 10:49
Colin Angus Mackay16-Apr-05 10:49 
Questioncenter text? Pin
Larsson16-Apr-05 3:33
Larsson16-Apr-05 3:33 
AnswerRe: center text? Pin
Heath Stewart16-Apr-05 10:00
protectorHeath Stewart16-Apr-05 10:00 
GeneralRe: center text? Pin
Larsson16-Apr-05 10:11
Larsson16-Apr-05 10:11 
GeneralRe: center text? Pin
Heath Stewart16-Apr-05 10:24
protectorHeath Stewart16-Apr-05 10:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.