Activex component cant create object error, cannot find cause [duplicate] - vb.net

Solved, see comments!
I have a simple .NET DLL written in c#.
In asp-classic or VB.NET i can create the object and call a member function in the DLL without any problem.
But, and this is my stumbling point, i can't access class properties.
Here's the sample code:
[Guid("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"),
ClassInterface(ClassInterfaceType.None),
ComSourceInterfaces(typeof(IComEvents))]
public class Com : IComInterface
{
public string MyProperty{ get; set; } // <-- NOT ACCESSIBLE
public void MyFunction() // <-- ACCESSIBLE
{
}
}
Here's the server-side script:
Set com = Server.CreateObject("ns.Com") // WORKS
com.MyProperty = "abc" // GIVES ERROR
com.MyFunction // WORKS
I get the following error-message:
Microsoft VBScript Runtime Error "800a01b6'
Object Doesn't Support This Property or Method: MyProperty
Can anybody tell me, why i can call the function 'MyFunciton', but if i want to set the property-value, i get the error above?

Properties must be included in the interface definition to make them visible to COM.
Example:
[Guid("... some GUID ...")]
[ComVisible(true)]
public interface MyClassInterface
{
string MyProperty { get; set; }
bool MyMethod();
}

Related

How to set properties if class has a static constructor?

I have a fully implemented property with private variable as shown below:
using System;
namespace ClaimMonitorInfo
{
internal class Claims
{
static Claims()
{
new MainModule();
}
private string claimName = string.Empty;
public string ClaimName
{
get
{
return claimName ;
}
set
{
claimName = value;
}
}
}
}
External projects will be setting it but the property never gets set inside its own namespace. So Jenkins thought setter has never been used and gave me a warning message. The constructor of the class is static. How can I assign default values for the property? Need to mention that, project has to be built with MSBuild 12, so C# 6.0 features won't be acceptable. Any help is greatly appreciated.
Sincerely

Ninject invalid cast exception

public partial class CTMSEntitiesModel : OpenAccessContext, ICTMSEntitiesModelUnitOfWork
{
public CTMSEntitiesModel(string connection)
:base(connection, backend, metadataSource)
{ }
// there are more IQueryable requests here
}
public interface ICTMSEntitiesContext : ICTMSEntitiesModelUnitOfWork
{
FetchStrategy FetchStrategy { get; set; }
}
public interface ICTMSEntitiesModelUnitOfWork : IUnitOfWork
{
//all the IQueryable requests are here
}
I need to bind the ICTMSEntitiesContext to CTMSEntitiesModel. How would I go about doing that? What am I doing wrong when I do this? It is throwing an InvalidCastException.
kernel.Bind(typeof(CTMSDAL.ICTMSEntitiesContext)).To(typeof(CTMSDAL.CTMSEntitiesModel)).InRequestScope()
.WithConstructorArgument("connection", System.Configuration.ConfigurationManager.ConnectionStrings["CTMS_MVCConnection"].ConnectionString);
I would appreciate all the help you can provide!
Thanks,
Safris
You have to implement the ICTMSEntitiesContext in the CTMSEntitiesModel class. Otherwise there is no way to cast an instance of the class to the target interface.
Given that you are using OpenAccess and the fact that the context class may be automatically generated I would suggest to you add the interface implementation into a new partial class in different project file to avoid losing the custom code after the original file is regenerated:
public partial class CTMSEntitiesModel : ICTMSEntitiesContext
{
// FetchStrategy property is already defined
}

mono rises unexpected compiler errors

