none
IHostAssemblyStore::ProvideAssembly give wrong pBindInfo: AssemblyBindInfo parameter! RRS feed

  • Question

  • Hi, I convert the C++ CLR Host to Delphi.

    var
      mHost: TClrHost;
      mRetValue: Cardinal;
      mAssemblyLoader: IHostAssemblyManager;
      mHostControlObj: THostControl;
      mHostControl: IHostControl;
      mCLRControl: ICLRControl;
      mDomainManager: ICosxDomainManager;
    begin
      mHost := TClrHost.Create();
      try
        mAssemblyLoader := TCosxAssemblyManager.Create('D:\CoShare\bin\');
        mHostControlObj := THostControl.Create(mAssemblyLoader);
        mHostControl := mHostControlObj;
        mHost.SetHostControl(mHostControl);

        mCLRControl := mHost.GetCLRControl;
        mCLRControl.SetAppDomainManagerType(
          'CosxRuntime, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null',
          'CosxRuntime.CosxDomainManager');

        mHost.Start();
        mmoInfo.Lines.Add('CorSystemDirecotry:' + mHost.CorSystemDirectory());
        mmoInfo.Lines.Add('CorVersion:' + mHost.CorVersion());
        mmoInfo.Lines.Add('CorRequiredVersion:' + mHost.CorRequiredVersion());

        mDomainManager := mHostControlObj.GetDomainManagerForDefaultDomain();
        mDomainManager.Run('XbrlExplorer, Version=1.0.0.0,  PublicKeyToken=null, culture=neutral', 'CoShare.XbrlExplorer.Program');
        //mHost.ExecuteInDefaultAppDomain('D:\CoShare\bin\XbrlExplorer.exe', 'CoShare.XbrlExplorer.Program', 'HostEntry', '', mRetValue);
        mHost.Stop();
      finally
        if(mHostControl <> nil) then
          mHostControl := nil;
        mHost.Free;
      end;

    end;

    function TCosxAssemblyStore.ProvideAssembly(
      const pBindInfo: AssemblyBindInfo; out pAssemblyId, pContext: Largeuint;
      out ppStmAssemblyImage, ppStmPDB: IStream): HRESULT;
    .....
    lpReferencedIdentity = 'xbrlexplorer, version=0.0.0.0, culture=neutral, publickeytoken=null'
    lpPostPolicyIdentity  = 'xbrlexplorer, version=0.0.0.0, culture=neutral, publickeytoken=null, processorarchitecture=x86'

    Why the version changed from Version=1.0.0.0 to version=0.0.0.0. and the Assembly.Load raise exception:
    System.IO.FileLoadException: 未能加载文件或程序集“xbrlexplorer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null”或它的某一个依赖项。找到的程序集清单定义与程序集引用不匹配。 (异常来自 HRESULT:0x80131040)

    Any help would be highly appreciated. Thank you.

    .NET 3.5 SP1 and also .NET 4.0 is also installed.


    graph xbrl
    Thursday, July 14, 2011 12:47 PM

Answers

  • public override PermissionSet ResolvePolicy(Evidence evidence) {
                WriteLine(" ResolvePolicy ");
                return new PermissionSet(PermissionState.Unrestricted);
            }

            private HostSecurityManagerOptions hostFlags = HostSecurityManagerOptions.HostDetermineApplicationTrust |
                                                       HostSecurityManagerOptions.HostAssemblyEvidence 
                                                       | HostSecurityManagerOptions.HostResolvePolicy;
            public override HostSecurityManagerOptions Flags {
                get {
                    return hostFlags;
                }
            }


    XBRL Expert
    Saturday, July 16, 2011 3:35 AM

All replies

  • http://blogs.msdn.com/b/junfeng/archive/2006/03/27/561775.aspx

    give some sugguest:

    2. Simply named assemblies

     

    Simply named assemblies are allowed in the host provided store. But CLR ignores the version number of simply named assemblies when doing ref-def matching. It is not expected that the host should implement the same logic. So we always pass version=0.0.0.0 for simply named assembly to the host.

     

    WARNING!!! In CLR binding model simply named assemblies must always be qualified with an application and you cannot load a simply named assembly outside of the application directory. But in the hosting model, there is no way to associate a simply named assembly with any particular application. For reason, you should not allow simply named assemblies in host assembly store.

     

    For example, if you have assembly Foo references a simply named assembly bar, when returning bar from the host assembly store, you have no idea whether the bar is the same one you referenced, or some random one other people have put into the store.

     

    The only safe simply named assemblies in the host store, are the ones that do not reference any other simply named assembly. (a.k.a, only references strongly named assemblies).

     

    Now get new error:
    “CoShare.Xbrl, Version=1.0.0.0, Culture=neutral, PublicKeyToken=8d44d12e12a6e1b0”或它的某一个依赖项。未能授予执行权限。 (异常来自 HRESULT:0x80131418)
    File name: 'CoShare.Xbrl, Version=1.0.0.0, Culture=neutral, PublicKeyToken=8d44d12e12a6e1b0' ---> System.Security.Policy.PolicyException: Execution permission cannot be acquired.
       at System.Security.SecurityManager.ResolvePolicy(Evidence evidence, PermissionSet reqdPset, PermissionSet optPset, PermissionSet denyPset, PermissionSet& denied, Boolean checkExecutionPermission)
       at System.Security.SecurityManager.ResolvePolicy(Evidence evidence, PermissionSet reqdPset, PermissionSet optPset, PermissionSet denyPset, PermissionSet& denied, Int32& securitySpecialFlags, Boolean checkExecutionPermission)
       at CoShare.XbrlExplorer.Forms.FormExplorer..ctor()
       at CoShare.XbrlExplorer.FormMain..ctor()
       at CoShare.XbrlExplorer.Program.HostEntry(String argument)


    graph xbrl
    Thursday, July 14, 2011 2:37 PM
  • FROM http://social.msdn.microsoft.com/Forums/en-US/clr/thread/b35fc119-0e86-4476-8f19-98c3bf6b8069

    Hi Hans, thanks for the tip.

    Indeed the immediate problem was fixed by overriding get HostSecurityManager and implementing HostSecurityManager::ResolvePolicy.  I did end up having to remove STARTUP_LOADER_OPTIMIZATION_MULTI_DOMAIN from the CorBindToRuntimeEx call in order to avoid COR_E_CANNOT_SET_POLICY, which is kind of annoying.

    I didn't find any answer to the problem of not being asked for the MSIL after refusing to provide the x86; I'm still explicitly asking for an MSIL assembly as a workaround.

    I've subsequently run into a larger problem which I'll start another thread for.

    Thanks,
    Kevin

     


    XBRL Expert
    Thursday, July 14, 2011 10:31 PM
  • public override PermissionSet ResolvePolicy(Evidence evidence) {
                WriteLine(" ResolvePolicy ");
                return new PermissionSet(PermissionState.Unrestricted);
            }

            private HostSecurityManagerOptions hostFlags = HostSecurityManagerOptions.HostDetermineApplicationTrust |
                                                       HostSecurityManagerOptions.HostAssemblyEvidence 
                                                       | HostSecurityManagerOptions.HostResolvePolicy;
            public override HostSecurityManagerOptions Flags {
                get {
                    return hostFlags;
                }
            }


    XBRL Expert
    Saturday, July 16, 2011 3:35 AM