質問

im workin on a C# WinForms application. I need to embed a .dll and i try to "export" this file from Resource to HDD.

Im using the default form Resource...

System.IO.Stream s = Assembly.GetExecutingAssembly().GetManifestResourceStream("FormNamespace.Form1.Newtonsoft_Json");

The Filename is Newtonsoft.Json.dll and i tried also:

System.IO.Stream s = Assembly.GetExecutingAssembly().GetManifestResourceStream("FormNamespace.Form1.Newtonsoft.Json.dll");

Both dosn't work. s is always null. I think im using the wrong way to access the resource but i dont know :(

Would be nice if someone could help me :)

役に立ちましたか?

解決

If you've set correctly the build action to "embedded resource", the problem is most likely the name of the resource.

It should be namespace + file name; have you tried FormNamespace.Newtonsoft_Json.dll?

Otherwise, you can try executing the GetManifestResourceNames method and see what it returns.

他のヒント

If you are using Assembly.GetExecutingAssembly() then you get a better path to your resource doing the following:

var assembly = Assembly.GetExecutingAssembly();
var s = assembly.GetManifestResourceStream($"{assembly.GetName().Name}.Json.dll");

You should provide all Path to the resource. Example [DLLNAME or NameSpace].[ResourceName] If resource located on Res folder then [DLLNAME or NameSpace].[Res.Resource.txt]

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top