XNA Creators Club Online
Page 1 of 1 (5 items)
Sort Posts: Previous Next

WinForm + Content Pipeline issue

Last post 9/3/2009 2:30 AM by dsoltyka. 4 replies.
  • 9/2/2009 3:36 AM

    WinForm + Content Pipeline issue

    Hey everyone.  I've been working on a level editor for some time now, and I just recently hit a weird problem.

    A little explanation.  My level editor uses the content pipeline to load content.  This works perfectly fine now.  I have all of the content manager classes and other xna controls in an external library.  I have also written a very simple plugin architecture for my editor.  This also works fine.  Each plugin has the the option to use xna controls and the content pipeline as they reference the same common library.  This also works fine.

    The problem comes in when I actually try to load content using the content pipeline from a plugin.

    When loading a class that has been serialized using the intermediate serializer, I get a ContentLoadException with the following information (the entire exception is at the end of the post):

    Microsoft.Xna.Framework.Content.ContentLoadException was unhandled
      Message="Error loading \"ofdcpsbpil\". Cannot find type A_World_Apart_EnemyEditor.EnemyInfo, A_World_Apart_EnemyEditor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null."
      Source="Microsoft.Xna.Framework"

    Now, a quick rundown of what you see there.  ofdcpsbpil is a random file name.  If you look at the ContentLoad<T> method pasted below, you'll see it builds a xnb with a random file name.  This works fine.  The problem, as I see it, is that the Content Manager is (obviously) not finding my class type ( A_World_Apart_EnemyEditor.EnemyInfo).  This *is* the correct type as well, as if I change it to anything else the MSBuild fails and errors out, so I know the type is fine.  It just can't load the content, and I have no idea why.

    Origianally I thought that maybe it can't find the type because all my content management classes are in their own DLL, but this isn't the case.  Also the references being loaded are fine, and I am loading the appropriate DLL files as references into the content builder.  I just can't understand why it will not find the type.

    Any ideas?




    public T LoadContent<T>(string fileName, 
                string contentImporter, 
                string contentProcessor, 
                out string buildError) 
            { 
                buildError = null
                string contentName = Rand.RandomString(10, true); 
                object content = null
     
                // Unload any existing model. 
                // contentManager.Unload(); 
     
                // Tell the ContentBuilder what to build. 
                contentBuilder.Clear(); 
     
                contentBuilder.Add(fileName, contentName, contentImporter, contentProcessor); 
     
                // Build this new model data. 
                buildError = contentBuilder.Build(); 
     
                if (string.IsNullOrEmpty(buildError)) 
                { 
                    // If the build succeeded, use the ContentManager to 
                    // load the temporary .xnb file that we just created. 
                    content = contentManager.Load<T>(contentName); 
                } 
     
                return (T)content; 
            } 
















    Microsoft.Xna.Framework.Content.ContentLoadException was unhandled
      Message="Error loading \"ofdcpsbpil\". Cannot find type A_World_Apart_EnemyEditor.EnemyInfo, A_World_Apart_EnemyEditor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null."
      Source="Microsoft.Xna.Framework"
      StackTrace:
           at Microsoft.Xna.Framework.Content.ContentTypeReaderManager.InstantiateTypeReader(String readerTypeName, ContentReader contentReader, ContentTypeReader& reader)
           at Microsoft.Xna.Framework.Content.ContentTypeReaderManager.GetTypeReader(String readerTypeName, ContentReader contentReader, List`1& newTypeReaders)
           at Microsoft.Xna.Framework.Content.ContentTypeReaderManager.ReadTypeManifest(Int32 typeCount, ContentReader contentReader)
           at Microsoft.Xna.Framework.Content.ContentReader.ReadHeader()
           at Microsoft.Xna.Framework.Content.ContentReader.ReadAsset[T]()
           at Microsoft.Xna.Framework.Content.ContentManager.ReadAsset[T](String assetName, Action`1 recordDisposableObject)
           at Microsoft.Xna.Framework.Content.ContentManager.Load[T](String assetName)
           at ParadigmCommon.WinFormsContentManager.LoadContent[T](String fileName, String contentImporter, String contentProcessor, String& buildError) in C:\Users\Lestat\Desktop\XNA\Projects\Tile Engine\ParadigmCommon\XNA Content Manager\WinFormsContentManager.cs:line 54
           at A_World_Apart_EnemyEditor.EnemyEditorMainForm.LoadEnemy(String fileName)
           at A_World_Apart_EnemyEditor.EnemyEditorMainForm.loadToolStripMenuItem_Click(Object sender, EventArgs e)
           at System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)
           at System.Windows.Forms.ToolStripMenuItem.OnClick(EventArgs e)
           at System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)
           at System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)
           at System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met)
           at System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met)
           at System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)
           at System.Windows.Forms.ToolStripDropDown.OnMouseUp(MouseEventArgs mea)
           at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
           at System.Windows.Forms.Control.WndProc(Message& m)
           at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
           at System.Windows.Forms.ToolStrip.WndProc(Message& m)
           at System.Windows.Forms.ToolStripDropDown.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.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
           at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 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 WorldBuilder.Program.Main() in C:\Users\Lestat\Desktop\XNA\Projects\Tile Engine\LevelEditor\Program.cs:line 18
           at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
           at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
           at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
           at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
           at System.Threading.ThreadHelper.ThreadStart()
      InnerException:

  • 9/2/2009 4:27 AM In reply to

    Re: WinForm + Content Pipeline issue

    Even stranger, if I add the plugin DLL as a reference in my main application, I get a different exception.

    Microsoft.Xna.Framework.Content.ContentLoadException was unhandled
      Message="Error loading \"cbltlucyuy\". File contains A_World_Apart_EnemyEditor.EnemyInfo but trying to load as A_World_Apart_EnemyEditor.EnemyInfo."
      Source="Microsoft.Xna.Framework"

    This is a really weird exception, as both of those types are identical...

    I definitely do NOT want the plugin to a be a reference in the main app project as I want plugins to be launched dynamically using reflection.


    EDIT:  Nevermind.  This exception is due to the fact that if I load the plugin assemblies dynamically using reflection AND use it as a reference, then there are two instances of A_World_Apart_EnemyEditor.EnemyInfo.  So, forget this error.  Still stuck on the original problem thoughl.
  • 9/2/2009 5:09 PM In reply to

    Re: WinForm + Content Pipeline issue

    Answer
    Reply Quote
    If you want an assembly name (in this case "A_World_Apart_EnemyEditor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null") to resolve against an assembly that is not directly referenced, you need to make sure that assembly is somewhere that the CLR will be able to find it.

    I'm far from an expert on this stuff, but I believe putting it in the same directory as your main executable will accomplish this, as will adding it to the GAC. The Assembly and AppDomain types have a bunch of stuff for configuring search paths and implementing your own AssemblyResolve event handlers for more complex situations, but I don't know much about that stuff.

    XNA Framework Developer - blog - homepage
  • 9/2/2009 5:22 PM In reply to

    Re: WinForm + Content Pipeline issue

    Answer
    Reply Quote
    Assuming this is a Windows game, if the CLR can't resolve your assembly, you can try resolving it yourself.

    http://msdn.microsoft.com/en-us/library/system.appdomain.assemblyresolve.aspx

    Or, for this particular case, resolving the type yourself might be necessary.

    http://msdn.microsoft.com/en-us/library/system.appdomain.typeresolve.aspx

    You can also define additional probing paths in your game application's configuration file.

    http://msdn.microsoft.com/en-us/library/kza1yk3a.aspx

    Stephen Styrchak | XNA Game Studio Developer
  • 9/3/2009 2:30 AM In reply to

    Re: WinForm + Content Pipeline issue

    Stephen Styrchak:
    Assuming this is a Windows game, if the CLR can't resolve your assembly, you can try resolving it yourself.

    http://msdn.microsoft.com/en-us/library/system.appdomain.assemblyresolve.aspx

    Or, for this particular case, resolving the type yourself might be necessary.

    http://msdn.microsoft.com/en-us/library/system.appdomain.typeresolve.aspx

    You can also define additional probing paths in your game application's configuration file.

    http://msdn.microsoft.com/en-us/library/kza1yk3a.aspx



    Well, the plugin DLL is in a different directory then the main executable...soooo probing additional paths may be the answer.

    Thanks guys, I'll look into this now.


    EDIT:


    Sweet.  It worked.   Adding <probing privatePath="Plugins"/>  to my app.config solved the problem.

    Thanks a bunch, I had assumed I wouldn't be able to solve this since I was loading assemblies dynamically, so wrote methods to rewrite the exported XML....which was a less than graceful approach.  This works much better, thanks again.
Page 1 of 1 (5 items) Previous Next