VB6 parameterized method with a return value over com interop - methods

I can't believe I'm having such a hard time with this, but can someone give me a quick example of a COM interface in C# that is to be called from VB6? I want to pass parameters from VB6 to C#, and return a string to VB6.
Here's what I've got so far (not working):
[ComVisible(true)]
public interface IMonitor
{
string IPAddress(Int64 UserId, Enums.ClientTypes clientType);
}
I also tried:
[ComVisible(true)]
public interface IMonitor
{
void IPAddress(Int64 UserId, Enums.ClientTypes clientType, [Out] string ipAddress);
}
Same error - Function or interface marked as restricted, or the function uses an Automation type not supported in Visual Basic.
FWIW, the ClientTypes enum works great in other VB6 code, so I don't believe the enum to be an issue.

Related

Inheriting default methods with the same name in the class without any compilation error

How a class can implement two interfaces with the same default method in Java 8.
I was not able to get the concept behind the same default method from different interfaces getting inherited in the sub class.Please explain the issue.
interface House {
default String getAddress() {
return "101 Main Str";
}
}
interface Bungalow extends House {
default String getAddress() {
return "101 Smart Str";
}
}
class MyHouse implements Bungalow, House {
}
public class TestClass {
public static void main(String[] args) {
House ci = new MyHouse(); //1
System.out.println(ci.getAddress()); //2
}
}
In the above code default method getAddress() in interface House is present.another method with the same name is declared as default in the extending interface Bungalow
How class MyHouse can implement both the interfaces without any compilation error(because it doesn't know which method has the preference in that case implementing should fail.)
If i call new MyHouse().getAddress(); gives compile error but it should give compilation error even without method calling from MyHouse class.
It seems that the answer is here, where there is a different example, but sort of makes sense and is really close to yours.
Ask me the exact same thing in 1/2 a year and I'll say it will fail at compile time and point me to this answer, so that I could read the JLS again. I guess this is how they decided to implement it. Without thinking too much, I, personally (may be wrong) think that this is at least counter intuitive...

How do I provide custom Intellisense descriptions in Visual Studio

Ok so let's say I have the following class in C#:
class Foo
{
public void Bar() { Console.WriteLine("FooBar"); }
}
In Visual Studio, whenever I instantiate my class and implement my method intellisense looks like this:
All this is showing is the name, return type and input parameters of my method. When viewing any method inside any of the .Net base classes using intellisense, a description is provided.
How do I add a description for my own methods to intellisense, so anybody who uses a *.dll I have written in the future can understand what my methods do without having to refer to external documentation?
Thanks
Add xml documentation :
/// <summary>
/// Foos something
/// </summary>
public void Foo()
{
}

why does this kill vs 2010

If you copy this into VS2010 it sobs and dies. Why?
A colleague sent this to me in a mail saying that this is why the dynamic keyword is dangerous and warning that it'd kill VS, I copied it into what I was working on and lo and behold, VS2010 crashed.(Destroying most of what I'd worked on that morning).
Warning , it'll kill VS without compiling or any other input, if it's there VS will crash.
namespace Crash
{
public class Foo
{
public static void Method(object o)
{
}
}
public class Bar
{
public Foo Foo { get; set; }
public static void Method(dynamic d)
{
Foo.Method(d); //This crashes VS instantly!
}
}
}
Someone has already logged a bug for this.
http://connect.microsoft.com/VisualStudio/feedback/details/704397/vs-crash-when-passing-dynamic-val-to-static-member-of-class-from-a-static-method-in-c
Conditions necessary to cause the crash:
The static method being called must be referenced via only the class name (i.e. without a namespace).
The method making the call must also be static, and the class it belongs to must have a non-static property with the same name as the class whose method is being called.
The dynamic value being passed to it can come from anywhere - it doesn't have to be an argument to the calling function as in the example.

Entity framework asp.net MVC3 .NET 4

I Have a little snag. With my asp.net mvc3 application.
When I trying to compile my app I obtain this Error
Error 2 'Blog.Domain.Concrete.EFEntryRepository' does not implement interface member 'Blog.Domain.Abstract.IEntryRepository.SaveEntry(Blog.Domain.Entities.Entry)' D:\dokumenty\Visual Studio 2010\Projects\MVC3\Blog\Blog.Domain\Concrete\EFEntryRepository.cs 10 19 Blog.Domain
This is my Interface.
namespace Blog.Domain.Abstract
{
public interface IEntryRepository
{
IQueryable<Entry> Entries { get; }
void SaveEntry(Entry entry);
void DeleteEntry(Entry entry);
}
}
And this is my implementation of it.
public class EFEntryRepository : IEntryRepository
{
private EFDbContext context = new EFDbContext();
public IQueryable<Entry> Entries
{
get { return context.Entries; }
}
public void SaveEntry(Entry entry)
{
if (entry.EntryID == 0)
context.Entries.Add(entry);
context.SaveChanges();
}
public void DeleteEntry(Entry entry)
{
context.Entries.Remove(entry);
context.SaveChanges();
}
}
This is link to my project. http://sigma.ug.edu.pl/~kkubacki/Blog.zip //NEW
Now I is compiling.
What I Do Wrong ?
I have new Information about the bug. Now the solution is compiling but the application crashes with the bug information
"{"The type 'Blog.Domain.Concrete.Entry' was not mapped. Check that the type has not been explicitly excluded by using the Ignore method or NotMappedAttribute data annotation. Verify that the type was defined as a class, is not primitive, nested or generic, and does not inherit from EntityObject."} " Visual studio shows bug in the EFEntryRepository class.
I don't know what to do please help.
OK Problem IS Solved.
You have two different Entry classes in different namespaces.
Blog.Domain.Entities.Entry
Blog.Domain.Concrete.Entry
The interface is referring to one and the implementation is referring to the other.

Why is generated override code for generic method incorrect?

I have an abstract generic class
public abstract class Foo<TType>
with an abstract method
public abstract object DoSomething(TType arg = default(TType)) {}
Now, the inherited class
public class BabyFoo : Foo<string>
when I want to override DoSomething and start typing "override " to get the intellisense/generator to write a method skeleton I expected
public override object DoSomething(string arg = default(string))
or even
public override object DoSomething(string arg = null)
but it literally comes up with
public override object DoSomething(string arg = default(TType))
My initial thought is it is a VS2010 bug since optional params are new to c#, but can anybody tell me if there is perhaps a real reason why (reference types vs value types??) the IDE generates this code?
Just to clarify:
public abstract class Foo<TType>
{
public abstract object DoSomething(TType arg = default(TType));
}
public class BabyFoo : Foo<string>
{
// Expected:
public override object DoSomething(string arg = default(string))
// Actual:
public override object DoSomething(string arg = default(TType));
}
Unless there's something I'm missing, it's quite simply a bug in the Visual Studio IDE / code-gen. Changing the method signature to the "expected" one results in code that will compile, as the "actual" one refuses to compile thanks to being clearly invalid.
Having tried a few different types for TType as well as things like the where TType : new() constraint, I couldn't get VS to generate valid code with your DoSomething method.
Congratulations - you've (probably) found a bug in Visual Studio =)
There are always edge cases when it comes to code generation, I logged one for Visual Basic 2005/2008 a long time ago that was resolved WONT FIX as it was a really obscure one comparatively. Hopefully this one'll be fixed though!

Resources