none
genasm error message when adding DesignTimeAttributes.xmta to my project

    Question

  • This is weird. I have a Smart Device C# library that builds perfectly. When I add a DesignTimeAttributes.xmta to it and rebuild it I got the following error message:

    genasm.exe(1) : error There was an error finalizing type . Type 'MyNameSpace.MyClass, MyLibrary, Version=9.2.0.0, Culture=neutral, PublicKeyToken=null' was loaded in the ReflectionOnly context but the AssemblyBuilder was not created as AssemblyBuilderAccess.ReflectionOnly.

    My Namespace is MyNameSpace. My library is called MyLibrary.

    I have tried to reproduce it on a small project and I can't. I will keep trying to see if I can narrow it down.

    Thanks in advance for helping.
    Tuesday, September 27, 2005 12:00 AM

Answers

  • Hi Partho,

    This is great news relatively speaking... Thanks for digging this issue.

    Using the steps you described, I was able to reproduce the issue.

    I don't have a Device Console Application, I have a Device Library. But this apart, yes, I have one public class that derives from ReadOnlyCollection<T>.

    As for the workaround, this is not applicable. I need a read only collection. Making it internal or private is not going to solve my issue. It seems that I have to implement my own read only collection.

    I have also found a seconfd way to reproduce it:
    1. Create a new Device Console Application project
    2. In Program.cs, create a new public class Foo
    3. In the Foo class add a public method that returns List<Component>
    3. Add a designtime attributes file to the project (could be a the default template)
    4. Build.
     

    I have tried by making the public method returns IList<Component>, I got the same issue.

    This looks like a serious issue for me. My goal is to provide a library and I can't use anywhere generics in my public class, or my public methods or my public properties.
     
    Bottom line, I can't release a library that uses generics despite the fact that generics are sold by Microsoft as performance improvements.

    Could you confirm this is going to be fixed in the final release of VS2005?

    Thanks
    Friday, October 07, 2005 3:36 PM
  • I forgot to follow up on this issue.

    Visual Studio 2005 SP1 did fix the issue.

     

    Thanks to everyone at MS.

     

    Fred

    Thursday, May 17, 2007 6:13 AM

