开发者

Assembly.GetExecutingAssembly() not looking in the correct path

I'm reading an embedded xml file using

C#:

var AssemblyRef = Assembly.GetExecutingAssembly();
TextReader reader = new StreamReader(AssemblyRef.GetManifestResourceStream("Text.xml"));

It has been working for some time, but starting throwing errors. I traced the path that it is looking for and it i开发者_JS百科s looking for the dll in the root of the bin folder and not in the Debug or release folder.

Once it is published this is fine, but for local development I cannot get my one feature to work.

I have it set to Debug when compiling. Any help would be great.


You have:

  • Changed Assembly Name OR
  • Changed namespace OR
  • Moved the resource to a folder in the project


I changed the call to this and everything is fine.

TextReader reader = new StreamReader(Assembly.GetExecutingAssembly().AssemblyRef.GetManifestResourceStream("Text.xml"));

Making the call one statement made it work. I'm not sure why.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