I've tried it with 2010.
To run this code with clr 4.0 you need to add following to app.comfig
<configuration>
   <runtime>
      <NetFx40_LegacySecurityPolicy enabled="true"/>
   </runtime>
</configuration>

But with 4.0 it works.

Change target framework to 3.5 to reproduce the issue



On 12 окт, 17:30, Konstantin <[email protected]> wrote:
> Remove   tuneDynamicProxy() call and restrict creation of signed
> assemby in some other way. Issue can be repeoduced where DP creates
> only unsigned assembly.
> The check for whether to create unsigned assembly or not is based on
> SecurityPermissionFlag.UnmanagedCode check.
>
> On 12 окт, 16:55, Krzysztof Koźmic <[email protected]> wrote:
>
>
>
> >   I ran it on .NET 4 under vs2010 and the code does not work at all.
>
> > Interestingly - for completely different reasons:
>
> > Unhandled Exception: System.TypeInitializationException: The type
> > initializer for 'ConsoleApplication9.Program' threw an  exception. --->
> > System.TypeInitializationException: The type initializer for
> > 'Castle.DynamicProxy.Generators.Emitters.StrongNameUtil' threw an
> > exception. ---> System.NotSupportedException: The Deny stack modifier
> > has been obsoleted by the .NET Framework.  Please 
> > seehttp://go.microsoft.com/fwlink/?LinkId=155571formore information.
> >     at System.Security.CodeAccessSecurityEngine.Check(Object demand,
> > StackCrawlMark& stackMark, Boolean isPermSet)
> >     at
> > System.Security.CodeAccessSecurityEngine.Check(CodeAccessPermission cap,
> > StackCrawlMark& stackMark)
> >     at System.Security.CodeAccessPermission.Demand()
> >     at Castle.DynamicProxy.Generators.Emitters.StrongNameUtil..cctor()
> > in
> > c:\TeamCity\buildAgent\work\f0c43d96621436a8\src\Castle.Core\DynamicProxy\G 
> > enerators\Emitters\StrongNameUtil.cs:line
> > 40
> >     --- End of inner exception stack trace ---
> >     at
> > Castle.DynamicProxy.Generators.Emitters.StrongNameUtil.get_CanStrongNameAss 
> > embly()
> >     at ConsoleApplication9.Program.tuneDynamicProxy() in
> > c:\users\xtoff\documents\visual studio
> > 2010\Projects\ConsoleApplication9\ConsoleApplication9\Program.cs:line 58
> >     at ConsoleApplication9.Program..cctor() in
> > c:\users\xtoff\documents\visual studio
> > 2010\Projects\ConsoleApplication9\ConsoleApplication9\Program.cs:line 52
> >     --- End of inner exception stack trace ---
> >     at ConsoleApplication9.Program.Main(String[] args)
>
> > Notice it fails even before any attempt to generate the proxy.
> > Anyway - I remember there was some bug in VS2008 debugger, so you may
> > have hit just that.
>
> > Which version of DP are you running?
>
> > On 12/10/2010 10:33 PM, Konstantin wrote:
>
> > > Following code causes exception if executed under VS2008 debugger.
>
> > > Exception:
> > > System.TypeLoadException: GenericArguments[0], 'ST2', on
> > > 'Castle.Proxies.Invocations.IService_Method2[ST1]' violates the
> > > onstraint of type parameter 'ST1'.
> > >     at Castle.Proxies.IServiceProxy.Method2[ST2](ST2 t)
> > >     at DPGenericsUnderDebugIssueDemo.Program.Main(String[] args) in C:
> > > \WORK\TestsAndTries\DPGenericsUnderDebugIssueDemo
> > > \DPGenericsUnderDebugIssueDemo\Program.cs: line 61
>
> > > This:
> > > "GenericArguments[0], 'ST2', on
> > > 'Castle.Proxies.Invocations.IService_Method2[ST1]'"
> > > looks very strange....
>
> > > If executed without debugger it work ok.
>
> > >      public class C : ICloneable
> > >      {
> > >          public object Clone()
> > >          {
> > >              throw new NotImplementedException();
> > >          }
> > >      }
>
> > >      public interface IService
> > >      {
> > >          void Method1<ST1>(ST1 t) where ST1 : class, new();
> > >          void Method2<ST2>(ST2 t) where ST2 : ICloneable;
> > >      }
>
> > >      public class Component : IService
> > >      {
> > >          public void Method1<CT1>(CT1 t) where CT1 : class, new()
> > >          {
> > >              Console.WriteLine(string.Format("Method1 CT1:{0}", typeof
> > > (CT1)));
> > >          }
>
> > >          public void Method2<CT2>(CT2 t) where CT2 : ICloneable
> > >          {
> > >              Console.WriteLine(string.Format("Method2 CT2:{0}", typeof
> > > (CT2)));
> > >          }
> > >      }
>
> > >      internal class Program
> > >      {
> > >          [SecurityPermission(SecurityAction.Deny, Unrestricted = true,
> > > Flags = SecurityPermissionFlag.UnmanagedCode)]
> > >          private static void tuneDynamicProxy()
> > >          {
> > >              Console.WriteLine(StrongNameUtil.CanStrongNameAssembly);
> > >          }
>
> > >          static Program()
> > >          {
> > >              //Restrict signed assembly generation
> > >              tuneDynamicProxy();
> > >          }
>
> > >          private static void Main(string[] args)
> > >          {
> > >              ProxyGenerator g = new ProxyGenerator();
> > >              var proxy = g.CreateInterfaceProxyWithTarget<IService>(new
> > > Component(), new IInterceptor[0]);
>
> > >              try
> > >              {
> > >                  proxy.Method1(new C());
> > >                  proxy.Method2(new C());
> > >              }
> > >              catch (Exception e)
> > >              {
> > >                  Console.WriteLine(e);
> > >              }
> > >              finally
> > >              {
> > >                  Console.ReadLine();
> > >              }
> > >          }
> > >      }

-- 
You received this message because you are subscribed to the Google Groups 
"Castle Project Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/castle-project-users?hl=en.

Reply via email to