All replies

  • Hi Frederic - thanks for reporting this issue.

    This error definitely seems possible from the genasm.exe sources. However we are unable to repro this issue in our labs.

    Can you send me the project and the xmta file that you used to successfully reproduce this error?

    Thanks...
    Wednesday, September 28, 2005 9:14 AM
  • Hi Frederic - we have been able to repro this problem.

    This repro for this issue is simple and as follows:
    1. Create a new Device Console Application project
    2. In Program.cs, create a new public class deriving from List<Component>
    3. Add a designtime attributes file to the project (could be a the default template)
    4. Build.

    Can you please confirm that you indeed have a public class that derived from an instantiated generic type like the above?

    Unfortunately there the only workaround for this issue is to make the class deriving from the instantiated generic type non-public e.g. private or internal.

    Please let me know if this fixes the issue for you. If not I will help you find ways of working around it.

    Thanks...

    Friday, October 07, 2005 6:35 AM
  • Hi Partho,

    This is great news relatively speaking... Thanks for digging this issue.

    Using the steps you described, I was able to reproduce the issue.

    I don't have a Device Console Application, I have a Device Library. But this apart, yes, I have one public class that derives from ReadOnlyCollection<T>.

    As for the workaround, this is not applicable. I need a read only collection. Making it internal or private is not going to solve my issue. It seems that I have to implement my own read only collection.

    I have also found a seconfd way to reproduce it:
    1. Create a new Device Console Application project
    2. In Program.cs, create a new public class Foo
    3. In the Foo class add a public method that returns List<Component>
    3. Add a designtime attributes file to the project (could be a the default template)
    4. Build.
     

    I have tried by making the public method returns IList<Component>, I got the same issue.

    This looks like a serious issue for me. My goal is to provide a library and I can't use anywhere generics in my public class, or my public methods or my public properties.
     
    Bottom line, I can't release a library that uses generics despite the fact that generics are sold by Microsoft as performance improvements.

    Could you confirm this is going to be fixed in the final release of VS2005?

    Thanks
    Friday, October 07, 2005 3:36 PM
  • Hi Fred - I am sorry that this did not make it into Whidbey RTM.

    This is definitely a severe issue and we are considering this for Whidbey SP1.

    Thanks...
    Tuesday, December 06, 2005 11:44 AM
  • Consider splitting your code into two assemblies. Move all of the generics use to the single assembly. PLace your control and XMTA files into the other. In many cases such refactoring is possible, but of course there are exceptions.
    Friday, December 09, 2005 9:28 AM
  • Any news on a possible release date for a fix / SP1?
     
    VS 05 is wonderful - well done, but not being able to use generics in controls with designer support is a real pain!
    Thursday, February 09, 2006 6:46 AM
  • thx Alex, it was helpfull
    Monday, February 20, 2006 3:17 PM
  • I have one particularly painful case where it would be great to be able to use generics.
     
    I've written a base list control, with designer support, in which I was intending on having a generic ListItem class parameter, allowing easy creation of custom list controls with a new ListItem type that can be created in the designer (collection editor). This allows all the scrolling / sizing / boilerplate code to be left in the list class, and the funky painting code / custom properties to be placed in ListItem implementations - with designer support.
     
    The problem is because I need my ListItem collection to be strongly typed (ie of the generic ListItem parameter, not of an interface or base type) so that the designer collection editor knows what type of ListItem to create at design time in the collection editor.
     
    Of course as soon I add the generic ListItem class parameter or collection property I can no longer compile. Does anyone know of another way to achieve this end? Is there any way to tell the collection editor to populate the collection with a specific class - not the reflected property type?
    Tuesday, February 21, 2006 5:09 AM
  • We had the same problem and we dont want the users of our control to work with specific classes made up from generic ones. To made the genasm work you can simply generate the XML using the Class Diagram as you usually does, put that on a new project, generate ClassDiagram1.PocketPC.asmmeta.dll and rename it to NameOfYourAssembly.PocketPC.asmmeta.dll.

     

     

    That should work. Let me know if you need the code.

     

    Thursday, May 11, 2006 6:30 PM
  • I've a similar problem, the error messagem is:

    "genasm.exe(1) : error There was an error initializing MyNamespace.MyControl.  Type 'System.Data.SqlServerCe.SqlCeConnection, System.Data.SqlServerCe, Version=3.0.3600.0, Culture=neutral, PublicKeyToken=3be235df1c8d2ad3, Retargetable=Yes' was loaded in the ReflectionOnly context but the AssemblyBuilder was not created as AssemblyBuilderAccess.ReflectionOnly."

    What does it mean? How can I fix that?
    Monday, May 29, 2006 10:19 PM
  • Just hit this one today.

    If I use protected List<> I get the "finalizing type" error message variant; If I use public List<> I get the "initializing" form of the message.

    Do we really have to wait until Q3 for SP1? Will it have a fix for this?

    Wednesday, June 07, 2006 8:39 PM
  • The problem is, you cant use generics and genasm.

    The workaround is, generate the DesignTimeAttributes.xmta using the Class Diagram as you would usually do, then, move that file to a new project and compile it, then rename it to [YourAssemblyName].PocketPC.asmmeta.dll and copy that to YourAssembly directory.

    If you want to automate that, just leave the DesignTimeAttributes file and set the CustomTool property to some dummy builder which does nothing and from the new project simply use the add existing file and a reference (link) to the original file, that way you can modify your class diagram directly from your original project and keep everything in sync. The final step is to use a build event and copy and rename the .asmmeta.dll to the proper name and folder.

     

    I hope this work for you, it have worked for us.

    Thursday, June 08, 2006 2:32 PM
  • Hi,

    Is it possible to have a patch released before the release of the service pack. When the ASP.net team did the new web project they required a VS 2005 patch to be installed before installing the project templates.

    This is kind of a major issue which I reported during the Beta. I dont understand how this problem was not detected during internal testing and why it was not fixed before launch.

    Kind Regards,

    Tarek

     

    Sunday, July 02, 2006 8:34 AM
  • It would be great to have that patch.

    Sunday, July 02, 2006 5:27 PM
  • mamadero

    Can you post a little more about your work-around?

    Which "dummy custom tool" did you use to stop VS trying to compile and include the DesignTimeAttributes.xmta in the original project as everything that I have tried results in an error.

    I have created a new project and added the original DesignTimeAttributes.xmta to the new project as a link. If I then exclude it from the original project then everything compiles and works fine, unfortunately however this means that the .xmta file is not included in any source control (links are not included as they are expected to be saved by the original project, but it is now excluded).

     

    Thanks

    Monday, July 03, 2006 10:47 AM
  • Sorry, it the custom tool stuff didnt worked as expected. 

    What I tried was, extending 

    BaseCodeGeneratorWithSite or

    IVsSingleFileGenerator

    as specified in http://www.gotdotnet.com/Community/UserSamples/Details.aspx?SampleGuid=4AA14341-24D5-45AB-AB18-B72351D0371C,

    to built a dummy Custom Tool, register that for COM and then change the property CustomTool of the XMTA file.

    Here's the code:

    using System;

    using System.Collections.Generic;

    using System.Text;

    using CustomToolGenerator;

    using System.Runtime.InteropServices;

    using Microsoft.Win32;

    namespace Intecmex.CustomToolGenerator

    {

    [Guid("D72D048D-FA0C-44f5-8287-B02B5CFDEB0F")]

    [ComVisible(true)]

    public class DummyCodeGenerator : IVsSingleFileGenerator//BaseCodeGeneratorWithSite

    {

    private static Guid csharpCategory = new Guid("{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}");

    private static Guid vbCategory = new Guid("{164B10B9-B200-11D0-8C61-00A0C91E29D5}");

    private static Guid customToolGuid = new Guid("{D72D048D-FA0C-44f5-8287-B02B5CFDEB0F}");

    private const string customToolName = "DummyCodeGenerator";

    private const string customToolDescripcion = "Does nothing, just fool the IDE to dont use a different tool";

    private const string keyFormat = @"SOFTWARE\Microsoft\VisualStudio\{0}\Generators\{1}\{2}";

    protected static void Register(Version vsVersion, Guid categoryGuid)

    {

    using(RegistryKey key = Registry.LocalMachine.CreateSubKey(String.Format(keyFormat,

    vsVersion,categoryGuid.ToString("B"),customToolName)))

    {

    key.SetValue("", customToolDescripcion);

    key.SetValue("CLSID",customToolGuid.ToString("B"));

    key.SetValue("GenerateDesignTimeSource",1);

    }

    }

    protected static void UnRegister(Version vsVersion,Guid categoryGuid)

    {

    Registry.LocalMachine.DeleteSubKey(String.Format(keyFormat,

    vsVersion,categoryGuid.ToString("B"),customToolName),false);

    }

    [ComRegisterFunction]

    public static void RegisterClass(Type t)

    {

    Register(new Version(8,0),csharpCategory);

    Register(new Version(8,0),vbCategory);

    }

    [ComUnregisterFunction]

    public static void UnRegisterClass(Type t)

    {

    UnRegister(new Version(8,0),csharpCategory);

    UnRegister(new Version(8,0),vbCategory);

    }

    //protected override byte[] GenerateCode(string inputFileName, string inputFileContent)

    //{

    // return null;

    //}

    #region IVsSingleFileGenerator Members

    public string GetDefaultExtension()

    {

    return "XMTA";

    }

    public void Generate(string wszInputFilePath, string bstrInputFileContents, string wszDefaultNamespace, out IntPtr rgbOutputFileContents, out int pcbOutput, IVsGeneratorProgress pGenerateProgress)

    {

    rgbOutputFileContents = IntPtr.Zero;

    pcbOutput = 0;

    return;

    }

    #endregion

    }

    }

     

     

    Ok. So the thing is, VS was supposed to give the control to my IVsSingleFileGenerator, but didnt get up to that step for the same Genasm error. All this CustomTool design has been on the IDE since the 7.0 version. I tought the problem was the CustomTool for XMTA so I decided to create my own just to find out the problem is before that layer. So this means also .xsd (for the Datasets), .rpt and all the other custom tools will have the same problem. Hope this patch come soon.

     

    Well so the workaroun is:

    (I can e-mail you a solution with the two projects needed)

    You have your controls project with your .cs file and generate the custom attributes from there.

    You create a new project with and add as existing file (as link) the XMTA file.

    Then before compiling you will have to exclude the XMTA file from project 1 and the .asmmeta will be placed in the seconds project bin directory.

    You will probably want to do a Build Action to copy the file from projects two output folder to project 1 output folder.

    I know it's a pain in the *** to be excluding and reincluding (you have to add it again if you want to see or change the Custom Attributes of your properties from the Class Designer), but you still have source control for your XMTA file. If you reinclude your XMTA each time you have to modify an attribute, the file will automatically be Checked, after that you could exclude the xmta, compile both projects and then do a check in and the link will detected the checked out file and add that to the list of pending changes of the solution.... Thats the way it has been working for us that way, we tought about the possibility of doint the Cusom Tool and doesnt work... sorry for posting that out before trying it.

     

    Hope this helps.

    Monday, July 03, 2006 4:36 PM
  • I have a related but somewhat different problem with the inclusion of the XMTA file. We included this file to be able to use the GUI designer to create custom controls. The project is a C#, CF 2.0, SmartDevice for Windows CE 5.0.

    Anyway, I don't have any trouble compiling the project until I use delayed signing. Removing the XMTA file allows me to compile and delay sign with no apparent effect. However, it is a major pain to remove this file each time a build is required.

    Is my situation related to those above or have I tapped a new compiler issue?

    Thanks,
    Drew

    Saturday, July 22, 2006 3:57 PM
  • Hi,

     I wont to make this problem as you described.

    But - it dosen't work for me.

    I explain.

    1. I added new project to my solution ( namespace: Sente.NetCL, main component library projet in solution: sente.netcl.cf): sente.netcl.cf.xmta

    2. I added the sente.netcl.cf.xmta file to sente.netcl.cf project, an then exceluded from project

    3. I included (linked) sente.netcl.cf.xmta file to sente.netcl.cf.xmta project (this new project)

    4. After buiding, I get sentenetcl.cf.xmta.Packet.asmmet.dll

    5. I renamed this into sente.netcl.cf.Packet.asmmet.dll

    And ...

    Designer still dosen't see the atributes parameters.

    If I added simple control descendad TextBox to sente.netcl.cf.xmta project with one property "MyProperty" (completly different namespace), and added property description to the same file, and used the component from sente.netcl.cf.xmta project - all works great !

     

    Why ?

    That, what doesn't work, is moment, when I must rename *.asmmet.dll file. Designer don't see proerty description if it is in renamed file.

    What I do wrong ?

    Regards

      Qubeczek

    Tuesday, October 31, 2006 4:59 PM
  • I forgot to follow up on this issue.

    Visual Studio 2005 SP1 did fix the issue.

     

    Thanks to everyone at MS.

     

    Fred

    Thursday, May 17, 2007 6:13 AM
  • Sorry for ripping up an old thread, but the error has popped up again in Visual Studio 8 Beta 2 with Sql Ce 3.5.

    I had to delete the xmta file to be able to rebuild.

     

    Here is the error I got:

     

    Error 1 genasm.exe(1) : error There was an error initializing MyProject.SqlMgr.rsExecuteQuery. 

     

    And here is the code in SqlMgr:

     

    Private Shared cmd As New SqlCeCommand()

    Public Shared Function rsExecuteQuery(ByRef cn As SqlCeConnection, ByVal strSql As String, Optional ByVal RsOptions As ResultSetOptions = ResultSetOptions.Scrollable Or ResultSetOptions.Updatable) As SqlCeResultSet

    cmd.CommandText = strSql

    cmd.Connection = cn

    Return cmd.ExecuteResultSet(RsOptions)

    End Function

     

    I don't use generics but I suspect that the SqlCeResult is.

     

     

     

    Friday, August 03, 2007 7:03 AM
  • I'd just like to echo that we're having a lot of problems with this (when using projects configured for Delayed Signing) as well.  It makes our company's release process a pain as right now for a workaround we have to manually edit the .csproj files with Notepad and remove the references to the .xmta before building release versions of our software (Note: this is VS2005 Team Suite edition).

    Just thought I'd bump the request for (re)fixing this problem :-)
    Thanks!
    Friday, August 24, 2007 7:02 PM
  •  

    I was able to work around this by specifying a build action (content I think) for the xmta file.

     

    Friday, August 24, 2007 7:37 PM
  • Thanks for the tip, this worked for me as well.

    Friday, September 14, 2007 5:45 PM
  • Hi,

     

    same problem here - with VS2008 RTM.

    BUT: the fix is to set the build action of the xmta file to "Content" - it works!

    Tuesday, January 15, 2008 7:42 AM
  • Hi,

     

    I seem to have a similar problem in VS2008 also. Setting the xmta file to content prevents the creation of the asmeta file. How did you get around that.

     

    Kind Regards,

    Tarek

     

    Wednesday, February 13, 2008 11:23 AM
  • Seems there is still an issue.

    When I give an List in the constructor of an object with the ref keyword I get this error.
    eg.

    void ctor( ref List<myobject> objects){

    }

    wil generate the same error.

    Good thing the list is passed by ref by default Stick out tongue
    Tuesday, June 03, 2008 2:52 PM
  • There is a work around .

    Right click on the DesignTimeAttributes.xmta from solution explorer. select properties.

    Set the BuildAction from "None" to "Content" and build.

    it will definitely work.

    Wednesday, July 23, 2008 6:53 AM
  • Problem is back in VS 2008 when upgrading a project from NETCF 2.0 to NETCF 3.5.  Setting BuildAction of the .xmta file to Content lets the project build but prevents generation of the .asmmeta.dll file for the project as thaoula

    mentioned.  Has anyone found a way around this yet?  Creating a new NETCF 3.5 project from scratch doesn't seem to have the problem, only when the target framework is upgraded from 2.0.

    Tuesday, July 29, 2008 11:21 PM
  • If anyone cares to reproduce the problem:
    <1>create a new smart device project that targets NETCF 3.5.
    <2>Add reference to System.Data and System.Data.SqlServerCe to the project.
    <3>Create a new class.
    <4>Add a method that has a System.Data.SqlServerCe type (SqlCeConnect, SqlCEParameter, etc) in its parameter list or as its return type.
    <5>Right click the Form1.vb and select "View class diagram"
    <6>Right click the diagram element for Form1 and select Properties.
    <7>Add "DesktopCompatible(true)" as custom attribute.  (This causes the DesigntimeAttributes.xtma file to be generated.)
    <8>Try to build the project, you will get the genasm error.
    <9>Now try changing the System.Data.SqlServerCe type to something not from that namespace, build, and it will work.

    Makes no sense at all.  MS's workaround here: https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=339763
    does not work unless you want to use only 2.0 libraries (in which case why not build a project that targets NETCF 2.0).
    Wednesday, July 30, 2008 11:15 PM
  • Had same problem here - with VS2008 .

    BUT: the fix is to set the build action of the xmta file to "Content" - it works!

    Wednesday, August 05, 2009 6:21 AM
  • Hi, All.

    I'm also having this issue when creating a control library to .NET CF with VS2008, with a little twist in the error message I've got:

      genasm.exe(1) : 
         There was an error finalizing type . 
         Object reference not set to an instance of an object.


    Changing the build action to Content does not help beacuse the BuildAsmeta Target expects that the XMTA file to be in the None category, and so it doesn't generate the necessary assembly.

    Running the genasm by hand also gives the same error.

    The only workaround that I was able to was to move the classes that inherits from and generic colection to another assembly and keep isolated the controls that requires design time attibutes. Not the best solution but it works.

    It doesn't matter if it's a 2.0 or a 3.5 Target, as I built my project aiming the 3.5 from start.

    Even after five years MS didn't solve this issue... it's amazing.

    Has anyone reported this issue on Microsoft Connect?


    PJ on Development
    Monday, February 15, 2010 3:55 PM
  • The same effect cause delete of .xmta file, but settings into .xmta not applyed
    Friday, October 08, 2010 5:18 PM
  • Hello, another workaround for this problem is

    ->Create a new project 

    ->remove all .cs file (empty project)

    ->Add the .xmta file with all properties description in this empty project, with Build Action property in CONTENT

    ->Compile the empty project with just xmta file, after that will be generated two files "EmptyProjectName.dll" and "EmptyProjectName.PocketPC.asmmeta.dll"

    ->Rename the EmptyProjectName.PocketPC.asmmeta.dll file to your REAL PROJECT NAME (RealProjectName.PocketPC.asmmeta.dll" and copy it to your RealProjectAssembly output directory.

    This steps is another workaround to this Visual Studio problem. Just to remember, this problem is incompatibillity between genasm.exe and generics or collections returns.


    mauricio_scoelho1

    Wednesday, October 24, 2012 10:20 PM