StrataFrame Forum

Invoked member is not supported in a dynamic assembly

http://forum.strataframe.net/Topic32103.aspx

By Chris Diesel - 6/10/2013

Trying to move from .Net 3.5 to 4.0 and I'm getting "The invoked member is not supported in a dynamic assembly." on this line:

StrataFrameApplication.RunApplication();

Any ideas???
By StrataFrame Team - 6/11/2013

Have you recompiled the SF source code in 4.0?
By Chris Diesel - 6/11/2013

Yes.
By StrataFrame Team - 6/11/2013

What is the call stack of the exception that is thrown?  Does it contain Assembly.GetTypes() or AssemblyBuilder.GetTypes()?  Googling the error it seems as though the  .NET 4.0 runtime has tightened down the ability to use Assembly.Load dynamically to load assemblies that are not explicitly referenced, for instance, plug-ins.  There is an app.config setting that can allow them to run, though:

By Chris Diesel - 6/11/2013

Saw that ealier and tried it again but doesn't help.

loadFromRemoteSources enabled="true"

Stack Trace:

   at System.Reflection.Emit.InternalAssemblyBuilder.GetManifestResourceNames()
   at MicroFour.StrataFrame.Application.StrataFrameApplication.LoadLocalizationFromAssembly(Assembly LoadedAssembly)
   at MicroFour.StrataFrame.Application.StrataFrameApplication.RunApplication()
   at IwSystemsCore.clsIwSystemsCore.Main(clsProcessing oStartProc, String fullAssemblyName) in c:\VssProjs\IwSystems\Development\IwApplications\IwSystemsMain\IwSystemsCore\SharedCore\IwSystemsCore.cs:line 188
   at IwSystemsStartup.IwSystemsStartupMain.Main() in c:\VssProjs\IwSystems\Development\IwApplications\IwSystemsMain\IwSystemsStartup\SharedStartup\IwSystemsStartupMain.cs:line 27
   at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
   at System.AppDomain.nExecuteAssembly(RuntimeAssembly 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 System.Activator.CreateInstance(ActivationContext activationContext)
   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone()
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()
By StrataFrame Team - 6/11/2013

Can you build SF in debug mode and break in the StrataFrameApplication.LoadLocalizationFromAssembly() method?  It would help to know what assembly is causing the error.
By Chris Diesel - 6/11/2013

In strataframeapplication.vb

erroring on this line...'-- Check the manifests for the xml files and register them if possible

For Each lcFile As String In LoadedAssembly.GetManifestResourceNames()

 

By StrataFrame Team - 6/11/2013

Yeah, sorry, it's looping through the assemblies, right?  What assembly is it trying to call GetManifestResourceNames on?
By Chris Diesel - 6/11/2013

Not sure if this is right...

LoadedAssembly is showing: {Microsoft.GeneratedCode, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null}
By StrataFrame Team - 6/11/2013

That actually makes sense that "GeneratedCode" would be a dynamic assembly.  Looks like there are 2 ways to fix this:

1) If you're not using localization, set StrataFrameApplication.IgnoreLoadLocalization = true; before you call StrataFrameApplication.Run() and the whole process will be skipped.

2) If you need localization, you'll need to change the second If test in the StrataFrameApplication.LoadLocalizationFromAssembly() method to have a second OrElse like this:

If TypeOf LoadedAssembly Is System.Reflection.Emit.AssemblyBuilder OrElse LoadedAssembly.IsDynamic Then

This can only be done if you're building in 4.0 because the Assembly.IsDynamic properti does not exist in 2.0.

One of those should get you fixed.
By Chris Diesel - 6/11/2013

I'll go with option 1 for now.

Thanks! 
By Chris Diesel - 6/28/2013

I now get the below message going into the SecurityDialog.  Is this releated to setting:
    StrataFrameAppLication.IgnoreLoadLocalization = true;



LocalizationKeyNotFoundException
  The specified key [SFSTText - None] was not found within the localization database.
