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: