我正在尝试在Visual Basic中编写Outlook加载项(在Windows 7上的Visual Studio 2012 Professional中),该加载项将与我们在工作中使用的Web服务进行交互。不幸的是,这个特定的Web服务并不真正与时俱进,因此需要Web Reference实现Microsoft.Web.Services2.WebServicesClientProtocol来执行某些操作。当我更改生成的Reference.vb以继承此类而不是默认值和Rebuild All时,构建将失败,并显示以下消息:
------ 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 ==========
我发现崩溃不会发生,因为具体改变了Reference.vb。如果我创建一个新的Outlook 2013加载项项目,创建一个新类,并让它继承Microsoft.Web.Services2.WebServicesClientProtocol:
,我可以一致地重现这一点。Public Class Class1 Inherits Microsoft.Web.Services2.WebServicesClientProtocol End Class
完成更改后,我将Microsoft.Web.Services2.dll添加到项目引用中,并在一些提示后添加System.Web.Services.dll。我重建所有并立即得到上述错误。
我发现如果我使用Microsoft.Web。 Services3 .WebServicesClientProtocol,它可以正常工作。
这是我的第一个Visual Basic项目(以及使用Microsoft工具的任何项目),所以我可能会遗漏一些非常明显的东西。选择使用此Web服务(以及扩展名为WSE2)不是我的选择;我正在尝试与其他人已购买的东西进行交互。
我重新安装了Visual Studio而没有运气。
有关为何发生这种情况或如何解决此问题的任何提示?提前谢谢!
答案 0 :(得分:1)
事实证明,WSE 2太老了。它只支持最高版本2的.NET框架,我认为它为什么会出现问题。自从我编写Outlook 2013加载项以来,我正在使用4.5(只能低至4)。由于没有任何内置功能来执行所有的SOAP附件,我最终手动POST原始SOAP消息,因为它是一个免费的解决方案,非常简单。
没有评论它的弹性和面向未来......
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