亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

這個是為什么?我就是無法生成那個流?該怎么改?

這個是為什么?我就是無法生成那個流?該怎么改?

C#
慕哥6287543 2023-04-08 13:09:14
有一個a.dll,它其中有一個b.xml是嵌入的資源?,F在我希望通過反射在我自己的程序中把這個a.dll中的b.xml的內容給讀出來,請詳細寫清楚方法。多謝了我換成LoadFile的時候,它也是報“未能找到任何適合于指定的區域性或非特定區域性的資源。請確保在編譯時已將“Biz.Client.SM.CreateAccount.Version.xml.resources”正確嵌入或鏈接到程序集“Biz.Client.SM.CreateAccount”,或者確保所有需要的附屬程序集都可加載并已進行了完全簽名?!?
查看完整描述

3 回答

?
www說

TA貢獻1775條經驗 獲得超8個贊

System.Reflection.Assembly dll = System.Reflection.Assembly.LoadFile("文件路徑");
Stream xmls = dll.GetManifestResourceStream("a.dll的命名空間.項目中的文件路徑.文件名");

后面就可以把這個xml作為正常的xml文件的流來使用了。

不好意思,只是按照自己的想法寫的。沒有去實踐。
這個問題是我寫錯函數了。用load函數的話。參數是dll的命名空間。我已經改了上面的source。
你試一下。

試了一下,這樣就好用了。

LoadFile,中的參數是你的dll的路徑。不是xml的路徑。

查看完整回答
反對 回復 2023-04-11
?
寶慕林4294392

TA貢獻2021條經驗 獲得超8個贊

System.Reflection.Assembly dll = System.Reflection.Assembly.LoadFile("文件路徑"); 
Stream xmls = dll.GetManifestResourceStream("a.dll的命名空間.項目中的文件路徑.文件名");

查看完整回答
反對 回復 2023-04-11
?
楊魅力

TA貢獻1811條經驗 獲得超6個贊

以下是我的代碼
將我的自定義類的內容去掉以后就是獲取DLL的嵌入資源的代碼了
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace Madison.Server.MethodFactory
{
public class MethodFactory
{
private static Assembly dllAssembly = null;
private MethodFactory() { }
private static List<MadisonMethodInfo> allMethodInfo = new List<MadisonMethodInfo>();

public static MethodFactory LoadDll(string dllFilePath)
{
dllAssembly = Assembly.LoadFile(dllFilePath);
var allTypes = dllAssembly.GetTypes();
LoadAllMethod(allTypes.ToList());
return new MethodFactory();
}

private static void LoadAllMethod(List<Type> allTypes)
{
if (allTypes.Count > 1)
{
var typeMethods = allTypes[0].GetMethods();
for (int i = 0; i < typeMethods.Count(); i++)
{
if (
typeMethods[i].GetCustomAttribute(typeof(MadisonMethodAttribute)) != null
&&
(typeMethods[i].GetCustomAttribute(typeof(MadisonMethodAttribute)) as MadisonMethodAttribute).UsingMethod
)
{
allMethodInfo.Add(MadisonMethodInfo.Create(typeMethods[i]));
}
}

}
}
}


查看完整回答
反對 回復 2023-04-11
  • 3 回答
  • 0 關注
  • 161 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號