locked
Class not registered exception when calling a WinRT compontent after migrating to VS2013.4

    Question

  • Hello, dear collegues.

    I have a HTML5 application, that contains a .winmd component used for file system operations (sqlite, zip archives and so on).

    After I upgraded to 2013.4 this component suddenly stopped working. Javascript still sees all the classes and function, but when I attempt to call any of them I get "WinRT: Class not registered" exception.

    Full VS reinstall didn't help. Neither did upgrading to community version. This behavior is reproduced on both desktop (8.1pro) and laptop (win8.1 single language)

    I spent 2 days trying to figure out what's wrong and I found that it fails as soon as component includes any asyncronous activity (like await/async or just Task.Delay(100))

    So my concern is... What's going on? Where I was wrong and what can I do?

    Right now installing 2015 preview. If I roll back to 2013.3 using system restore, project works fine, but VS gets in semi-broken state, and there is no link on a MS website to download previous version.

    If what I say doesn't make any sense, i may upload a file with a simpliest possible VS solution to reproduce a problem. But in brief it's as simple as:

    namespace NSUtil {

    class Test{

    public IAsyncOperation<string> DoSomething () { return Task<string>.Run(async () => {

    await Task.Delay(100); return ""; }).AsAsyncOperation(); }

    }

    }

    And in Javascript 

    NSUtil.Test.doSomething()
    throws "Class not registered" exception



    • Edited by itage Wednesday, November 19, 2014 2:36 PM added await
    Wednesday, November 19, 2014 2:36 PM

