C# - Possible Windows 8 compiler bug?

Hey guys!

We’re currently going through the process of getting the latest version of PowerUI working fully with Windows Store but there’s been a snag; this particular error has happened a few times now and it’s really hard to pin down the actual cause.

So, the error that appears:
error: CS1027: Expected ‘#endif’ directive.

It seems pretty clear what the problem is - well, it’s not quite that simple! Here’s the code:

(For clarity, the error disappears when this block is removed - it’s not some other piece of code).

#if UNITY_METRO
bool isGeneric=type.GetTypeInfo().IsGenericType;
#else
bool isGeneric=type.IsGenericType;
#endif

The error still appears if the else is removed:

#if UNITY_METRO
bool isGeneric=type.GetTypeInfo().IsGenericType;
#endif

It also still appears if we make the code inside the block really simplistic:

#if UNITY_METRO
bool isGeneric=false;
#endif

Changing the definition used also makes no difference too:

#if NETFX_CORE
bool isGeneric=false;
#endif

Things get really odd when it’s put in another file though. Simply moving the above block of code to some other file and it compiles with no errors. However, it appears to be completely random which files preprocessing directives can and cannot be used in.

So my first suspicion was maybe something to do with the file encoding - e.g. the UTF8 BOM getting in the way. No dice there either unfortunately; it seems to be a semi-random compiler bug.

Has anybody else experienced this/ got any ideas?

Thanks! :slight_smile:

Are you sure it’s completely random.

Or maybe that the files it happens in have something going on in them that you just don’t notice.

For example I had a problem where I couldn’t add components to my gameobjects after they started supporting namespaces for it. The exception said that the filename did not match. But it didn’t effect all namespaced components. After some digging around… it was because I had optional parameters in those classes. I guess how unity implemented it, optional parameters break it.

Seemed random at first, but usually there’s a reason for it. No matter if that reason is weird.

Welcome to programming… where weird is the norm.

I’ve actually been programming for a very long time so I sure know how wierd it gets! :stuck_out_tongue: I was also one of the first to start developing with Unity too, but I’m still pretty new to W8.

I’ve been trying to pin down what the actual cause is but there has been no patterns so far unfortunately.

Edit: I had a suspicion that maybe it was related to static classes within a namespace; that appears to be common to all of the files that have problems with preprocessing directives. Oddly though, moving the files which don’t compile to another empty project makes them compile.

It seems like there’s an open-ended directive somewhere but just adding another #endif at the top of the file doesn’t seem to work either. I’ll keep digging!

So it seems I’ve found a way around it!

  • Create a new file outside of Unity (in your computers file browser) in your project
  • Copy the code from the original and into that one
  • Delete the original

Presumably it’s related to file permissions on Windows 8 - maybe some particular permissions prevent preprocessor directives from working properly in some specific case.