prayank.gahlot
Member
- Joined
- Apr 28, 2016
- Messages
- 5
- Programming Experience
- 1-3
I am running the below code to copy embedded resource to disk at run time in the vb.net application which works fine (the embedded resource file is added in the project resources folders and set as embedded resource in the properties):
But when I try the same logic in the codedom to achieve exactly same thing (copy embedded resource to disk when running the generated executable) it fails with an error : Object reference not set to an instance of an object
This is the way I am trying to do it:
and in the actual code which gets compiled at run time:
Please help!! :blue:
VB.NET:
Public Function CopyResourceToDisk(ByVal ResourceName As String, ByVal FileToCopyTo As String) As Boolean
Dim str As System.IO.Stream = System.Reflection.Assembly.GetExecutingAssembly.GetManifestResourceStream(ResourceName)
Dim RF As New System.IO.FileStream(FileToCopyTo, IO.FileMode.Create)
Dim byt(str.Length) As Byte
str.Read(byt, 0, str.Length)
RF.Write(byt, 0, byt.Length - 1)
RF.Flush()
RF.Close()
RF = Nothing
End Function
VB.NET:
Dim Appdatapath As String = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
VB.NET:
CopyResourceToDisk("Myapplicationrootnamespace.resourcefile.xml", Appdatapath & "\Myapp\resourcefile.xml")
But when I try the same logic in the codedom to achieve exactly same thing (copy embedded resource to disk when running the generated executable) it fails with an error : Object reference not set to an instance of an object
This is the way I am trying to do it:
VB.NET:
Dim filebyte As Byte() = IO.File.ReadAllBytes("full path of resourcefile.xml")
Dim writer As New System.Resources.ResourceWriter("tmp.resources")
writer.AddResource("resourcefile.xml", filebyte)
writer.Generate()
writer.Close()
VB.NET:
complierparams.EmbeddedResources.Add(System.Windows.Forms.Application.StartupPath & "\tmp.resources")
and in the actual code which gets compiled at run time:
VB.NET:
Public Function CopyResourceToDisk(ByVal ResourceName As String, ByVal FileToCopyTo As String) As Boolean
Dim str As System.IO.Stream = System.Reflection.Assembly.GetExecutingAssembly.GetManifestResourceStream(ResourceName)
Dim RF As New System.IO.FileStream(FileToCopyTo, IO.FileMode.Create)
Dim byt(str.Length) As Byte
str.Read(byt, 0, str.Length)
RF.Write(byt, 0, byt.Length - 1)
RF.Flush()
RF.Close()
RF = Nothing
End Function
VB.NET:
CopyResourceToDisk("resourcefile.xml", Appdatapath & "\resourcefile.xml")
Please help!! :blue:
Last edited: