Auto Dependency Injection Discovery and Click-Once Deployment

Posts   
 
    
Posts: 93
Joined: 13-Feb-2008
# Posted on: 19-May-2008 15:57:43   

We are getting code access security exceptions when deploying a click-once application with auto dependency injection discovery turned on. When we turn it off the application deploys and executes as expected. Any ideas?


at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandle& ctor, Boolean& bNeedSecurityCheck)

   at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean fillCache)

   at System.RuntimeType.CreateInstanceImpl(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean fillCache)

   at System.Activator.CreateInstance(Type type, Boolean nonPublic)

   at System.Activator.CreateInstance(Type type)

   at SD.LLBLGen.Pro.ORMSupportClasses.EntityCollectionBase2`1.DetermineEntityFactory()

   at SD.LLBLGen.Pro.ORMSupportClasses.EntityCollectionBase2`1..ctor(IEntityFactory2 entityFactoryToUse)

   at TestDeploy.HelperClasses.EntityCollection`1..ctor() in C:\Projects\TestDeploy.Objects\DatabaseGeneric\HelperClasses\EntityCollection.cs:line 82

   at TestDeploy.ManagerClasses.MyTable.GetAll() in C:\Projects\TestDeploy.Objects\DatabaseGeneric\ManagerClasses\MyTable.cs:line 24

   at TDApplication.Form1.Form1_Load(Object sender, EventArgs e) in C:\Projects\TestDeploy\TDApplication\Form1.cs:line 27

   at System.Windows.Forms.Form.OnLoad(EventArgs e)

   at System.Windows.Forms.Form.OnCreateControl()

   at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)

   at System.Windows.Forms.Control.CreateControl()

   at System.Windows.Forms.Control.WmShowWindow(Message& m)

   at System.Windows.Forms.Control.WndProc(Message& m)

   at System.Windows.Forms.ScrollableControl.WndProc(Message& m)

   at System.Windows.Forms.ContainerControl.WndProc(Message& m)

   at System.Windows.Forms.Form.WmShowWindow(Message& m)

   at System.Windows.Forms.Form.WndProc(Message& m)

   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)

   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)

   at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

   at System.Windows.Forms.SafeNativeMethods.ShowWindow(HandleRef hWnd, Int32 nCmdShow)

   at System.Windows.Forms.Control.SetVisibleCore(Boolean value)

   at System.Windows.Forms.Form.SetVisibleCore(Boolean value)

   at System.Windows.Forms.Control.set_Visible(Boolean value)

   at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)

   at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)

   at System.Windows.Forms.Application.Run(Form mainForm)

   at TDApplication.Program.Main() in C:\Projects\TestDeploy\TDApplication\Program.cs:line 18

   at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)

   at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)

   at System.Runtime.Hosting.ManifestRunner.Run(Boolean checkAptModel)

   at System.Runtime.Hosting.ManifestRunner.ExecuteAsAssembly()

   at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext, String[] activationCustomData)

   at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext)

   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone()

   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)

   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)

   at System.Threading.ThreadHelper.ThreadStart()



Inner Exception


 at System.Security.CodeAccessSecurityEngine.ThrowSecurityException(Assembly asm, PermissionSet granted, PermissionSet refused, RuntimeMethodHandle rmh, SecurityAction action, Object demand, IPermission permThatFailed)

   at System.Security.CodeAccessSecurityEngine.ThrowSecurityException(Object assemblyOrString, PermissionSet granted, PermissionSet refused, RuntimeMethodHandle rmh, SecurityAction action, Object demand, IPermission permThatFailed)

   at System.Security.CodeAccessSecurityEngine.CheckSetHelper(PermissionSet grants, PermissionSet refused, PermissionSet demands, RuntimeMethodHandle rmh, Object assemblyOrString, SecurityAction action, Boolean throwException)

   at System.Security.PermissionSetTriple.CheckSetDemand(PermissionSet demandSet, PermissionSet& alteredDemandset, RuntimeMethodHandle rmh)

   at System.Security.PermissionListSet.CheckSetDemand(PermissionSet pset, RuntimeMethodHandle rmh)

   at System.Security.PermissionListSet.DemandFlagsOrGrantSet(Int32 flags, PermissionSet grantSet)

   at System.Threading.CompressedStack.DemandFlagsOrGrantSet(Int32 flags, PermissionSet grantSet)

   at System.Security.CodeAccessSecurityEngine.ReflectionTargetDemandHelper(Int32 permission, PermissionSet targetGrant, CompressedStack securityContext)

   at System.Security.CodeAccessSecurityEngine.ReflectionTargetDemandHelper(Int32 permission, PermissionSet targetGrant)



goose avatar
goose
User
Posts: 392
Joined: 06-Aug-2007
# Posted on: 19-May-2008 18:56:09   

Check the following:

1- Make sure that your are deploying a release version of your application, not a debug version. 2- If you are using LLBL's debugging features, make sure to turn it off (<add name="SqlServerDQE" value="0"/>) in the .config of your application.

Posts: 93
Joined: 13-Feb-2008
# Posted on: 20-May-2008 15:15:37   

Both release and debug mode produce the same error and we are not using LLBLGen's debugging features. Any other ideas?

goose avatar
goose
User
Posts: 392
Joined: 06-Aug-2007
# Posted on: 20-May-2008 19:17:04   

sounds like a reflection problem, your application has to be able to read the assemblies and reflect over them.

Posts: 93
Joined: 13-Feb-2008
# Posted on: 05-Jun-2008 15:31:19   

We never figured out what the issue was with our deployment, we simply turned auto discovery off and explicitly identified the assemblies that participate in dependency injection.