I have the following class
public class LockRequest
{
public int Id { get; set; }
public string TypeName { get; set; }
public bool Ok { get; set; }
public LockRequest ( int id, string t)
{
Id = id;
TypeName = t;
}
}
Then, it's referenced in a delegate, as follows
private static void ReceiveLockRequest<LockRequest>(PacketHeader header, Connection connection, LockRequest input )
{
LockRequest lr = new LockRequest(1, "SomeTypeName" );
Console.WriteLine( String.Format ( "{0} ", input.TypeName) );
}
When compiling, both lines from the delegate rises compiler errors.
The line with the "new()", produces "Cannot create an instance of the type class 'LockRequest' because it does not have the 'new()' constraint.
The line which would show some of the input data gives "The type 'Lockrequest' does not contains a definition for 'TypeName' and no extension method 'TypeName' ... etc".
Could someone explain why is this behaviour?
My dev environment is Ubuntu 10.04 (64 bits) and Monodevelop 2.8.6.3
TIA
Could add some info.
I changed the name of the class, and the thing compiled. The whole class is to be serialised by ProtoBuf, so it must be decorated with attributes. Here are is a sample
[ProtoContract]
public class Foo
{
[ProtoMember(1)]
public int { get; protected set; }
[ProtoMember(2)]
public string TypeName { get; protected set; }
...
Just after I added the attributes, mono stop compiling. Same erors raise again.
To test it, I commented the attributes, do a Clean All, an recompile. The errors raise again, as if MonoDevelop cached them.
I need some help more than after the initial post.
2013-10-31
Thank you, Jester. It´s an event handler, from NetworkCommDotNet library.
My faults:
1) The first error (members not recognized) raises from the fact that (somewhat astobishing) the "input" argument comes as a plain object. Casting it in another method does the trick.
2) The error regarding the instanciation: the delegate definition in the library have a where clause wich states that T must be class, but no the new() constraint.
That's not a delegate, that's a generic method.
It's not clear what you want to do and why do you need a generic method.
If you really do, then try something along the lines of:
private static void ReceiveLockRequest<T>(PacketHeader header, Connection connection, T input) where T:LockRequest
PS: your development environment is very old, consider upgrading.

.NET Dynamic Decision to Call Similar Classes?

C# on .NET 4.5:
public Interface IMyInterface
{
public string DoSomething( string input1 )
}
public MyClass1 : IMyInterface
{
public string DoSomething( string input1 )
{
return "1";
}
}
public MyClass2 : IMyInterface
{
public string DoSomething( string input1 )
{
return "2";
}
}
At runtime, I want to detect the hosting environment, set some kind of "global", and then based on the global always instance and use MyClass1 or MyClass2. I do not want to have a single "MyClass" and then do lots of case logic inside it to detect the environment.
What is a good pattern or practice to do that? Is this actually a good place for Dynamics?
Thanks.
Seems like you need to use Factory. Create a method in Factory class to return MyClass object. Keep the return type of the method as IMyInterface. Within the method, you can execute your hosting logic and depending upon the output of hosting logic, instantiate proper class and return the reference to the object.

Extending WCF proxy with partial classes and OnDeserializing: OnDeserializing does not get fired

I'm trying to get OnDeserializing work with my WCF Proxy by using partial classes, but for some reason the OnDeserializing doesn't get triggered. In OnDeserialing I need to examine whether the web service returned nothing and set my own default value in that case. Everything looks OK in Visual Studio 2010 and I can access the properties of my WCF proxy in the code editor but at run-time OnDeserialing is never called. Can you please advice me what I'm doing wrong? Here's the code:
Proxy class
public partial class SerialInfo : object, System.ComponentModel.INotifyPropertyChanged {
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=2)]
public string Location {
get {
return this.locationField;
}
set {
this.locationField = value;
this.RaisePropertyChanged("Location");
}
}
}
Extended proxy class
public partial class SerialInfo
{
[OnDeserializing]
void OnDeserializing(StreamingContext c)
{
Location = "Test value";
MessageBox.Show("OnDeserializing was triggered!");
}
}
Try adding brackets to your attribute, and changing the method name
[OnDeserializing()]
void OnDeserializingMethod(StreamingContext c)
{
Location = "Test value";
MessageBox.Show("OnDeserializing was triggered!");
}
EDIT: Also, shouldn't partial classes have identical inheritance? Are you sure your partial class is extending what you think it is?