Note that there are some explanatory texts on larger screens.

plurals
  1. POMarshalling .NET Object when class is in another namespace
    text
    copied!<p>I am having a problem with Marshalling an object across application domains in a .NET Windows Service.</p> <p>I have created two app's that marshal an object across an app domain and run code through a proxy <code>MarshalByRefObject</code> </p> <p>The first application was a simple proof of concept since I do not have a lot of experience with marshalling across application domains. It contains a single project where the <code>MarshalByRefObject</code> is defined in the same namespace as the rest of the project. This app works fine, using almost the same code as my other app. The main difference is that the class I am Marshalling in the second app is defined in another Namespace.</p> <p>The other project is more complex, it is a Windows Service with multiple projects. The main Windows Service loads a library that that does the marshalling. The class type of the Marshal target type is defined in another library, so I use the fully qualified namespace/class name.</p> <p>The problem I am facing is that when it gets to the last line of the code below it throws an exception:</p> <p><strong>Could not load CompanyName.ProductGroup.BusinessObjects.ProductName.MarshalByRefScriptCompiler from assembly ProductNameService</strong> where product name is the main Windows Service class.</p> <p>The Code:</p> <pre><code>AppDomain compilerDomain = null; AppDomainSetup compilerDomainSetup; CompanyName.ProductGroup.BusinessObjects.ProductName.MarshalByRefScriptCompiler scriptCompiler; ... // Setup a seperate AppDomain compilerDomainSetup = new AppDomainSetup(); exeAssembly = Assembly.GetEntryAssembly().FullName; compilerDomainSetup.ApplicationBase = System.Environment.CurrentDirectory; compilerDomainSetup.DisallowBindingRedirects = false; compilerDomainSetup.DisallowCodeDownload = true; compilerDomainSetup.ConfigurationFile = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile; compilerDomain = AppDomain.CreateDomain("LiveLinkCSScriptDomain", null, compilerDomainSetup); // Create an instance of the MarshalByRefScriptCompiler in the other AppDomain scriptCompiler = (CompanyName.ProductGroup.BusinessObjects.ProductName.MarshalByRefScriptCompiler)compilerDomain.CreateInstanceAndUnwrap(exeAssembly, typeof(CompanyName.ProductGroup.BusinessObjects.ProductName.MarshalByRefScriptCompiler).FullName); </code></pre> <p>I have done research on this exception and almost everything I find says that it is a problem with versioning of the DLL, however my DLL's are not in the GAC, and there are no other versions installed. I am doing a clean build and installing the service with installutil.</p> <p>I used the <a href="http://msdn.microsoft.com/en-us/library/system.appdomain.aspx" rel="nofollow">MSDN documentation</a> as a guide for creating the code that does the marshalling</p> <p>I am wondering if there is an issue with loading the <code>MarshalByRefScriptCompiler</code> because the type is in another library. I am able to create a <code>MarshalByRefScriptCompiler</code> in a simple winforms app, but I get the exception in my windows service.</p> <p>Any tips or insight would be greatly appreciated!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload