SharpDX:未找到内容资产

时间:2014-02-25 09:24:21

标签: c# directx sharpdx

如果在使用sharpdx toolkit contentpipeline时找不到我的资产,可能会出现什么问题。

sf = Content.Load<SpriteFont>("Arial16ClearType");

它们位于名为“Content”的子目录中,并在应用程序中设置:

Content.RootDirectory = "Content";

将buildaction正确设置为Toolkitfont。 “复制到输出目录”是“不要复制”。

我通过将此添加到我的csproj

来导入buildactions
<Import Project="f:\work\github\SharpDX\SharpDX.targets" />

并且总是抛出此异常

SharpDX.Toolkit.Content.AssetNotFoundException was unhandled
  HResult=-2146233088
  Message=Content\Arial16ClearType
  Source=SharpDX.Toolkit
  StackTrace:
       at SharpDX.Toolkit.Content.ContentManager.FindStream(String assetName) in ..\..\Source\Toolkit\SharpDX.Toolkit\Content\ContentManager.cs:line 330
       at SharpDX.Toolkit.Content.ContentManager.Load(Type assetType, String assetName, Object options) in ..\..\Source\Toolkit\SharpDX.Toolkit\Content\ContentManager.cs:line 201
       at SharpDX.Toolkit.Content.ContentManager.Load[T](String assetName, Object options) in ..\..\Source\Toolkit\SharpDX.Toolkit\Content\ContentManager.cs:line 163
       at glyphrenderer.GlyphGame.LoadContent() in GlyphGame.cs:line 78
       at SharpDX.Toolkit.Game.InitializeBeforeRun() in ..\..\Source\Toolkit\SharpDX.Toolkit.Game\Game.cs:line 326
       at SharpDX.Toolkit.GameWindowDesktop.RunRenderLoop() in ..\..\Source\Toolkit\SharpDX.Toolkit.Game\Desktop\GameWindowDesktop.cs:line 340
       at SharpDX.Toolkit.GameWindowDesktop.Run() in ..\..\Source\Toolkit\SharpDX.Toolkit.Game\Desktop\GameWindowDesktop.cs:line 302
       at SharpDX.Toolkit.GamePlatform.Run(GameContext gameContext) in ..\..\Source\Toolkit\SharpDX.Toolkit.Game\GamePlatform.cs:line 133
       at SharpDX.Toolkit.Game.Run(GameContext gameContext) in ..\..\Source\Toolkit\SharpDX.Toolkit.Game\Game.cs:line 378
       at glyphrenderer.Program.Main(String[] args) in Program.cs:line 18
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       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()
  InnerException: 

1 个答案:

答案 0 :(得分:1)

不确定“buildaction是否设置正确”是什么意思,但你必须使用构建操作ToolkitFont而不是Content而不指定“复制到输出目录”,因为它已完成通过ToolkitFont任务。检查以这种方式配置的Toolkit示例中的项目。 Toolkit任务负责将xml /源文件编译为将在运行时加载的二进制形式。