I have an issue where I am unable to access the Name object of a range. So, I am calling Excel.Application.get_Range() and passing in a name. It returns a non-null object and I can access methods. However, Range.Name returns a System.__ComObject(). If I try to access Range.Name.Name I get an exception similar to the following
Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: ''System.__ComObject' does not contain a definition for "Name"
Also, this project is one that I migrated from .net Framework to .net Core. The exact same code works in Framework. I have tried various methods of trying to determine what the underlying type is (because it does not appear to be a Name object). ITypeInfo returns that the typename is Name so it does appear to be a name object.
I'm at a loss as to why I'm unable to access Name.Name in .net core. When I check the .net Core Excel sample they never access a name object.
Also, I am able to access other COM objects like ListObject just fine.
I figured out what the issue is. For anyone else running into this with .net Core, the problem is that .net core appears to not support dynamic types through COM automatically. This is discussed in the following github issue Github issue about dynamic not working. Where it talks about why this doesn't work.
Basically, for my specific case I needed to cast the type manually and then it worked. This also impacts use of IEnumerable COM types needing to be cast directly to IEnumerable before iterating through them.
Assuming you have the following using statement.
using Excel = Microsoft.Office.Interop.Excel;
I had to turn the following:
return range.Name.Name;
into
return ((Excel.Name)range.Name).Name;
As an aside, I also noticed that if you copy/paste the cast above into the debug watch window it does not display properly and instead shows an exception about an invalid cast.
Related
I'm trying to call a PL/SQL procedure with custom type parameters from a SSIS Workflow.
I tried:
Using the ADO.NET connection manager for Oracle - doesn’t work, since it doesn’t allow for parameter mapping.
Using the OLEDB connection manager - ok, but only for simple datatypes on INPUT / OUTPUT -> doesn’t solve my problem since I can’t use custom types, and I don’t have the option to use IN OUT parameters (which also occur in the procedures on the Oracle db).
I then tried to make my own custom mapping through C# by implementing all the necessary classes and interfaces used for custom UDT mapping. This way I managed to make it work to pass custom type parameters to and from the procedure. (POC created as a ConsoleApplication).
The tutorial I followed in creating the custom classes: https://www.codeproject.com/Articles/1139474/ODP-NET-User-Defined-Type-Implementation
I tried using the same code that I used in the Console Application within the SSIS Script Task. And here I met with a strange problem ☹
In order to implement the customType used in the procedure, I used the Oracle.DataAccess reference. Whenever I add this reference to the script task, I get the following error on execution:
DTS Script Task: Runtime Error
The error occurs as soon as I implement a class that uses a reference to Oracle.DataAccess. The class declaration itself seems to be causing this error, cause even when I don’t use them In scriptMain the error remains.
Whenever I comment out the classes (but leave the reference within the script) the component executes without error…
CONFIGURATION:
I'm using Visual Studio 2017 Enterprise Edition,
TargetServerVersion: SQL Server 2017
Target framework on package: .NET Framework 4.5
PATH Environment setting for Oracle client: C:\app\client32\product\12.2.0\client_1\bin
I tried changing the SQL Server target, the Target Framework and some other setting at project and package level but nothing worked.
Anyone knows how to solve this problem so that I can use my C# custom mapping within the Script Task?
Any other solutions offering calling procedures with custom parameters are also welcome :)
Lastly, if anyone knows a good auto UDT mapper I would be grateful :) I tried Odapter - ok but uses Oracle.ManagedDataAccess instead of DataAccess and I can't seem to use OracleDbType.Object there...
EDIT:
I managed to find out that the problem occurs whenever I implement an interface from a reference (f.ex. IOracleCustomType). If I only use this type as a parameter in a method or so, the script executes. As soon as I add a class implementing the interface, the 'Could not load script for execution' error appears..
I have inherited a WCF RIA, Silverlight 4 application that has been dormant for a few years. It is assumed that the code is stable. To get it working I need to install dependencies which were not documented, as far as I can tell.
After installing dependencies based on what information I could gather I am left with the following error.
Operation named 'namereplaced' does not conform to the required
signature. Parameter types must be an entity type or one of the
predefined serializable types
I already tried uninstalling Ria Services as recommended here.
WCF Ria Operation does not conform to the required signature
but this leads to more errors.
I've also tried hunting down a specific version of the Ria Services Toolkit as suggest here, but no luck
https://social.msdn.microsoft.com/Forums/silverlight/en-US/86f40859-18e8-4ce6-8d8a-a864fbe4e3ac/error-operation-named-createuser-does-not-conform-to-the-required-signature-parameter-types?forum=silverlightwcf
Additionally, I tried setting up a drop retrieved from the client's FTP in IIS and saw the following in the machine Event Log
: The service
'/AppName/Services/SomeManager-Web-Services-ImportService.svc' cannot
be activated due to an exception during compilation. The exception
message is: Operation named 'namereplaced' does not conform to the
required signature. Parameter types must be an entity or complex type,
a collection of complex types, or one of the predefined serializable
types.. ---> System.InvalidOperationException: Operation named
'namereplaced' does not conform to the required signature. Parameter
types must be an entity or complex type, a collection of complex
types, or one of the predefined serializable types.
However, using an old installer that the IT team found in the old developers files, I was able to set up an instance of the website which does not generate these errors, but is incompatible with the latest version of the database. I haven't found the source for the setup project in source control.
The method in question is defined as follows
[Invoke(HasSideEffects=true)]
public void NameReplaced(IEnumerable<ImportRecord> recs)
{
foreach (var item in recs)
{
UpdateImportRecord(item);
}
}
I'd ideally like to resolve this without trying to change the code as an investigation needs to be done on an error in the clients environment, then further updates are required.
EDIT:
Included suggestion from Mark W,
public IQueryable<ImportRecord> GetImportRecords()
{
return null;
}
but the same build error is reported.
Since this project is being resurrected for some purpose, I recommend that you use the latest Visual Studio and move it to Silverlight 5. The thought is why deal with old technology which will frankly hamper the process.
Comment out the things that don't work to until you have a running (not operational though) baseline to start from. Then bring back in the things which are causing problems.
I say this from having worked extensively in both S4 & S5 and frankly (to the code) not much changed; in doing this process, yes the upgrade will have problems but they are not insurmountable. Plus the installs smarts got better for S5 and later versions of Visual Studio.
We run RIA Services on a server that does not have it installed. What we did was publish the web site with Copy Local = true on:
System.ServiceModel.DomainServices.EntityFramework
System.ServiceModel.DomainServices.Hosting
System.ServiceModel.DomainServices.Hosting.OData
System.ServiceModel.DomainServices.Server
If that is not it - Due to the magic of domain services, the service needs to auto-generate the class type. Only types that are returned from the service are generated. If the domain service does not have a method to return an Iqueryable or Ienumerable of type ImportRecord, you can create a method that returns null - that will be enough for the code to generate.
Those are my 2 first thoughts.
EDIT: This looks like what I'm talking about :previously asked question
To get a .NET console application running on Server 2003, we're having to downgrade one of our core libraries from .NET 4.5 to 4.0. Among other things, this library has a class that performs some reflection, cycling through an object's properties to get their values using Propertyinfo.GetValue()
According to the MSDN documentation, PropertyInfo.GetValue (Object) is in .NET 4.5 only. In .NET 4.0, this method exists, but in the form PropertyInfo.GetValue (Object, Object[]) (the extra parameter is to know how to handle indexed properties).
If we're to downgrade this code, we need to know what happens when PropertyInfo.GetValue Method (Object) encounters an indexed property, so we can mirror this functionality using PropertyInfo.GetValue Method (Object, Object[]). Can anyone help?
The documentation isn't clear about this, but inspecting the implementation in a decompiler shows that property.GetValue(obj) just calls property.GetValue(obj, null) without any checks whatsoever, and without catching any exceptions whatsoever. Any exception that you would get from property.GetValue(obj) is therefore exactly the exception that you would get from property.GetValue(obj, null), and you should have no problems updating your calls.
I get the error:
Ambiguous match found
During this code on the .Add
var db = new NexusEntities();
db.Reports.Add(mmr);
From googling it appears to be an issue if the there are two classes with the same name but in different namespaces. As far as I can tell this is not the case... Is there another reason why this error can happen? Or is there a way to tell which parameter it is finding two of?
This is a "weakness" in EF. It happens when the same property appears in class / subtype hierarchy.
Most likely you have a hidden field. i.e. a property that has been redefined.
When EF looks for the a property it too must use the type/base tree to find the property. But if it finds it twice in the tree, it interprets this as a duplicate. EF doesnt just use the lowest most specific override.
So property hiding is not possible with EF.
Check your classes, a property will occur twice somewhere.
Although this is probably a much less likely scenario, but we were running EF Core 1.0 which had only one version of the Include() method... in version 1.1, Microsoft added a second implementation (the string version) and since we were calling this method dynamically we got this error after updating our EF Core to 1.1
I am currently building an emulator in C#/Silverlight. Because we are emulating a particular software domain, we have domain-level classes (Cube, CubeSet, BaseApp, etc.) that we have to implement within the scope of our emulator. Additionally, these domain-level classes have to be available to the application developer because they are accessible to applications which will be emulated.
So what we have is a .dll which is a compilation of just the domain-level classes, and then within the emulator implementation itself we have a package of the same domain-level classes.
The goal is to dynamically instantiate the application object, which is doable, and then call a sequence of that application's methods to carry out the emulation. However, in calling one of the methods, we have to pass in a domain-level object which is instantiated within the emulator implementation. We have to call AssociateCubes (which takes a CubeSet parameter) on the dynamically instantiated application. When I try to do that dynamically, I'm getting an InvalidCastException which (amusingly enough) says that a "CubeSet" object cannot be cast as a "CubeSet" object. An example of the code being used to dynamically access the application is:
Object o = Activator.CreateInstance(appType);
MethodInfo AssocCubes = o.GetType().GetMethod("AssociateCubes");
AssocCubes.Invoke(o, new object[] { Cubes });
where Cubes is of type CubeSet in the emulator, and the appType is as given by the user.
Is there any way to force some sort of link between the two so that the compiler recognizes that in reality the same class, or is it that the two classes are completely distinct and cannot be associated in such a way to allow an object of one type to be cast as the other.
One solution I have considered is simply defining a method to manually copy the contents of one object to an instance in the emulator, but the problem therein is that the application developer can define their own methods for the application class to be used as helper methods.
I may not have explained everything completely, so I can offer any clarifications that may help expose a potential solution.
The InvalidCastException only shows last portion of full class name for convinience, but types are compared on full identity: Full Name (including namespaces) and assembly it is coming from (which may have strong name if signed).
Consider using Unit Testing framework for "mocking" objects. Or at least read on how such frameworks wrap classes.
The real fix is to use testable class hierarchies. Often using interfaces instaed of concreate classes help to solve this type if issues.
I don't want to discount the previous answer given, but I have found a solution as I described in the comment I wrote.
What I do instead is pull the domain layer out of the emulator project and compile it separately as a DLL. Now that DLL is referenced in the emulator and the separate applications, so when the types are loaded dynamically they are considered to be the same type after all.