I'm trying to write an Outlook add-in in Visual Basic (in Visual Studio 2012 Professional on Windows 7) that will interface with a web service we use at work. Unfortunately this particular web service doesn't really stay with the times and as such, requires the Web Reference to implement Microsoft.Web.Services2.WebServicesClientProtocol to do certain things. When I change the generated Reference.vb to inherit this class instead of the default and Rebuild All, the build fails with the message:
------ Rebuild All started: Project: OutlookAddIn1, Configuration: Debug Any CPU ------
OutlookAddIn1 -> \\nas01\my-home$\chq-andrewt\Visual Studio 2012\Projects\OutlookAddIn1\OutlookAddIn1\bin\Debug\OutlookAddIn1.dll
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\OfficeTools\Microsoft.VisualStudio.Tools.Office.targets(176,9): error MSB4018: The "FindRibbons" task failed unexpectedly.
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\OfficeTools\Microsoft.VisualStudio.Tools.Office.targets(176,9): error MSB4018: System.IO.FileNotFoundException: Could not load file or assembly 'OutlookAddIn1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\OfficeTools\Microsoft.VisualStudio.Tools.Office.targets(176,9): error MSB4018: File name: 'OutlookAddIn1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\OfficeTools\Microsoft.VisualStudio.Tools.Office.targets(176,9): error MSB4018: at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\OfficeTools\Microsoft.VisualStudio.Tools.Office.targets(176,9): error MSB4018: at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\OfficeTools\Microsoft.VisualStudio.Tools.Office.targets(176,9): error MSB4018: at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\OfficeTools\Microsoft.VisualStudio.Tools.Office.targets(176,9): error MSB4018: at System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection)
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\OfficeTools\Microsoft.VisualStudio.Tools.Office.targets(176,9): error MSB4018: at System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\OfficeTools\Microsoft.VisualStudio.Tools.Office.targets(176,9): error MSB4018: at System.Reflection.Assembly.Load(String assemblyString)
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\OfficeTools\Microsoft.VisualStudio.Tools.Office.targets(176,9): error MSB4018: at System.UnitySerializationHolder.GetRealObject(StreamingContext context)
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\OfficeTools\Microsoft.VisualStudio.Tools.Office.targets(176,9): error MSB4018:
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\OfficeTools\Microsoft.VisualStudio.Tools.Office.targets(176,9): error MSB4018: at Microsoft.Build.Framework.ITask.Execute()
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\OfficeTools\Microsoft.VisualStudio.Tools.Office.targets(176,9): error MSB4018: at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\OfficeTools\Microsoft.VisualStudio.Tools.Office.targets(176,9): error MSB4018: at Microsoft.Build.BackEnd.TaskBuilder.d__20.MoveNext()
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\OfficeTools\Microsoft.VisualStudio.Tools.Office.targets(176,9): error MSB4018:
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\OfficeTools\Microsoft.VisualStudio.Tools.Office.targets(176,9): error MSB4018: === Pre-bind state information ===
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\OfficeTools\Microsoft.VisualStudio.Tools.Office.targets(176,9): error MSB4018: LOG: DisplayName = OutlookAddIn1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\OfficeTools\Microsoft.VisualStudio.Tools.Office.targets(176,9): error MSB4018: (Fully-specified)
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\OfficeTools\Microsoft.VisualStudio.Tools.Office.targets(176,9): error MSB4018: LOG: Appbase = file:///C:/Program Files (x86)/Microsoft Visual Studio 11.0/Common7/IDE/
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\OfficeTools\Microsoft.VisualStudio.Tools.Office.targets(176,9): error MSB4018: LOG: Initial PrivatePath = NULL
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\OfficeTools\Microsoft.VisualStudio.Tools.Office.targets(176,9): error MSB4018: Calling assembly : (Unknown).
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\OfficeTools\Microsoft.VisualStudio.Tools.Office.targets(176,9): error MSB4018: ===
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\OfficeTools\Microsoft.VisualStudio.Tools.Office.targets(176,9): error MSB4018: LOG: This bind starts in default load context.
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\OfficeTools\Microsoft.VisualStudio.Tools.Office.targets(176,9): error MSB4018: LOG: Using application configuration file: C:\Users\chq-andrewt\AppData\Local\Microsoft\VisualStudio\11.0\devenv.exe.config
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\OfficeTools\Microsoft.VisualStudio.Tools.Office.targets(176,9): error MSB4018: LOG: Using host configuration file:
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\OfficeTools\Microsoft.VisualStudio.Tools.Office.targets(176,9): error MSB4018: LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\OfficeTools\Microsoft.VisualStudio.Tools.Office.targets(176,9): error MSB4018: LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\OfficeTools\Microsoft.VisualStudio.Tools.Office.targets(176,9): error MSB4018: LOG: The same bind was seen before, and was failed with hr = 0x80070002.
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\OfficeTools\Microsoft.VisualStudio.Tools.Office.targets(176,9): error MSB4018:
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
I've found that the crash doesn't happen because of the change to Reference.vb specifically. I can consistently reproduce this if I create a new Outlook 2013 Add-In project, create a new class, and have it inherit Microsoft.Web.Services2.WebServicesClientProtocol:
Public Class Class1
Inherits Microsoft.Web.Services2.WebServicesClientProtocol
End Class
Once I make that change, I add Microsoft.Web.Services2.dll to the project References and after some prompting, System.Web.Services.dll. I rebuild all and promptly get the above error.
I've found that if I use Microsoft.Web.Services3.WebServicesClientProtocol instead, it works fine.
This is my first Visual Basic project (and any project using Microsoft tools, for that matter), so I may be missing something painfully obvious. The choice to use this web service (and WSE2 by extension) wasn't my choice; I'm trying to interface with something others have already purchased.
I've reinstalled Visual Studio with no luck.
Any hints on why this is happening or how to troubleshoot this a bit more? Thanks in advance!
It turns out that WSE 2 is simply too old. It only supports the .NET framework up to version 2, which is I think why it was tanking. I'm using 4.5 (could only go as low as 4) since I was writing an Outlook 2013 add-in. Since there isn't any built-in functionality for doing SOAP attachments AT ALL, I ended up POSTing the raw SOAP message by hand as it was a free solution and pretty straightforward.
No comment on how resilient and future-proof it is...
Public Shared Sub createAttachment(uploadPath As String, fileName As String, ticketHandle As String, description As String)
Dim fInfo As New FileInfo(uploadPath)
Dim numBytes As Long = fInfo.Length
Dim fStream As New FileStream(uploadPath, FileMode.Open, FileAccess.Read)
Dim br As New BinaryReader(fStream)
Dim data As Byte() = br.ReadBytes(CInt(numBytes))
br.Close()
fStream.Close()
Dim boundary As String = "Part_3_4083017.1413597427118"
' Set the 'Method' property of the 'Webrequest' to 'POST'.
Dim myHttpWebRequest As HttpWebRequest = CType(WebRequest.Create("http://soapserver:8080/axis/services/USD_R11_WebService"), HttpWebRequest)
myHttpWebRequest.Method = "POST"
myHttpWebRequest.UserAgent = "Jakarta Commons-HttpClient/3.1"
myHttpWebRequest.Host = "soapserver:8080"
myHttpWebRequest.ContentType = "multipart/related; type=""text/xml""; start=""<rootpart#soapui.org>""; boundary=""----=_" & boundary & """"
Dim myWebHeaderCollection As WebHeaderCollection = myHttpWebRequest.Headers
myWebHeaderCollection.Add("MIME-Version: 1.0")
myWebHeaderCollection.Add("Accept-Encoding: gzip,deflate")
myWebHeaderCollection.Add("SOAPAction:""""")
'myWebHeaderCollection.Add("Expect:100-continue")
Dim inputData As String = Console.ReadLine()
Dim postData As New StringBuilder()
postData.Append("------=_" & boundary & vbCrLf)
postData.Append("Content-Type: text/xml; charset=UTF-8" & vbCrLf)
postData.Append("Content-Transfer-Encoding: 8bit" & vbCrLf)
postData.Append("Content-ID: <rootpart#soapui.org>" & vbCrLf)
postData.Append("" & vbCrLf)
postData.Append("<soapenv:Envelope xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:ser=""http://www.vendorurl.com/TheirProduct"">")
postData.Append("<soapenv:Header/>")
postData.Append("<soapenv:Body>")
postData.Append("<ser:createAttachment>")
postData.Append("<sid>" & sid & "</sid>")
postData.Append("<repositoryHandle>" & getRepositoryHandle() & "</repositoryHandle>")
postData.Append("<objectHandle>" & ticketHandle & "</objectHandle>")
postData.Append("<description>" & description & "</description>")
postData.Append("<fileName>" & uploadPath & "</fileName>")
postData.Append("</ser:createAttachment>")
postData.Append("</soapenv:Body>")
postData.Append("</soapenv:Envelope>" & vbCrLf)
postData.Append("------=_" & boundary & vbCrLf)
postData.Append("Content-Type: image/x-png; name=" & fileName & vbCrLf)
postData.Append("Content-Transfer-Encoding: binary" & vbCrLf)
postData.Append("Content-ID: <" & fileName & ">" & vbCrLf)
postData.Append("Content-Disposition: attachment; name=""" & fileName & """; filename=""" & fileName & """" & vbCrLf)
postData.Append("" & vbCrLf)
Dim encoding As New UTF8Encoding()
Dim header As Byte() = encoding.GetBytes(postData.ToString)
Dim tail As Byte() = encoding.GetBytes(vbCrLf & "------=_" & boundary & "--")
myHttpWebRequest.ContentLength = header.Length + data.Length + tail.Length
Dim newStream As Stream = myHttpWebRequest.GetRequestStream()
newStream.Write(header, 0, header.Length)
newStream.Write(data, 0, data.Length)
newStream.Write(tail, 0, tail.Length)
newStream.Close()
Try
Dim response = myHttpWebRequest.GetResponse()
Dim s As Stream = response.GetResponseStream()
Dim sr As New StreamReader(s)
Dim Content As String = sr.ReadToEnd()
'Could parse Content to get the handler for our new attachment
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Related
I've created a little VB.NET console application (using Visual Studio 2019 Commmunity Edition), that automatically downloads a file from the Internet.
The compiled .exe works just fine if I launch it from the Debug directory, inside my Project tree; it does not if I publish the application to a local folder; instead, I get the error message:
Could not load type 'System.ComponentModel.AsyncCompletedEventArgs' from assembly 'System.Net.WebHeaderCollection, Version=4.1.2.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
Here's the configuration I use to publish my app:
Apparently, this is the code generating the exception:
In Program Module:
Imports System
Imports Microsoft.VisualBasic
Imports Microsoft.Win32
Module Program
Sub Main(Args() As String)
(...)
End Sub
Sub Download_SpeedTest()
Dim ooklaWebSite As String
Dim html As String
ooklaWebSite = "https://www.speedtest.net/apps/cli"
Try
' Retrieve download link
Console.WriteLine("Getting download link from " & ooklaWebSite)
html = Get_WebPage(ooklaWebSite)
(...)
Catch ex As Exception
Console.WriteLine("An error occurred downloading SpeedTest utility. - " & ex.Message)
End Try
End Sub
In WebRequests Module:
Imports System.Net
Module WebRequests
Public Function Get_WebPage(WebURL As String) As String
Dim sourceString As String
Dim wc As New System.Net.WebClient
sourceString = wc.DownloadString(WebURL)
wc.Dispose()
Return sourceString
End Function
End Module
Here's an example of what I get when I run the published program from Windows Command Line:
Getting download link from https://www.speedtest.net/apps/cli
An error occurred downloading SpeedTest utility. - Could not load type 'System.ComponentModel.AsyncCompletedEventArgs' from assembly 'System.Net.WebHeaderCollection, Version=4.1.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
As per I could see, the exception occurs as soon the function Get_WebPage is called (no code inside it is executed)
Any suggestion?
When you use Trim unused assemblies (in preview) it sometimes removes assemblies you actually need. You can either turn that off (bloating the file size) or for this particular error, you can add the following to your csproj file:
<ItemGroup>
<TrimmerRootAssembly Include="System.ComponentModel.EventBasedAsync" />
</ItemGroup>
This will make sure that System.ComponentModel.EventBasedAsync.dll (where System.ComponentModel.AsyncCompletedEventArgs is defined) is not trimmed from the final, self-contained binary.
I am storing .dat files in ProgramData to write and read configurations about my software. I can read, but I can't write. These .dat files are copied when software is installed. The installer has been created with AwInstall.
CODE TO WRITE .DAT:
If File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) & "\NameSoftware\Configuration\paramsBiz.dat") = True Then
Dim sw As StreamWriter = New StreamWriter(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) & "\NameSoftware\Configuration\paramsBiz.dat")
sw.Write(myString)
sw.Close()
sw = Nothing
Return True
Else
Return False
End If
ERROR:
I am getting this error:
System.UnauthorizedAccessException: Acceso denegado a la ruta de acceso 'C:\ProgramData\NameSoftware\Configuration\paramsBiz.dat'.
en System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
en System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
en System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
en System.IO.StreamWriter.CreateFile(String path, Boolean append)
en System.IO.StreamWriter..ctor(String path, Boolean append, Encoding encoding, Int32 bufferSize)
en System.IO.StreamWriter..ctor(String path)
UPDATE 1:
ok, is a problem with this directory ProgramData, as has been said Hans Passant
But alternative path could be used to store data and that any user (admin or not) can read and write these files?
After recently upgrading from Excel 2010 to Excel 2013, I moved a custom add-in (.xlam) to the new Application.LibraryPath directory (C:\Program Files\Microsoft Office 15\root\office15\Library\BTRTools). There is a bit of code that launches an executable (exe) file (located in sub directory of the add-in). However, since the upgrade/move, I am not getting an error:
PrettyPrintXml.exe - Application Error
The application was unable to start correctly (0xc000007b). Click OK to close the application.
I'm obviously pretty convinced it is file permissions. I have explicitly added myself permissions with full rights to the \Library folder (and all subs). Note that I think I had to do this even with Excel 2010 (folder at C:\Program Files (x86)\Microsoft Office\Office14\Library) to make things work.
However, after all this, I'm still stuck and can not launch the exe file. Any ideas/suggestions on how to make this work?
Code is pretty standard:
Public Sub RunShellExecute(sFile As String, Optional params As String = "", Optional wait As Boolean = False)
Dim wsh As Object: Set wsh = VBA.CreateObject("WScript.Shell")
Dim waitOnReturn As Boolean: waitOnReturn = wait
Dim windowStyle As Integer: windowStyle = 1
Dim exe As String: exe = IIf(Left(sFile, 1) <> """", """" & sFile & """", sFile)
Dim exeParams As String: exeParams = IIf(params <> "", " " & params, "")
Dim errorCode As Integer: errorCode = wsh.Run(exe & exeParams, windowStyle, waitOnReturn)
If errorCode = 0 Then
'// MsgBox "Done! No error to report."
Else
MsgBox "Program exited with error code " & errorCode & "."
End If
End Sub
I know your question is "Why doesn't this work", but I thought you might be interested in an alternate solution: There is a native VBA PrettyPrintXML. You need to add a reference to the MSXML library in your VBA project by clicking "Tools" ---> "References..." and then check the box next to Microsoft XML, v6.0 (or whatever version is included with your version of Office/Windows).
Please change the title of your question, because Excel VBA is able to use WScript.Shell.Run, otherwise you wouldn't be getting your error.
As for the actual issue, this looks like a 32-bit / 64-bit problem. Investigate whether the program you're calling is appropriate for your system and whether it tries to load the right DLLs.
The problem is not file permissions, then you would get a different status code.
You should use a path without spaces in it, something simple like 'C:\BTRTools'. Then it should work.
Am attempting to Serialize a dynamically generated/compiled assembly to store into SQL and then subsequently extract the assembly for use. However, I am hitting an error that is driving me nuts.
"Could not load file or assembly '<random code>, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified."
When I try to De-Serialize the Assembly. Will appreciate any pointers. Partial codes:
'--------------------------------------------------------------
'This section SUCCESSFULLY Compile & Execute the Dynamic Code
' vsResult returns ok.
' **Note: This is partial code to create the compiler.
'--------------------------------------------------------------
Dim voCompileResults As System.CodeDom.Compiler.CompilerResults = voCompiler.CompileAssemblyFromSource(voCompilerParams, sb.ToString)
Dim voAssembly As Reflection.Assembly = voCompileResults.CompiledAssembly
Dim voInstance As Object = Activator.CreateInstance(voAssembly.GetType("libARules.clsMyRoutine"), {New libARules.Sys.clsInterProcessData(New System.Xml.XmlDocument), New libArrowOps.clsDBAccess})
Dim vsResult As String = voInstance.GetType().InvokeMember("Run", Reflection.BindingFlags.InvokeMethod, Nothing, voInstance, Nothing)
'----------------------------------------------------
'Attempt to Serialize the Assembly for store/forward
'----------------------------------------------------
Dim voMemStream As New IO.MemoryStream
Dim voBF As New Runtime.Serialization.Formatters.Binary.BinaryFormatter
voBF.AssemblyFormat = Runtime.Serialization.Formatters.FormatterAssemblyStyle.Simple
voBF.Serialize(voMemStream, voCompileResults.CompiledAssembly)
'--------------------------------------
'Reset the MemoryStream position to begining
'--------------------------------------
voMemStream.Position = 0
'--------------------------------------
'Attempt to De-Serialize the MemoryStream back to an assembly
'--------------------------------------
voBF = New Runtime.Serialization.Formatters.Binary.BinaryFormatter
voBF.AssemblyFormat = Runtime.Serialization.Formatters.FormatterAssemblyStyle.Simple
voAssembly = voBF.Deserialize(voMemStream)
'----- **Error Here** ---------------------------------
ERROR At this point: at the line voAssembly = voBF.Deserialize(voMemStream)
Could not load file or assembly '...<random code>..., Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
Ok, I finally figured it out after a nap ... Documenting it here for "future generations" :P
Apparently, I should not be Serializing/De-Serializing the CompiledAssembly.
'-----------------------------------------------------
'Instead of Generating in Memory, generate it into a temporary Assembly file (I don't need the CompiledAssembly from the compiler).
' Note: Again, this is partial code, with only the important parts here.
'-----------------------------------------------------
voCompilerParams.ReferencedAssemblies.Add("mscorlib.dll")
voCompilerParams.GenerateInMemory = False
voCompilerParams.OutputAssembly = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "deleteNow_" & Guid.NewGuid().ToString() & ".dll")
Dim voCompileResults As System.CodeDom.Compiler.CompilerResults = voCompiler.CompileAssemblyFromSource(voCompilerParams, sb.ToString)
'--------------------------------------------------------------------------
'After the Assembly is generated, open the Assembly file and read the entire content into a byte buffer.
'Note that this byte buffer **CAN BE STORED into an SQL BLOB field.**
'--------------------------------------------------------------------------
Dim voInstance As Object = Nothing
Dim vsResult As String = ""
Dim voAssembly As Reflection.Assembly = Nothing
If Not voCompileResults.Errors.HasErrors Then
'----------------------------------------------------------------
'No compilation error, open and read the generated assembly file
' into a Byte array.
'----------------------------------------------------------------
Dim voBuffer() As Byte = Nothing
Dim voFileStream As IO.FileStream = IO.File.OpenRead(voCompilerParams.OutputAssembly)
If voFileStream.CanRead Then
ReDim voBuffer(voFileStream.Length - 1)
voFileStream.Read(voBuffer, 0, voFileStream.Length)
End If
voFileStream.Close()
IO.File.Delete(voCompilerParams.OutputAssembly) 'Clean-up after ourselves.
'----------------------------------------------------------------
'Now, re-create the CompiledAssembly from the Byte array.
'----------------------------------------------------------------
If Not IsNothing(voBuffer) Then
voAssembly = Reflection.Assembly.Load(voBuffer)
End If
If Not IsNothing(voAssembly) Then
'--------------------------------------------
'Instantiate my dynamically compiled class
'--------------------------------------------
voInstance = Activator.CreateInstance(voAssembly.GetType("libARules.clsMyRoutine"), {New libARules.Sys.clsInterProcessData(New System.Xml.XmlDocument), New libMyLib.clsMyClass})
If Not IsNothing(voInstance) Then
'------------------------------------------------
'Run my dynamic code to proof that it is working
'------------------------------------------------
vsResult = voInstance.GetType().InvokeMember("Run", Reflection.BindingFlags.InvokeMethod, Nothing, voInstance, Nothing)
End If
End If
End If
And whola... the vsResult is populated. This is a proof of concept that the CompiledAssembly can be stored and reused later. NOTING that the actual temporary assembly file has been deleted before the voAssembly object is recreated from voBuffer().
Has anyone delt with this exception from ABCpdf? We're running on Server 2008 and only have issues converting Office files (Word and Excel). This all worked well on Server 2003. Because we're only having issues with Office files I wonder if it's related to the XPS support on Server 2008? The code that calls into this function is running as a Windows Service.
Private Overloads Function ConvertMicrosoftOfficeDocToPdf(ByVal inputFile As Byte(), ByVal fileExt As String) As Byte()
Dim abcDoc As WebSupergoo.ABCpdf7.Doc = Nothing
Try
abcDoc = New WebSupergoo.ABCpdf7.Doc()
Dim xro As New WebSupergoo.ABCpdf7.XReadOptions()
xro.FileExtension = fileExt
Try
abcDoc.Read(inputFile, xro)
Catch ex As Exception
System.Diagnostics.Trace.Write(ex.ToString())
Throw ex
End Try
Dim fileBytes As Byte() = abcDoc.GetData()
Return fileBytes
Finally
If Not abcDoc Is Nothing Then
abcDoc.Clear()
abcDoc.Dispose()
End If
End Try
End Function
WebSupergoo.ABCpdf7.Internal.PDFException:
Attempted to read or write protected
memory. This is often an indication
that other memory is corrupt. --->
System.AccessViolationException:
Attempted to read or write protected
memory. This is often an indication
that other memory is corrupt.
at WebSupergoo.ABCpdf7.Internal.NDoc._InvokeMethod(IntPtr
inDoc, Int32 inMethod, Int32 inIndex,
Int32 inFlags, String inParams,
String& outErr)
at WebSupergoo.ABCpdf7.Internal.NDoc.InvokeMethod(IntPtr
inDoc, Int32 inMethod, Int32 inIndex,
Int32 inFlags, String inParams,
String& outErr)
at WebSupergoo.ABCpdf7.Doc.PrintToXps(String
inputFile, String outputFile, Int32
timeout, String printerName)
at WebSupergoo.ABCpdf7.Operations.XpsImportOperation.ImportAny(Doc
doc, String path, Int32 timeout)
at WebSupergoo.ABCpdf7.XReadOptions.ImportXpsAny(Doc
doc, String path, Boolean clear)
at WebSupergoo.ABCpdf7.XReadOptions.Read(Doc
doc, Byte[] data, ReadModuleType
module)
at WebSupergoo.ABCpdf7.XReadOptions.Read(Doc
doc, Byte[] data)
Added a folder called "Desktop" here:
C:\Windows\SysWOW64\config\systemprofile\
http://social.msdn.microsoft.com/Forums/en/innovateonoffice/thread/b81a3c4e-62db-488b-af06-44421818ef91
Actual problem is that the folder where you are trying write the file, give the write permission to IIS_IUSR. Then it should work.