Trying to go through my project and expand documentation, and have the following situation:
//TestClass.h
namespace Test {
public enum class TypeOne {
/// <summary>
/// Description <see cref="Test::TypeTwo">TypeTwo</see>
/// </summary>
AAA
};
public enum class TypeTwo {
BBB
};
}
cref produces following error:
warning C4638: XML document comment applied to 'Test.TypeOne.AAA': reference to unknown symbol 'Test::TypeTwo'.
Is there anyway to get the xml documentation to recognize TypeTwo? I would just put TypeTwo above TypeOne, but TypeTwo also as a cref to TypeOne so I would be back in the same situation.
Am I just being stupid?
You'll probably need to handle this situation like you would regularly for such a circular reference in C++: Forward declare TypeTwo before TypeOne (but don't define it).
I think XML documentation may use C#'s scoping notation (the error message certainly does) regardless of the source file language, so perhaps try Test.TypeTwo.
Related
apologies in advance for the long post. I'm hoping somebody can help.
I've been asked to work on upgrading NHibernate (from 2.1.2.4000 to 3.3.1.4000) and Fluent NHibernate (from 1.1.0.685 to 1.3.0.0) in an ASP.NET app. I'm a newbie to NHibernate but have spent several weeks working on this so I've got some understanding.
For instance, I know the newer version of NHibernate has a built-in proxy generator, so I've deleted any references to the old NHibnernate.ByteCode.Castle.dll which was the proxy generator we were using previously, got rid of the reference to that file from the nhibernate.config, and the intention is to use the built-in proxy.
I've been successfully working my way through a variety of issues but have run into one I'm stuck on, and nothing I've found on the web really seems to exactly correspond to it. This is surprising because I would have thought anybody who did such an upgrade would have this issue, but maybe it's just the way we're coding our Entity Base class.
There are two Visual Studio solutions, one of which is a "Framework" solution, which contains the EntityBase class, and the other which is the main application solution, which uses the DLLs from the Framework solution.
In the EntityBase class there are two methods that return the "real" object instead of the proxy, very similar to the "As" method described here: http://sessionfactory.blogspot.com/2010/08/hacking-lazy-loaded-inheritance.html
As I understand it, these methods are essentially returning the "real" (domain) object which is wrapped by the NHibernate proxy object. In my case the methods in question are called "CastTo" and "AsOfType". It is the type constraints on these methods that seem to be causing my issue.
Here is the pertinent code from my EntityBase class:
/// <summary>
/// Represents the base class for a domain entity.
/// </summary>
/// <typeparam name="TIdentity">The type of the identity.</typeparam>
/// <remarks>
/// This class implements all the interfaces that all domain entities must have.
/// </remarks>
[Serializable]
public abstract class EntityBase<TIdentity> : IAuditable, IEntity<TIdentity>, IPersistent
{
/// <summary>
/// Casts to.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
public virtual T CastTo<T>() where T : EntityBase<TIdentity>
{
return (T)this;
}
/// <summary>
/// Casts this entity to the type passed in.
/// This is required when trying to cast from a proxy.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
public virtual T AsOfType<T>() where T : EntityBase<TIdentity>
{
return this as T;
}
So, when I run the unit tests in the main application solution, I'm getting errors like this:
Creating a proxy instance failed ---> System.TypeLoadException: Method 'AsOfType' on type 'LocationProxy' from assembly 'LocationProxyAssembly, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' tried to implicitly override a method with weaker type parameter constraints.
So it seems the Reflection.Emit code that's creating the NHibernate proxy is complaining about the type constraints on the AsOfType and CastTo methods.
So I thought I'd relax those constraints a bit, and instead of using a generic in the type constraint, I'd try just using "Entity" as a constraint (a class derived from EntityBase). So I tried the following (and yes, I know the two methods are essentially doing the same thing, but I'm just trying to preserve the interface of the EntityBase class to avoid breaking all the calls to those methods):
[Serializable]
public abstract class EntityBase<TIdentity> : IAuditable, IEntity<TIdentity>, IPersistent
{
/// <summary>
/// Casts to.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
public virtual T CastTo<T>() where T : Entity
{
if (!typeof(T).IsAssignableFrom(GetType()))
{
throw new InvalidCastException();
}
return this as T;
}
/// <summary>
/// Casts this entity to the type passed in.
/// This is required when trying to cast from a proxy.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
public virtual T AsOfType<T>() where T : Entity
{
return this as T;
}
So now the test fails in a different way. I've got a unit test that looks like this:
/// <summary>
/// Tests the type of the get real.
/// </summary>
[TestMethod, TestCategory("Integration")]
public void TestEntityProxyCastToMethod()
{
using (var unitOfWork = UnitOfWork.Begin(Database.MainSolution.Name()))
{
var person = unitOfWork.GetProxy<Person>(new Guid("E196BC94-DFBA-4D6C-B504-03E00F5CA914"));
Assert.IsTrue(person.IsOfType<Employee>());
var employee = person.AsOfType<Employee>();
Assert.IsNotNull(employee);
}
}
And the exception thrown now when running the unit test is:
Test method MainSolution.Data.Tests.EntityProxyTests.TestEntityProxyCastTo threw exception:
System.InvalidOperationException: Late bound operations cannot be performed on types or methods for which ContainsGenericParameters is true.
So this still appears to be some Reflection.Emit error, which is happening when NHibernate tries to generate the proxy. It seems clear that the way NHibernate is now generating its proxy is incompatible with the way we coded our EntityBase class. It used to work fine, when we were using the NHibernate.ByteCode.Castle.dll to generate the proxy, but it's obviously not happy with the type constraints on these methods.
Now, I've seen posts like this ( Nhibernate: Get real entity class instead of proxied class ) which suggest that we should just "Unproxy" the class to get the underlying "real" object. But that would mean changing the signature of these methods (perhaps), breaking all the calls to the "CastTo" and "AsOfType" methods etc. As I understand it, I'd have to get a UnitOfWork, get the current session from that, then do the "Unproxy" thing to get the underlying object, whereas with the current code, all we had to do was essentially return "this as T" and it would work. I thought maybe I could get the current session in the calling code, then pass it into some method on the EntityBase, but that seems ugly and a lot of overhead for doing something that seems like it ought to be simpler.
So the questions are: a) what am I doing wrong, b) how can I do it correctly given the 3.3. version of NHibernate, and c) is there a way to preserve the existing signature of the "CastTo" and "AsOfType" methods on my EntityBase class, while still getting NHibernate to generate its proxies correctly without complaining about the type constraints on those methods?
Any help appreciated, many thanks.
There are JIRA issues for it:
https://nhibernate.jira.com/browse/NH-2726
https://nhibernate.jira.com/browse/NH-2819
And there is even an pull request, sadly it hasn't been pulled yet:
https://github.com/nhibernate/nhibernate-core/pull/129
Edit: The pull request was pulled, so this specific issue is fixed. But there is another problem that also affects the .NET 2.0 runtime: https://nhibernate.jira.com/browse/NH-3244
But your code that uses just "Entity" as a constraint should work now.
I was not able to reference a specific class method using the doxygen #see command.
Suppose I have a class Server with a method start like below
#interface Server : NSObject
- (void) start:(NSInteger) mask;
#end
And suppose I have another class that has an object of Server.
#interface RandomNumberGeneration
/// How can I reference the method start from
/// class server using the command #see
/// #see ????
+ (NSInteger) generate;
#end
So, is there a way to reference the method start of class Server?
Copied from here
#see text | URL | classname | classname#methodname Use this to tag to
refer the reader to some other source of related information.
So I guess it should be:
/// #see Server#start:
See the doxygen manual page Automatic link generation for more information on referencing classes and functions. In particular see the section "Links to Functions".
Typically, I use the function refernce pattern
<className>::<functionName>
So in your case, I would use
/// \see Server::start
However, from the doxygen manual
For JavaDoc compatibility a # may be used instead of a :: in the patterns above
as stated in #PeterG.'s answer.
For completeness, note that if you a reference a member in the same class
In the documentation of a class containing a member foo, a reference to a global variable is made using ::foo, whereas #foo will link to the member.
I have an enum that I use for processing logic flags and I would like to expose the processing logic through a WCF service to a Silverlight client.
First problem is that if I use Option1 | Option2 (bit flags) the serializer has a problem as the sum of the two options do not equate to an enumerable option (as should be). I can overcome this by using an int as the parameter. This however gets met to my second problem: my enum is not included in the service reference as it is not a member of any type (DataContract).
I can overcome my second problem with a linked file but would prefer not to, or by creating a dummy method that returns the enum type, also not great.
Is there a simple way of desrializing the odd number, or injecting the enum type into the service reference? Or a better option all together?
For this you should use:
[DataContract(Name = "CarCondition")]
public enum CarConditionEnum
{
[EnumMember]
New,
[EnumMember]
Used,
[EnumMember]
Rental,
Broken,
Stolen
}
You can get more details here: MSDN.
I have just found a enum friend called [Flags] which allows me to use the enum as a parameter value and bit flags are deserialized correctly...
In my Google Web Toolkit project, I got the following error:
com.google.gwt.user.client.rpc.SerializationException: Type ‘your.class.Type’ was not included in the set of types which can be serialized by this SerializationPolicy or its Class object could not be loaded. For security purposes, this type will not be serialized.
What are the possible causes of this error?
GWT keeps track of a set of types which can be serialized and sent to the client. your.class.Type apparently was not on this list. Lists like this are stored in .gwt.rpc files. These lists are generated, so editing these lists is probably useless. How these lists are generated is a bit unclear, but you can try the following things:
Make sure your.class.Type implements java.io.Serializable
Make sure your.class.Type has a public no-args constructor
Make sure the members of your.class.Type do the same
Check if your program does not contain collections of a non-serializable type, e.g. ArrayList<Object>. If such a collection contains your.class.Type and is serialized, this error will occur.
Make your.class.Type implement IsSerializable. This marker interface was specifically meant for classes that should be sent to the client. This didn't work for me, but my class also implemented Serializable, so maybe both interfaces don't work well together.
Another option is to create a dummy class with your.class.Type as a member, and add a method to your RPC interface that gets and returns the dummy. This forces the GWT compiler to add the dummy class and its members to the serialization whitelist.
I'll also add that if you want to use a nested class, use a static member class.
I.e.,
public class Pojo {
public static class Insider {
}
}
Nonstatic member classes get the SerializationException in GWT 2.4
I had the same issue in a RemoteService like this
public List<X> getX(...);
where X is an interface. The only implementation did conform to the rules, i.e. implements Serializable or IsSerializable, has a default constructor, and all its (non-transient and non-final) fields follow those rules as well.
But I kept getting that SerializationException until I changed the result type from List to X[], so
public X[] getX(...);
worked. Interestingly, the only argument being a List, Y being an interface, was no problem at all...
I have run into this problem, and if you per chance are using JPA or Hibernate, this can be a result of trying to return the query object and not creating a new object and copying your relavant fields into that new object. Check the following out, which I saw in a google group.
#SuppressWarnings("unchecked")
public static List<Article> getForUser(User user)
{
List<Article> articles = null;
PersistenceManager pm = PMF.get().getPersistenceManager();
try
{
Query query = pm.newQuery(Article.class);
query.setFilter("email == emailParam");
query.setOrdering("timeStamp desc");
query.declareParameters("String emailParam");
List<Article> results = (List<Article>) query.execute(user.getEmail
());
articles = new ArrayList<Article>();
for (Article a : results)
{
a.getEmail();
articles.add(a);
}
}
finally
{
pm.close();
}
return articles;
}
this helped me out a lot, hopefully it points others in the right direction.
Looks like this question is very similar to what IsSerializable or not in GWT?, see more links to related documentation there.
When your class has JDO annotations, then this fixed it for me (in addition to the points in bspoel's answer) : https://stackoverflow.com/a/4826778/1099376
I am getting the error below when I call my WCF service. What am I missing here?
'System.String[]' with data contract name
'ArrayOfstring:http://schemas.microsoft.com/2003/10/Serialization/Arrays'
is not expected. Add any types not known statically to the list of known
types - for example, by using the KnownTypeAttribute attribute or by adding
them to the list of known types passed to DataContractSerializer.'. Please
see InnerException for more details.
{"There was an error while trying to serialize parameter
http://tempuri.org/:myEntity. The InnerException message was
'Type 'System.String[]' with data contract name
'ArrayOfstring:http://schemas.microsoft.com/2003/10/Serialization/Arrays'
is not expected. Add any types not known statically to the list of known
types - for example, by using the KnownTypeAttribute attribute or by adding
them to the list of known types passed to DataContractSerializer.'.
Please see InnerException for more details."}
From what I gather, you have a WCF function that has a parameter named 'myEntity'. I'm assuming that the type of myEntity is a user-defined class and is adorned with the DataContract attribute, as it should be. I'm also assuming that the type of myEntity has a member field that is a string array. Let's assume that all of this is true (again, it'd be really helpful if you could post your code).
Ordinarily, string arrays, i.e., string[], will serialize just fine. But, in some cases (see here and here), you may have to add it to the list of known types in order for WCF to serialize everything correctly.
To do this, add the following:
[DataContract]
[KnownType(typeof(string[]))]
public class YourClassNameHere
{
}
You haven't posted the code, so my answer is based on the assumption that you have a class myEntity which you are trying to serialize. Try using a KnownTypeAttribute for the class
e.g.
[KnownType(typeof(myEntity))]
You can refer to the following MSDN link:
KnownTypeAttribute
Yes. As explained in the previous post, The issue occurs if you pass an array of a Type(which is defined as a DataContract]). you will need to define the array of this class as a seperate type and mark it as data contract.
Wont Work`
[DataContract]
Public class ABC{
}
...
SendData(ABC[])
`
What will work:
Public class Data{ public ABC[] prop{get;set;}}
...
SendData(Data);
In my case, after adding [Serializable] attribute to the MyEntity class. And then the issue came with serialization of the roles string array.
[Serializable]
[KnownType(typeof(string[]))]
public class MyEntity
{
.........
public string roles[]
.........
}
[KnownType(typeof(string[]))] worked like magic!