I need the C#
code to add the assemblies to the GAC
. Does anybody know how to add DLLs to GAC
using C#
?
EDIT: I am trying to load a dll using bytes in a window application. As some of the dll file loads properly in my application but when I am trying to load the assembly (Microsoft_DirectX_AudioVideoPlayback.dll) it is giving me error of badImage exception. Basically I just need to load the assembly from bytes array using the following method.
byte[] ByteArray = Resource1.Microsoft_DirectX_AudioVideoPlayback;
Assembly.Load(ByteArray );
where BytesArray is the assembly bytes array.
I am getting following lines as an error.
An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)
System.badImageformat exception :{"An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)"}
Publish publish = new Publish();
publish.GacInstall(System.IO.Path.GetFullPath("MyAssembly.dll"));
Namespace: System.EnterpriseServices.Internal
Assembly: System.EnterpriseServices (in System.EnterpriseServices.dll)
No; you don't need to add anything to the GAC.
You can simply call Assembly.Load()
to load the assemblies directly from the byte arrays embedded in your file.
Note that you will need to do that before the JITer encounters any types from those assemblies.
When you include your video file you have to include it as a "Embedded Resource". If you do not know how to do it here are the steps.
Then use below class to retrieve the video as a byte array. I am sure you can take care of the rest.
using System.IO;
using System.Reflection;
namespace MyProject.Video
{
class MyVideoClass
{
private const string videoExtract = "MyProject.Video.MyVideo.dat";
public byte[] GetStream()
{
try
{
var memoryStream = new MemoryStream();
Stream sourceStream = null;
sourceStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(videoExtract);
if (sourceStream != null) sourceStream.CopyTo(memoryStream);
return memoryStream.ToArray();
}
catch
{
return null;
}
}
}
}
User contributions licensed under CC BY-SA 3.0