Answers

  • This one works without an issue for some... weird reason

    But further, when I start adding classes, i get the same issue over and over.

    At least now I see I'm not alone in this (got a couple comments here and there about same issue), so looking forward to some kind of solution. 

    For now -- i reinstalled windows and rolled back to 2013.3 (trial professional, cause I couldn't find any place to get express edition.

    So i got another sub-question -- where can I download 2013.3 express?

    Friday, November 21, 2014 12:59 PM
  • Hi itage,

    For your sub question, I'm not familiar with Visual Studio installation and related. I think as at VS general forum could be a better choice: https://social.msdn.microsoft.com/Forums/vstudio/en-US/home?forum=visualstudiogeneral

    Thanks for your understanding.

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.


    Monday, November 24, 2014 2:59 AM
    Moderator
  • Hi ,

    Thanks for reporting the issue.

    I just find a workaround for the "Class not registered" in other thread. Could you please have a look at it and see if you are running into same problem.

    If it doesn't work for you, could you please summary your problem again and provide a repro project with detailed steps for further investigation. Thanks for your cooperation!


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    Alan Yao
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Wednesday, December 3, 2014 1:53 AM
  • Hi Alan_Yao!

    The problem demonstrated in the thread you linked is, in a sense, related to the problem discussed in this thread: in both cases the problem originates from missing the ActivatableClass reference in AppxManifest.xml file.

    If you add a default constructor to the WinRT class, the reference gets generated as it should. But if you don't have it defined, the following structure in AppxManifest.xml will be missing the ActivatableClass line:

      <Extensions>
        <Extension Category="windows.activatableClass.inProcessServer">
          <InProcessServer>
            <ActivatableClass ActivatableClassId="MyNamespace.MyClass" ThreadingModel="both" />
          </InProcessServer>
        </Extension>
      </Extensions>

    But as said, this is just a temporary workaround, and hopefully the VS dev team will introduce a proper fix in the future.


    • Proposed as answer by jsunfutu Friday, December 5, 2014 9:30 AM
    • Edited by jsunfutu Friday, December 5, 2014 9:31 AM
    • Marked as answer by Jamles HezModerator Tuesday, December 16, 2014 8:58 AM
    Friday, December 5, 2014 9:30 AM

All replies

  • Hi itage,

    Thanks for your feedback, hears like something wrong with the update, and I tested the code you provided in Visual Studio 2013.3, works fine without any problem.

    I believe there might be something wrong with the Update 4, I will find a test machine to give a try and update you the results later.

    Thanks,

    James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Thursday, November 20, 2014 5:31 AM
    Moderator
  • Hi itage,

    Tested with following code and works perfectly in VS2013.4

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using Windows.Foundation;
    
    namespace NSUtil
    {
        public sealed class Test
        {
    
            public IAsyncOperation<string> DoSomething()
            {
                return Task<string>.Run(async () =>
                {
    
                    await Task.Delay(100);
                    return "";
                }).AsAsyncOperation();
            }
    
        }
    }
    

    and

        var t = NSUtil.Test();
        t.doSomething();

    Probably something wrong with your Visual Studio, please try to fix it :)

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Thursday, November 20, 2014 7:11 AM
    Moderator
  • I second his concern about things breaking in the update to VS2013.4 and getting a ClassNotRegisteredException during runtime (but the app compiles with no errors) with a Windows Phone project. In one of my apps (written in C#), I have a reference a winmd metafile written in C++ and attempt to call it within C#. A class used by the app in the C++ winmd metadata (which I am using to "scan" the phone's filesystem) references a C# class in a different winmd metafile. Upon debugging, it seems to break when I call the constructor for the C# class in a different winmd metafile as part of a function in a class in the C++ winmd metadata. Under VS2013.3, it worked without problems, but upon updating to VS2013.4, it does not work. I have tried removing the reference and re-adding it, but that does not work. I tried recreating the C++ winmd metadata and re-adding the references back, but that does not work either. If I can, I will try investigating further to see if I can get more specific than I already am.
    Thursday, November 20, 2014 3:36 PM
  • This one works without an issue for some... weird reason

    But further, when I start adding classes, i get the same issue over and over.

    At least now I see I'm not alone in this (got a couple comments here and there about same issue), so looking forward to some kind of solution. 

    For now -- i reinstalled windows and rolled back to 2013.3 (trial professional, cause I couldn't find any place to get express edition.

    So i got another sub-question -- where can I download 2013.3 express?

    Friday, November 21, 2014 12:59 PM
  • Hi itage,

    For your sub question, I'm not familiar with Visual Studio installation and related. I think as at VS general forum could be a better choice: https://social.msdn.microsoft.com/Forums/vstudio/en-US/home?forum=visualstudiogeneral

    Thanks for your understanding.

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.


    Monday, November 24, 2014 2:59 AM
    Moderator
  • Hi itage,

    I had the very same problem in a project I'm working on after installing VS2013.4, but managed to fix things by adding a default public constructor to the WinRT class. In your example case, that would be just:

    public Test() { }

    Also please note that the class should be sealed:

    public sealed class Test { ... }

    I hope this helps!

    Certainly feels like a bug in the latest VS update...



    • Proposed as answer by jsunfutu Wednesday, November 26, 2014 1:58 PM
    • Edited by jsunfutu Wednesday, November 26, 2014 2:05 PM add mention about sealed class
    Wednesday, November 26, 2014 1:55 PM
  • Yes, this is a solution, but it is only a temporary one (I still classify it as a bug). I have the default constructor in the class with the constructor that I get the ClassNotRegisteredException on when called marked as internal, not public, because I am only using the default constructor to initialize an "empty" singleton for that class. The only public constructor in the class in question is parameterized. Under Visual Studio 2013.3, marking the default constructor as internal, not public, worked correctly (as designed) with no issues. Under Visual Studio 2013.4, I get a ClassNotRegisteredException. I hope the dev team finds a fix for this problem soon.
    Wednesday, November 26, 2014 6:26 PM
  • Thanks a lot, jsunfutu.

    Sealing static classes wasn't an issue in 2013 (not mentioning class cannot be both public and sealed). 

    But anyway, it looks to me now that this problem occures as soon as I make something internal or protected. So this has something with visibility scopes (when i start playing with private/internal methods, this error occurs.

    Don't have specific information at this point, will try to dig further on weekend.

    Thursday, November 27, 2014 7:30 AM
  • Hi ,

    Thanks for reporting the issue.

    I just find a workaround for the "Class not registered" in other thread. Could you please have a look at it and see if you are running into same problem.

    If it doesn't work for you, could you please summary your problem again and provide a repro project with detailed steps for further investigation. Thanks for your cooperation!


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    Alan Yao
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Wednesday, December 3, 2014 1:53 AM
  • Hi Alan_Yao!

    The problem demonstrated in the thread you linked is, in a sense, related to the problem discussed in this thread: in both cases the problem originates from missing the ActivatableClass reference in AppxManifest.xml file.

    If you add a default constructor to the WinRT class, the reference gets generated as it should. But if you don't have it defined, the following structure in AppxManifest.xml will be missing the ActivatableClass line:

      <Extensions>
        <Extension Category="windows.activatableClass.inProcessServer">
          <InProcessServer>
            <ActivatableClass ActivatableClassId="MyNamespace.MyClass" ThreadingModel="both" />
          </InProcessServer>
        </Extension>
      </Extensions>

    But as said, this is just a temporary workaround, and hopefully the VS dev team will introduce a proper fix in the future.


    • Proposed as answer by jsunfutu Friday, December 5, 2014 9:30 AM
    • Edited by jsunfutu Friday, December 5, 2014 9:31 AM
    • Marked as answer by Jamles HezModerator Tuesday, December 16, 2014 8:58 AM
    Friday, December 5, 2014 9:30 AM