From 6ad71030b15677fcc629a79c717ddb6e43479a83 Mon Sep 17 00:00:00 2001 From: Scott Xu Date: Tue, 5 Aug 2014 19:58:51 +0800 Subject: [PATCH] should only add public interfaces If the interface is not public, the castle dynamic proxy will throw: Castle.DynamicProxy.Generators.GeneratorException : Type System.Data.Entity.Internal.Linq.IInternalQueryAdapter is not visible to DynamicProxy. Can not create proxy for types that are not accessible. Make the type public, or internal and mark your assembly with [assembly: InternalsVisibleTo(InternalsVisible.ToDynamicProxyGenAssembly2)] attribute. --- Source/Mock.Generic.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Source/Mock.Generic.cs b/Source/Mock.Generic.cs index d60cdc5d5..d54260799 100644 --- a/Source/Mock.Generic.cs +++ b/Source/Mock.Generic.cs @@ -40,6 +40,7 @@ using System; using System.Diagnostics.CodeAnalysis; +using System.Linq; using System.Linq.Expressions; using Moq.Language.Flow; using Moq.Proxy; @@ -111,7 +112,7 @@ public Mock(MockBehavior behavior, params object[] args) this.Behavior = behavior; this.Interceptor = new Interceptor(behavior, typeof(T), this); this.constructorArguments = args; - this.ImplementedInterfaces.AddRange(typeof(T).GetInterfaces()); + this.ImplementedInterfaces.AddRange(typeof(T).GetInterfaces().Where(i => i.IsPublic)); this.ImplementedInterfaces.Add(typeof(IMocked)); this.CheckParameters();