convert object from one assembly to another cli c++ - visual-studio

I have an multi Module Project. Here we are passing System::Object^ from one exe to code from another DLL.
When I am trying to convert that Object to its type(Here we have the same definition) in DLL, I am getting the below error...
[A] can not be cast to [B]; A originates from one assembly , b from another
I tried through some documents but could not crack through.
Both the below code giving that conversion error
LocalClassType ^x1 = LocalClassType (x);
LocalClassType ^x2 = cli::safe_cast<LocalClassType ^>(x)
Can anyone please suggest or guide me through the document where I can convert correctly.

I was able to resolve the issue, and cast it using static_cast
LocalClassType ^x2 = static_cast<LocalClassType ^>(x)

Related

Why is RStudio giving an error when using plotFun from the Mosaic package?

My students are using the Mosaic package for RStudio, and one of them is not able to use the function plotFun. Every time she tries to use it, she gets the same error. For example,
> plotFun(x+2~x)
Error in as.data.frame.default(x[[i]], optional = TRUE) :
cannot coerce class ‘"formula"’ to a data.frame
Are there any thoughts as to what is going wrong? She will need to use this function often for this class; is she missing a package or update of R or RStudio?

BTOUCH:error BI1017:Do not know how to make a signature for System.Int32* in method get_IssueTransport

I am binding JMC objective C static library to Xamarin compatible one, currently I am trying to build my binding project now(which contains ApiDefinition.cs, StructsAndEnums.cs and libJmcSDK.a) but when I try to build this Xamarin binding project I'm getting the following error:
BTOUCH: error BI1017: btouch: Do not know how to make a signature for System.Int32* in method 'get_IssueTransport'.
When I try to search for get_IssueTransport method, their is no search results for this, trying to find the System.Int32 signature as well but not able to find in throughout solution.
Any help in resolving this issue is much appreciated in advance. Thanks.
Answer
Remove unsafe keyword and * from int.
Like:
unsafe int*
Change int* (any pointer type) to IntPtr

Why is the (PyQt5) QWidget not being added to the QBoxLayout

Right so essentially I am creating a user interface and have attempted to add a QtWidgets.QLineEdit to a QVBoxLayout as well as a QtWidgets.QLabel to a different QVBoxLayout. Unfortunately it is not working and throwing up an error:
in build_gui_adddata_device
self.labellayout.addWidget(self.labelsupplierid)
TypeError: QBoxLayout.addwidget(QWidget; int stretch=0, Qt.Alignment alignment=0): first argument of unbound = method must have type QBoxLayout
I have defined labellayout as thus:
print("e")
self.labellayout = QtWidgets.QVBoxLayout
"e" was printed, which is how I know that there is no issue with the definition of the layout itself.
Just for reference this is the QtWidget I was trying to add:
print("f")
self.labelsupplierid = QtWidgets.QLabel("Supplier ID: ")
Again "f" was printed
This is the line that is causing the problem:
print("i")
self.labellayout.addWidget(self.labelsupplierid)
I don't understand why my code isn't working, I am honestly perplexed. My syntax seems to be correct and I have made other build_gui functions that have executed exactly the same type of code (with different widgets, might I add) that have been successful.
Please can someone enlighten me. Many Thanks.

Remove project from solution via Package Manager Console

