1

私は非常に単純なクラスCompiledFunction(MarshalByRefObject)を持っています-私はこのような新しいドメインでこれのインスタンスを作成しようとします

var appDomainSetup = new AppDomainSetup();
appDomainSetup.ApplicationBase = Path.GetDirectoryName(typeof(CompilerService).Assembly.CodeBase);
var evidence = AppDomain.CurrentDomain.Evidence;
SandboxDomain = AppDomain.CreateDomain("Sandbox", evidence, appDomainSetup);

CompiledFunction<T> result = (CompiledFunction<T>)SandboxDomain.CreateInstanceAndUnwrap(
    assemblyName: typeof(CompiledFunction<T>).Assembly.GetName().Name,
    typeName: typeof(CompiledFunction<T>).FullName);

これはコンソールアプリケーションでは正常に機能しますが、ASP .NET MVCアプリケーションでは次の例外が発生します-これがWebアプリで機能しない理由について誰かが提案できますか?私が渡しているTパラメータはSystem.Decimalです。

System.IO.FileLoadException was caught
  Message=The given assembly name or codebase, 'Ems.Scripting, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null', was invalid.
  Source=mscorlib
  FileName=Ems.Scripting, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
  FusionLog==== Pre-bind state information ===
LOG: User = EMSLaptop\PeterMorris
LOG: DisplayName = Ems.Scripting, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
 (Fully-specified)
LOG: Appbase = /C:/Users/PeterMorris/Documents/Visual Studio 2010/Projects/MvcApplication26/MvcApplication26/bin
LOG: Initial PrivatePath = NULL
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Found application configuration file (C:\Program Files\Common Files\Microsoft Shared\DevServer\10.0\WebDev.WebServer40.exe.Config).
LOG: Using application configuration file: C:\Program Files\Common Files\Microsoft Shared\DevServer\10.0\WebDev.WebServer40.exe.Config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL /C:/Users/PeterMorris/Documents/Visual Studio 2010/Projects/MvcApplication26/MvcApplication26/bin/Ems.Scripting.DLL.

  StackTrace:
       at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
       at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
       at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection, Boolean suppressSecurityChecks)
       at System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
       at System.Activator.CreateInstance(String assemblyName, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, Evidence securityInfo, StackCrawlMark& stackMark)
       at System.Activator.CreateInstance(String assemblyName, String typeName)
       at System.AppDomain.CreateInstance(String assemblyName, String typeName)
       at System.AppDomain.CreateInstanceAndUnwrap(String assemblyName, String typeName)
       at System.AppDomain.CreateInstanceAndUnwrap(String assemblyName, String typeName)
       at Ems.Scripting.CompilerService.Compile[T](String[] scripts, Dictionary`2 variableDefinitions, IEnumerable`1 referencedAssemblies, ICompiledFunction`1& function, IEnumerable`1& compilerErrors) in C:\Data\EMS\Lib\Ems.Scripting\CompilerService.cs:line 43
  InnerException: 
4

2 に答える 2

3

問題は、Assembly.Codeベースがfile:/// {残りのパスはここ}で始まっていたことでした。このようなパスでPath.GetDirectoryNameを使用すると、file:///が単一のスラッシュに置き換えられます。したがって、「/ c:\ myfolder\myfile.dll」になります。

Uriにローカルパスを教えてもらうことが解決策でした

if (SandboxDomain == null)
{
    var appDomainSetup = new AppDomainSetup();
    string appBase = typeof(CompilerService).Assembly.CodeBase;

    //Added the following line
    appBase = new Uri(appBase).LocalPath;
    appDomainSetup.ApplicationBase = Path.GetDirectoryName(appBase);
    var evidence = AppDomain.CurrentDomain.Evidence;
    SandboxDomain = AppDomain.CreateDomain("Sandbox", evidence, appDomainSetup);
}
于 2012-04-27T22:33:47.600 に答える
0

WebプロジェクトのEms.Scriptingアセンブリを適切にコピーしていないか、新しいドメインに間違ったApplicationBaseを設定していないようです(可能性が高いです)。

Path.GetDirectoryName呼び出しは、ApplicationBaseプロパティの計算で疑わしいものです。

于 2012-04-27T18:04:55.530 に答える