"The object does not support this method" - Error when trying to update the subject of an email (MailItem.Subject) - outlook-addin

I'm maintaining a C# Outlook add-in. It runs, since many years, in Outlook 2003. Today, a user reported an error I never saw before. For two mails (both from the same sender), she's getting this error message when she tries to process them:
The object does not support this method.
at Microsoft.Office.Interop.Outlook._MailItem.set_Subject(String Subject)
The exception is raised when the add-in tries to update the subject:
private static void ForceReconnectToExchangeServer(Outlook.MailItem mi)
{
mi.Subject = mi.Subject + ""; // <-- HERE
mi.Save();
}
I can see a second error message (a tooltip at the end of the line in Visual Studio):
errorCS0433: The type 'MailItem' exists in both
'Microsoft.Office.Tools.Outlook.Implementation, Version=10.0.0.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' and
'Microsoft.Office.Tools.Outlook, Version=10.0.0.0, Culture=neutral
(... can't see the rest of the line ....)
Any idea why this is happening? Many thanks!
Note 1: This add-in uses a recent version of Redemption.
Note 2: I'm getting the same error when I forward the message to myself (an process it), even if I delete everything in the message. If I change the mail format to Plain Text however, no error.
Note 3: this problem maybe related to this one, but nobody answered it.

Do you have both references in your project? Make sure there are no conflicts.
Also keep in mind that updating Subject will cause conversation specific properties to be be reset. Resetting the message class (IPM.Note.Dummy, then back to the original one) might be a better idea.

The Microsoft.Office.Tools.Outlook namespace contains a set of classes and interfaces that enable you to create form regions that customize Microsoft Office Outlook forms.
I'd suggest reviewing the code base and remove unused references from the project. Also make sure that the Outlook namespace points to the Microsoft.Office.Interop.Outlook one, for example:
private static void ForceReconnectToExchangeServer(Microsoft.Office.Interop.Outlook.MailItem mi)
{
mi.Subject = mi.Subject + ""; // <-- HERE
mi.Save();
}

Related

Webforms Error shows TWO projects although solution shows ONE project

In a VS-2019 webforms solution I get this error that shows TWO projects although the solution only has ONE project.
Severity: Error
Code Description : BC30456 'prpPageCaption' is not a member of 'MasterPage'.
Project: 7_SessionExpired.aspx, repo_TripManagement
File: C:\Users...\SessionExpired.aspx.vb
Line: 100
Suppression State: Active
It appears that the error shows TWO projects and I did not create a project named 7_SessionExpired.aspx
The vb-page "SessionExpired.aspx and .vb" was copied from a similar project in VS-2017. This is confusing to me and I don't have any way to know what this error is saying.
Here is the LINE=100 from the source VB file:
100| | Master.prpPageCaption = "Session has Expired"
Here is the property in the master-page:
Public Property prpPageCaption() As String
Get
Return Me.lblCaption.Text
End Get
Set(ByVal p_sCaption As String)
Me.lblCaption.Text = p_sCaption
Me.updpanelPageCaption.Update()
End Set
End Property
The vb-page "SessionExpired.aspx and .vb" was copied from a similar project in VS-2017. This is confusing to me and I don't have any way to know what this error is saying. I need your help. Thanks...John
Think the IDE/VS-2019 is confused and I cut ALL of the files for SessionExpired.aspx (.vb) and pasted them in a my-documents-folder.
I then added a webform-page with Master-page (WebForm1.aspx) into the project.
I then added the ASPX objects as UI for the page. I performed a "View Code" option and the / VB-code structure is shown. I only added "Option Explicit ON". Saved both modified files and closed the SOLUTION.
I then re-opened the solution and the code compiled -- even though the full VB-functionality was not coded.
From the 'Solution Explorer' I then renamed the WebForm1.aspx to "SessionExpired" and compiled again -- all ok.
Finally I added the VB-code from the saved-off original SessionExpired.vb code.
All of the errors shown above were cleared and things are working.
IMHO, bringing in an older webform brings with it the old-style of 'designer' and by starting with a VS-2019 webform-page conforms to the VS-2019 designer pattern.
I apologize to those that viewed this question.
Thanks. John.

Place Equipment From Ribbon Revit 2015: Transaction already started

Stack,
I'm programming an external application that works in Autodesk's Revit (2015). I've created a button on the ribbon that allows the user to place a special equipment that I'll use later to read and pass on to another process. I using 'TheBuildingCoder's' 'Family API' examples to do so. The button on the ribbon has an external command set in the .addin file in the ProgramData Directory...
<AddIn Type="Command">
<Assembly>C:\GSN Programs\MyDll.dll</Assembly>
<AddInId>{97715E4F-EA48-4690-8C62-B5D4836FF452}</AddInId>
<FullClassName>RcarsPlugIn.PlaceEquipment</FullClassName>
<VendorId>MyCompany, LLC</VendorId>
<Text>Place Equipment</Text>
<VisibilityMode>AlwaysVisible</VisibilityMode>
<Discipline>Any</Discipline>
<LanguageType>Unknown</LanguageType>
</AddIn>
On the button press, I put the command data into a global variable to use throughout the program...
If IsNothing(gv_oGo) Then
gv_oGo = New clsGeneralOperations
gv_oGo.CachedCommandData = exCommandData
gv_oGo.UiApp = exCommandData.Application.ActiveUIDocument.Application
End If
With the CommandData cached I move to place the equipment by user pick...
uiDoc = gv_oGo.UiApp.ActiveUIDocument
oSym = oRF.FindElement(doc, GetType(FamilySymbol), "MyEQUIP")
uiDoc.PromptForFamilyInstancePlacement(oSym)
Public Function FindElement(doc As Document, targetType As Type, sTargetName As String) As Element
Return New FilteredElementCollector(doc).OfClass(targetType).FirstOrDefault(Function(e) e.Name.Equals(sTargetName))
End Function
That's where the problem comes into play. I get an error message sent back from Revit stating that "Placement is not permitted in an already modifiable document. The active transaction must be closed first." The problem is, I haven't started a different transaction. The button onthe ribbon is the first that touched when Revit starts.
Is there a way to loop through the open transactions and find one that is open? Is the document in some state that I don't understand? I'm not sure which direction to turn here... any help would be appreciated.
Thanks,
Runnin...
Ok, one clarifying question - the exception is occurring on
uiDoc.PromptForFamilyInstancePlacement(oSym) line correct? if so, try using a subtransaction to complete your command instead:
Document doc = uiDoc.Document;
using (SubTransaction subtr_fam = new SubTransaction(doc))
{
try
{
uiDoc.PromptForFamilyInstancePlacement(oSym);
}
catch(Exception e)
{
Console.WriteLine(e.StackTrace.ToString());
}
}

SubSonic throwing 'System.IndexOutOfRangeException' when in Visual Studio Debug mode

I recently inherited the code set for a Product I now own which uses Subsonic 2.1.0 to perform its data-access.
When I go in to debug said code set, all that I get in the Output window of Visual Studio 2010 is the following (for pretty much every column of every object trying to be loaded):
A first chance exception of type 'System.IndexOutOfRangeException' occurred in System.Data.dll
This is the block of code where it is blowing up in Subsonic, which is located in the SubSonic.RecordBase class, which looks like so:
/// <summary>
/// Loads the object with the current reader's values. Assumes the reader is already moved to
/// first position in recordset (aka has been "Read()")
/// </summary>
/// <param name="dataReader">The data reader.</param>
public virtual void Load(IDataReader dataReader)
{
foreach(TableSchema.TableColumn col in BaseSchema.Columns)
{
try
{
SetColumnValue(col.ColumnName, dataReader[col.ColumnName]);
}
catch(Exception)
{
// turning off the Exception for now
// to support partial loads
// throw new Exception("Unable to set column value for " + col.ColumnName + ": " + x.Message);
}
}
SetLoadState();
MarkClean();
}
The offending line in there is:
SetColumnValue(col.ColumnName, dataReader[col.ColumnName]);
col.ColumnName doesn't match anything in the dataReader at this point. It's almost like it's using an old/prior dataReader to attempt to pull data from.
I'm hoping someone else has encountered this issue, as I'm still fairly new to Subsonic and have only used Hibernate in the past for an ORM.
This happens on both my older machine and a new one I just built, both running Windows 7 Professional x64 w/ Visual Studio 2010 Professional as the IDE.
I've gone through the forums, Google, and many other sites out there, but have yet to find anyone else encountering this issue.
If more information is required, please let me know and I'll be happy to post!
Thanks in advance!
Justin
After spending a while longer looking into this issue, I've realized that it's intentionally throwing these Exceptions for the sake of "partially loading" a data object when only certain fields are being retrieved from the database and mapped to the data object itself. (e.g. just supresses the Exceptions itself and resumes if it can't map a column's data properly.
Not sure if this was originally part of the SubSonic code or something that was introduced by those before me.
Thanks again!
Justin
It looks like the DB Schema may have changed since the SubSonic objects where last created.

ConfigurationManager not declared - Have dll

Quick background: I have a VB.NET application in which I was previously using ConfigurationSettings.AppSettings to read from app.config, and got an error message to change it to System.Configuration.ConfigurationManager.AppSettings (as the first way is now obsolete)
I did so, and I even have a reference to System.Configuration.dll AND the Imports statement at the top, but I am getting a "Name ConfigurationManager not declared" error message. Any suggestions?
CODE:
It's pretty straightforward - I'm just checking if something exists, and if it does, I read from it:
If Not Exists(ConfigurationManager.AppSettings.Get(rep & "Email")) Then
Return False
End If
message = ReadAllText(ConfigurationManager.AppSettings.Get(rep & "Email"))
The project template doesn't have the reference you need. Project + Add Reference, select "System.Configuration".
For more insight, click the "Show All Files" icon at the top of the Solution Explorer window and open the References node.
Another issue that causes this is the reference being the wrong case.
System.configuration was in the .vbproj, instead of System.Configuration.
For me, compiling with the above mistake worked on Windows but not on Linux, but fixing it to the latter made it work on both.
If you are using visual studio 2015 and Visual Basic language. Go to Project + Add Reference > Select Assemblies > Framework. Search for System.configuration. Add the DLL file. After it. On your form, add this in the first line without quotations "Imports System.Configuration" go to your connection string declaration then put this value without quotation "ConfigurationManager.ConnectionStrings("'string configuration name'").ConnectionString" like this.
Public constr As String = ConfigurationManager.ConnectionStrings("string configuration name").ConnectionString
This one works for me. Just now. Hope this one helps others. ^_^

Code Analysis Error: Declare types in namespaces

Is VS2010, I analyzed my code and got this error:
Warning 64 CA1050 : Microsoft.Design : 'ApplicationVariables' should be declared inside a namespace. C:\My\Code\BESI\BESI\App_Code\ApplicationVariables.vb 10 C:\...\BESI\
Here is some reference info on the error. Essentially, I tried to create a class to be used to access data in the Application object in a typed way.
The warning message said unless I put my (ApplicationVariables) class in a Namespace, that I wouldn't be able to use it. But I am using it, so what gives?
Also, here is a link to another StackOverflow article that talks about how to disable this warning in VS2008, but how would you disable it for 2010? There is no GlobalSuppressions.vb file for VS2010.
Here is the code it is complaining a bout:
Public Class ApplicationVariables
'Shared Sub New()
'End Sub 'New
Public Shared Property PaymentMethods() As PaymentMethods
Get
Return CType(HttpContext.Current.Application.Item("PaymentMethods"), PaymentMethods)
End Get
Set(ByVal value As PaymentMethods)
HttpContext.Current.Application.Item("PaymentMethods") = value
End Set
End Property
'Etc, Etc...
End Class
I suspect that the code you entered is in your App_Code fodler of your web app. This code is accessible from your web code as you have deomnstrated but is not accessible from any other assembly.
You can suppress the instance of the error by right mouse clicking on the particular error and selecting "Suppress Message In Source." That'll result in code being added to your source that says "the next time you check this error-fuggedabodit!"
When to Suppress Warnings
--------------------------------------------------------------------------------
While it is never necessary to suppress a warning from this rule, it is safe to do this when the assembly will never be used with other assemblies.
To suppress the error on all occurences, select "Suppress in Project Suppression File"