KeyNotFoundException
  The message key [SFSTText - None] could not be found in the localization data.

Source     : MicroFour StrataFrame Base

Stack Trace: 

   at MicroFour.StrataFrame.UI.Localization.ThrowKeyNotFoundException(String Key)
   at MicroFour.StrataFrame.UI.Localization.GetKeyRowFromXml(String Key)
   at MicroFour.StrataFrame.UI.Localization.RetrieveTextValue(String TextValueKey)

   at MicroFour.StrataFrame.Security.SecurityDialog..ctor(Int32 ProjectPK, ShowProjectPropertiesDeleg ShowProjectProperties, CreatePermissionEditor CreatePermEditor, Boolean ShowPermissions, Boolean ShowRestrictionSets)
   at MicroFour.StrataFrame.Security.SecurityDialog..ctor()
   at IwSystemsCore.frmIwSystemsMain.action_UserSetup() in c:\VssProjs\IwSystems\Development\IwApplications\IwSystemsMain\IwSystemsCore\SharedCore\frmIwSystemsMain.cs:line 361
   at IwSystemsCore.frmIwSystemsMain.dxBarMgr_ItemClick(Object sender, ItemClickEventArgs e) in c:\VssProjs\IwSystems\Development\IwApplications\IwSystemsMain\IwSystemsCore\SharedCore\frmIwSystemsMain.cs:line 831
   at DevExpress.XtraBars.BarManager.RaiseItemClick(ItemClickEventArgs e)
   at DevExpress.XtraBars.BarItem.OnClick(BarItemLink link)
   at DevExpress.XtraBars.BarBaseButtonItem.OnClick(BarItemLink link)
   at DevExpress.XtraBars.BarButtonItem.OnClick(BarItemLink link)
   at DevExpress.XtraBars.BarItemLink.OnLinkClick()
   at DevExpress.XtraBars.BarButtonItemLink.OnLinkClick()
   at DevExpress.XtraBars.BarItemLink.OnLinkAction(BarLinkAction action, Object actionArgs)
   at DevExpress.XtraBars.BarButtonItemLink.OnLinkAction(BarLinkAction action, Object actionArgs)
   at DevExpress.XtraBars.BarItemLink.OnLinkActionCore(BarLinkAction action, Object actionArgs)
   at DevExpress.XtraBars.ViewInfo.BarSelectionInfo.ClickLink(BarItemLink link)
   at DevExpress.XtraBars.ViewInfo.BarSelectionInfo.UnPressLink(BarItemLink link)
   at DevExpress.XtraBars.Controls.CustomLinksControl.OnMouseUp(MouseEventArgs e)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at DevExpress.XtraBars.Controls.CustomControl.WndProc(Message& msg)
   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.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
   at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
   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 MicroFour.StrataFrame.Application.StrataFrameApplication.RunApplication()
By StrataFrame Team - 6/28/2013

Yes, that's because none of the localization files have been loaded.  You can manually load the files for the MicroFour StrataFrame Security assembly like this:

MicroFour.StrataFrame.Messaging.Localization.RegisterEmbeddedXmlFile(typeof(MicroFour.StrataFrame.Security.SessionLock).Assembly, "MicroFour.StrataFrame.Security.Messages_1033.XML");
By Chris Diesel - 6/28/2013

Great!  I'm almost there, but I'm getting the below message when I put that line in:
    'Localization' does not exist in the namespace 'MicroFour.StataFrame.Messaging'

Do I need to reference another assembly?
By StrataFrame Team - 6/28/2013

Nope, sorry, Localization is in the UI namespace:

MicroFour.StrataFrame.UI.Localization.RegisterEmbeddedXmlFile(typeof(MicroFour.StrataFrame.Security.SessionLock).Assembly, "MicroFour.StrataFrame.Security.Messages_1033.XML");
By Chris Diesel - 6/28/2013

Great, that did it!  Thanks for the help! Smile