I'm working on an Add-in project wich generates some codes and adds it in different projects in a solution.
The solution structure is like below:
Solution
SolutionFolder1
TargetProject
OtherProject1
OtherProject2
SolutionFolder2
TargetProject
OtherProject1
OtherProject2
Due to solution design the TargetProject names in both Solution folders are exactly the same! and it cannot be changed,(that's why there is solution folders there)
The problem is when I try to add files to either the projects there is no problem(suppose I add some files in different folders in SolutionFolder1.TargetProject, then when I try to add some other classess in SolutionFolder2.TargetProject it
gives me the error below:
System.ArgumentException was unhandled by user code Message=The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))
Source=""
StackTrace:
at EnvDTE.ProjectItems.Item(Object index)
at TransactionsAddIn.TransactionWizard.TestTransactionWizard.SaveToFrontEnd() in D:\My Projects\visual studio 2010\Projects\TransactionsAddIn\TransactionsAddIn\TransactionWizard\TestTransactionWizard.cs:line 440
at TransactionsAddIn.TransactionWizard.TestTransactionWizard.btnAddFiles_Click(Object sender, EventArgs e) in D:\My Projects\visual studio 2010\Projects\TransactionsAddIn\TransactionsAddIn\TransactionWizard\TestTransactionWizard.cs:line 422
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ThreadContext.LocalModalMessageLoop(Form form)
InnerException:
Here is the code I use:
public Solution2 Solution
{
get;
internal set; // which was set to ((Solution2)((DTE2)application)).Solution in Connect.cs class in Add-In project
}
public Project FindItemtByName(string name)
{
foreach (Project project in Solution)
{
if (project.Name == name)
return project;
}
// not exists.
return null;
}
private Project GetTargetProject1()
{
var frontEndItems = this.FindItemtByName("SolutionFolder1").ProjectItems;
foreach (ProjectItem item in frontEndItems)
{
if (item.Name.Equals(TARGET_PROJECT_NAME)) return ((Project)item.Object);
}
return null;
}
private Project GetTargetProject2()
{
var frontEndItems = this.FindItemtByName("SolutionFolder2").ProjectItems;
foreach (ProjectItem item in frontEndItems)
{
if (item.Name.Equals(TARGET_PROJECT_NAME)) return ((Project)item.Object);
}
return null;
}
void MainMethod()
{
string xamlTemplatePath = Solution.GetProjectItemTemplate("SLPage.zip", @"CSharp\Silverlight");
if (!File.Exists(xamlFullPatch))
{
GetTargetProject1.ProjectItems.Item(1).ProjectItems.Item(2).ProjectItems
.AddFromTemplate(xamlTemplatePath, "Class1.xaml");
}
string codeTemplatePath = Solution.GetProjectItemTemplate("CodeFile.zip", @"CSharp");
if (!File.Exists(processFullName))
{
GetTargetProject2.ProjectItems.Item(3).ProjectItems.Item(4).ProjectItems
.AddFromTemplate(codeTemplatePath, String.Format("Tlr{0}Process.cs", _tranCode));
// ERROR! : System.ArgumentException was unhandled by user code
// Message=The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))
}
}
<div>
By the way, I tried to simulate the problem in the case project names are different and there was no problem. I have searched a lot in the internet and red many topics which mostly refered the issue as .Net framework caching which is not the case here, would
you please give me a hand, Any ideas are welcomed.
Amin.Mirzapo...
Member
546 Points
98 Posts
Add-in Code generation, HRESULT: 0x80070057
Jun 16, 2012 02:37 AM|LINK
Hi,
I'm working on an Add-in project wich generates some codes and adds it in different projects in a solution.
The solution structure is like below:
Due to solution design the TargetProject names in both Solution folders are exactly the same! and it cannot be changed,(that's why there is solution folders there)
The problem is when I try to add files to either the projects there is no problem(suppose I add some files in different folders in SolutionFolder1.TargetProject, then when I try to add some other classess in SolutionFolder2.TargetProject it gives me the error below:
System.ArgumentException was unhandled by user code
Message=The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))
Source=""
StackTrace:
at EnvDTE.ProjectItems.Item(Object index)
at TransactionsAddIn.TransactionWizard.TestTransactionWizard.SaveToFrontEnd() in D:\My Projects\visual studio 2010\Projects\TransactionsAddIn\TransactionsAddIn\TransactionWizard\TestTransactionWizard.cs:line 440
at TransactionsAddIn.TransactionWizard.TestTransactionWizard.btnAddFiles_Click(Object sender, EventArgs e) in D:\My Projects\visual studio 2010\Projects\TransactionsAddIn\TransactionsAddIn\TransactionWizard\TestTransactionWizard.cs:line 422
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ThreadContext.LocalModalMessageLoop(Form form)
InnerException:
Here is the code I use:
public Solution2 Solution { get; internal set; // which was set to ((Solution2)((DTE2)application)).Solution in Connect.cs class in Add-In project } public Project FindItemtByName(string name) { foreach (Project project in Solution) { if (project.Name == name) return project; } // not exists. return null; } private Project GetTargetProject1() { var frontEndItems = this.FindItemtByName("SolutionFolder1").ProjectItems; foreach (ProjectItem item in frontEndItems) { if (item.Name.Equals(TARGET_PROJECT_NAME)) return ((Project)item.Object); } return null; } private Project GetTargetProject2() { var frontEndItems = this.FindItemtByName("SolutionFolder2").ProjectItems; foreach (ProjectItem item in frontEndItems) { if (item.Name.Equals(TARGET_PROJECT_NAME)) return ((Project)item.Object); } return null; } void MainMethod() { string xamlTemplatePath = Solution.GetProjectItemTemplate("SLPage.zip", @"CSharp\Silverlight"); if (!File.Exists(xamlFullPatch)) { GetTargetProject1.ProjectItems.Item(1).ProjectItems.Item(2).ProjectItems .AddFromTemplate(xamlTemplatePath, "Class1.xaml"); } string codeTemplatePath = Solution.GetProjectItemTemplate("CodeFile.zip", @"CSharp"); if (!File.Exists(processFullName)) { GetTargetProject2.ProjectItems.Item(3).ProjectItems.Item(4).ProjectItems .AddFromTemplate(codeTemplatePath, String.Format("Tlr{0}Process.cs", _tranCode)); // ERROR! : System.ArgumentException was unhandled by user code // Message=The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG)) } }<div>By the way, I tried to simulate the problem in the case project names are different and there was no problem. I have searched a lot in the internet and red many topics which mostly refered the issue as .Net framework caching which is not the case here, would you please give me a hand, Any ideas are welcomed.
</div>Thanks in advance
Dino He - MS...
Star
8068 Points
1023 Posts
Microsoft
Re: Add-in Code generation, HRESULT: 0x80070057
Jun 20, 2012 01:25 AM|LINK
HI
You can try to create a new project with same name in other folder, and then cover this folder.
http://msdn.microsoft.com/en-us/library/windows/desktop/aa378137(v=vs.85).aspx
If you have any feedback about my replies, please contact msdnmg@microsoft.com
Microsoft One Code Framework