注意:这个问题的主要目的是理解/解释 CLR的程序集绑定行为.一旦确定原因,解决方案应该是明显的.请知道我理解我的设置不是最佳的(nativedll没有签名和版本化等)但我再次想要调查CLR的绑定行为.
我试图在我的asp.net解决方案中使用本机(非COM,C++)DLL.我将避免命名dll,因为我认为它会将主题转向错误的方向.
本机dll来自博客站点,并没有太多信息.我没有关于本地dll的任何信息,比如它编译的架构,它是什么文化和版本等.使用提供的包装器,我可以在控制台应用程序中正确使用dll.它工作,即使我们必须使用部分程序集名称进行绑定.本机程序集的包装器具有DLL导入之类的[DllImport("nativedll.dll")]
public static extern void someMethod([Out] BE_VERSION pbeVersion);
我已阅读有关CLR程序集绑定的大量信息,包括:
根据我的理解,我们应该能够加载程序集,但没有.我得到程序集绑定错误.
SETUP
调用本机dll的我的帮助程序库(编译为MSIL(任何CPU))是强名称的并且在GAC中..我在IIS上的Win 7,x64位机器上运行我的asp.net应用程序,而不是Visual Studio开发服务器.nativedll没有签名而且没有GAC.
问题
总结是,当我将原生dll放在windows目录中时,(c:\ Windows)解决方案工作正常.在任何其他情况下,我得到程序集绑定错误.
问题
1.我想知道为什么程序集在Windows目录中被删除时会被绑定?2.错误是什么意思:错误:从文件中提取清单导入时出错(hr = 0x80131018)?(查看场景1,场景6)
3.为什么对Assembly.Load*()方法的调用失败?(情景3,4,5)
我的测试情景1的结果
:
**Setup**
Calling Assembly: GACed.
Native Assembly: Included in project; Build Action: None; Copy To Output Directory: Copy Always.
**Description:**
Logged into the site, home page open. Did not navigate to the page with native call.
**Result:**
Binding Error
*** Assembly Binder …Run Code Online (Sandbox Code Playgroud) 我的asp.net WebApi项目包含多个服务,核心和数据访问程序集.为了在项目中使用Ninject作为我的DI容器,我从NuGet添加了Ninject.Web.Common包.然后,我实现了IDependencyResolver:
public class NinjectDependencyResolver : NinjectDependencyScope, IDependencyResolver
{
readonly IKernel kernel;
public NinjectDependencyResolver(IKernel kernel) : base(kernel)
{
this.kernel = kernel;
}
public IDependencyScope BeginScope()
{
return new NinjectDependencyScope(this.kernel.BeginBlock());
}
}
public class NinjectDependencyScope : IDependencyScope
{
IResolutionRoot resolver;
public NinjectDependencyScope(IResolutionRoot resolver)
{
this.resolver = resolver;
}
public object GetService(System.Type serviceType)
{
if (resolver == null)
throw new ObjectDisposedException("this", "This scope has been disposed");
var resolved = this.resolver.Get(serviceType);
return resolved;
}
public System.Collections.Generic.IEnumerable<object> GetServices(System.Type serviceType)
{
if (resolver == null) …Run Code Online (Sandbox Code Playgroud) 我的asp.net WebApi项目包含多个服务,核心和数据访问程序集.为了在项目中使用Ninject作为我的DI容器,我从NuGet添加了Ninject.Web.Common包.然后,我实现了IDependencyResolver:
public class NinjectDependencyResolver : NinjectDependencyScope, IDependencyResolver
{
readonly IKernel kernel;
public NinjectDependencyResolver(IKernel kernel) : base(kernel)
{
this.kernel = kernel;
}
public IDependencyScope BeginScope()
{
return new NinjectDependencyScope(this.kernel.BeginBlock());
}
}
public class NinjectDependencyScope : IDependencyScope
{
IResolutionRoot resolver;
public NinjectDependencyScope(IResolutionRoot resolver)
{
this.resolver = resolver;
}
public object GetService(System.Type serviceType)
{
if (resolver == null)
throw new ObjectDisposedException("this", "This scope has been disposed");
var resolved = this.resolver.Get(serviceType);
return resolved;
}
public System.Collections.Generic.IEnumerable<object> GetServices(System.Type serviceType)
{
if (resolver == null) …Run Code Online (Sandbox Code Playgroud) 作为参考,这是有问题的流程:
"获取客户输入"(Lex) - >"设置联系人属性" - >"播放提示"
在调用Lex之后,我使用"将文本另存为属性"选项设置了一个联系人属性:
DestinationKey Value ProductType $ .Lex.SessionAttributes.ProductType
然后,在"播放提示"中,我无法引用set属性.我使用"文本到语音(Ad hoc)"并尝试了以下语法:
有趣的是,如果我在"设置联系人属性"之后添加"检查联系人属性",则它与"用户定义"属性"ProductType"匹配.
我该如何引用该属性?
在开发数据访问解决方案时,该解决方案利用实体框架 4.2 上的通用存储库和工作单元模式。我看到一些异常行为。为了使我的存储库通用,我使用了 DbContext 的 Set 方法,例如:
public class MyGenericRepository<T>
{
protected readonly IDbContext context;
public virtual IEnumerable<T> FindBy(Func<T, bool> predicate)
{
return context.GetDbSet<T>().Where(predicate).First();
}
}
Run Code Online (Sandbox Code Playgroud)
其中 IDbContext 是这样的:
public interface IDbContext
{
void Commit();
void Attach<T>(T obj) where T : class;
void Add<T>(T obj) where T : class;
DbSet<T> GetDbSet<T>() where T : class;
bool Remove<T>(T item) where T : class;
}
Run Code Online (Sandbox Code Playgroud)
DbContext 类将 IDbContext 实现为:
public partial class MyEntities : IDbContext
{
public DbSet<T> GetDbSet<T>() where T : …Run Code Online (Sandbox Code Playgroud)