Home Dashboard Directory Help
Search

Can't use AppDomains inside WCF called methods by Steve Hansen [2sky]


Status: 

Closed
 as By Design Help for as By Design


3
0
Sign in
to vote
Type: Bug
ID: 712500
Opened: 12/8/2011 7:21:04 AM
Access Restriction: Public
Moderator Decision: Sent to Engineering Team for consideration
0
Workaround(s)
view
1
User(s) can reproduce this bug

Description

Using a new AppDomain inside a method that is called as a WCF service gives the following exception:

"Type 'System.Reflection.Emit.AssemblyBuilder' in assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' is not marked as serializable."

Which is triggered by the following code:
        public void DoWork()
        {
            var appDomain = AppDomain.CreateDomain("Test");
            var asmBuilder = appDomain.DefineDynamicAssembly(new AssemblyName("Test"), AssemblyBuilderAccess.Run);
        }

I tried on the following environments:
- .NET 4.0: Client/Full
- .NET 4.5: Client/Full
- x86/x64
- Hosted on ServiceHost, IIS or Azure

All give the exact same exception.
Details
Sign in to post a comment.
Posted by Microsoft on 12/19/2011 at 2:08 PM
Thanks Steve,
I took a look at the repro and the documentation for the overload method for DefineDynamicAssembly (http://msdn.microsoft.com/en-us/library/bs22fky4.aspx) says that this overload should only be called from the current app domain. Once I did that, there was no exception.
This page also notes the recommended way if you are creating your own app domain -
"During the development of code that emits dynamic assemblies, it is recommended that you use an overload of the DefineDynamicAssembly method that specifies evidence and permissions, supply the evidence you want the dynamic assembly to have, and include SecurityPermissionFlag.SkipVerification in refusedPermissions. Including SkipVerification in the refusedPermissions parameter ensures that the MSIL is verified. A limitation of this technique is that it also causes SecurityException to be thrown when used with code that demands full trust."
I am resolving this as By Design. Please reactivate/ create a new bug if you are still having any issues.
Thanks.
Posted by MS-Moderator08 [Feedback Moderator] on 12/8/2011 at 8:47 PM
Thank you for submitting feedback on Visual Studio 2010 and .NET Framework. Your issue has been routed to the appropriate VS development team for investigation. We will contact you if we require any additional information.
Posted by MS-Moderator01 on 12/8/2011 at 8:44 AM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Sign in to post a workaround.
File Name Submitted By Submitted On File Size  
WcfTest.zip 12/8/2011 10 KB