I am trying to use powershell within the Package Manager Console to script the removal of a project from a solution and I am having a surprisingly hard time.
I can easily add a project by
PM> $dte.Solution.AddFromFile("C:\Dev\Project1.csproj")
Now I want to be remove a project and can't get anything to work.
I have tried a number of things including:
PM> $project1 = Get-Project "Project1Name"
PM> $dte.Solution.Remove($project1)>
Cannot convert argument "0", with value: "System.__ComObject", for "Remove" to
type "EnvDTE.Project": "Cannot convert the "System.__ComObject" value of type
"System.__ComObject#{866311e6-c887-4143-9833-645f5b93f6f1}" to type
"EnvDTE.Project"."
PM> $project = Get-Interface $project1 ([EnvDTE.Project])
PM> $dte.Solution.Remove($project)
Cannot convert argument "0", with value: "System.__ComObject", for "Remove" to
type "EnvDTE.Project": "Cannot convert the "System.__ComObject" value of type
"NuGetConsole.Host.PowerShell.Implementation.PSTypeWrapper" to type
"EnvDTE.Project"."
PM> $project = [EnvDTE.Project] ($project1)
Cannot convert the "System.__ComObject" value of type
"System.__ComObject#{866311e6-c887-4143-9833-645f5b93f6f1}" to type
"EnvDTE.Project".
PM> $solution2 = Get-Interface $dte.Solution ([EnvDTE80.Solution2])
PM> $solution2.Remove($project1)
Exception calling "Remove" with "1" argument(s): "Exception calling
"InvokeMethod" with "3" argument(s): "Object must implement IConvertible.""
PM> $dte2 = Get-Interface $dte ([EnvDTE80.DTE2])
PM> $dte2.Solution.Remove($project)
Method invocation failed because [System.Object[]] doesn't contain a method
named 'Remove'.
I have tried other combinations, but I am clearly spinning my wheels. I appreciate any suggestions.
Right, I know I'm late to the party but I've just been tackling this same issue for an internal NuGet package we've been writing, and I think I've found how to do it.
Indeed Microsoft have (helpfully) left the Delete method unimplemented, and as we have both found, attempting to call the Remove method on the Solution2 interface throws an exciting myriad of errors depending on context!
However what I have found is that directly invoking the Remove method defined in SolutionClass does actually work (despite its being documented by Microsoft as internal use only. But hey, when every other option is exhausted...). The only catch is that the runtime binder also sometimes seems to fail to resolve the method overload, producing the error:
No overload for method 'Remove' takes 1 arguments
All of which means that it's time to get our reflection crayons out! The code looks like this:
$removeMethod = [EnvDTE.SolutionClass].GetMethod("Remove");
$solution = $dte.Solution;
$toremove = ($solution.Projects | where ProjectName -eq "<whatever>");
$removeMethod.Invoke($solution, #($toremove));
After a day of various iterations (many closely resembling those in the question) and varying degrees of success (depending on whether I was executing inside the package manager, from inside the install script or within a debugger), the above is what I have found to be most reliable.
One thing to note is that because the reflected method is defined in EnvDTE.SolutionClass, passing it a EnvDTE._Solution or EnvDTE80.Solution2 throws a Type mismatch error, so unfortunately you cannot obtain your $solution object by the Get-Interface cmdlet (which is usually my preferred method). Doing the cast to [EnvDTE.SolutionClass] wherever possible is obviously preferable, but again I've found varying degrees of success in doing so. Hence the slightly sloppy $solution = $dte.Solution above.
Hope this is useful to someone else!
Looks like it is "Delete" instead of "Remove". See this MSDN article
Project prj = dte.Solution.Projects.Item(1);
prj.Delete();

DbLimitExpression requires a collection argument

Does anyone have the faintest idea what this error means please and how to resolve it? All my research is drawing a blank, I can see how to set it on MSDN but it doesn't explain it in a way that explains to me what the issue is. If I remove some of my LINQ queries to set viewbag items then it seems to resolve it but the moment I set new ones and pass them into my view to generate a mail for MVCMailer it comes back. Not sure if its a viewbag issue or simply that I am calling too many linq queries to generate them to pass to the view.
I am very stuck (again)..........
Cheers,
Steve.
DbLimitExpression requires a collection argument.
Parameter name: argument
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentException: DbLimitExpression requires a collection argument.
Parameter name: argument
An example of the code is:
var VBSalutation = from A in context.Salutations
where A.SalutationId == policytransaction.SalutationId
select A.SalutationName;
ViewBag.Salutation = VBSalutation.FirstOrDefault();
This is repeated for various parameters and then passed to the view.
Well, I faced a similar problem and solved it. Problem was in WHERE clause: data type of left side equal operator (=) sign was not matching with data type of right side. So in your scenario:
where A.SalutationId == policytransaction.SalutationId
SalutationID of A might be an INT and SalutationId of policytransaction might be a string (This is how it was in my case).
I solved it by assigning policytransaction.SalutationId to an Int variable and using it:
int myIntVariable = Convert.ToInt16(policytransaction.SalutationId);
...//some code here
where A.SalutationId == myIntVariable;
Please also note that you cannot directly cast your variables directly in Linq else you'll get an error "LINQ to Entities does not recognize the method". You'll have to use a temp variable and then apply the where clause.
Try ViewBag.Salutation = VBSalutation.SingleOrDefault();

Resources