Skip to content

Commit

Permalink
should only add public interfaces
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
scott-xu committed Aug 5, 2014
1 parent f9f8a3c commit 6ad7103
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Source/Mock.Generic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@

using System;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Linq.Expressions;
using Moq.Language.Flow;
using Moq.Proxy;
Expand Down Expand Up @@ -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<T>));

this.CheckParameters();
Expand Down

0 comments on commit 6ad7103

Please sign in to comment.