1
votes

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!

1

1 Answers

1
votes

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=""<[email protected]>""; 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: <[email protected]>" & 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