none
How do I build and ignore errors? RRS feed

  • Question

  • Hey there,

    I'm trying to build my game and I keep getting the error Error.

    "The non-generic type 'example<T>' cannot be used with type arguments"

    But I know that it should still run. Is there anyway to have visual studio 2012 ignore errors and build it anyways?

    -Thanks in advance

    Monday, December 3, 2012 10:53 PM

Answers

  • Your error is likely not in the section of code you posted.  For example. The following compiles (with warnings about unused fields.)

    using System;
    using System.Collections.Generic;
    using System.Collections.ObjectModel;
    
    public interface IGameObject
    {
    }
    
    public class SomethingeElse<T>
    {
    }
    
    public sealed class Example<T> : List<T> where T : IGameObject
    {
        private SomethingeElse<T> mComparer;
        private object mLock;
        private int mMaxCapacity;
        private bool mNeedSort;
        private List<T> mPendingAdditions;
        private List<T> mPendingRemovals;
        private int mSortCursor;
        private List<T> mStaticBuffer;
        private bool mWantSort;
        private int mWorkChunkCursor;
    }

    Is it possible that it's the extra 'e' in SomethingeElse that is giving you trouble?

    • Proposed as answer by Jason Dot Wang Friday, December 7, 2012 4:15 AM
    • Marked as answer by Jason Dot Wang Thursday, December 13, 2012 9:45 AM
    Thursday, December 6, 2012 1:39 PM

All replies

  • Solve your problem - go to that error and fix it or post relevant code...

    Classified SR-2 | 2x Xeon W5580 - 3.20 GHz | 12x 2GB Kingston KHX2000C9D3T1K3/6GX | 2x MARS II/2DIS/3GD5 | SAMSUNG 830 MZ-7PC512D/AM 2.5" 512GB SATA III MLC | 4x Spinpoint F3EG HD503HI 500GB 5400 16MB SATA 3.0Gb/s |

    Monday, December 3, 2012 11:00 PM
  • It gives me the option to "Generate class 'example'"

    If that helps.

    Monday, December 3, 2012 11:05 PM
  • Given this error:
    "The non-generic type 'example<T>' cannot be used with type arguments"

    try replacing example<T> with example in your code.


    "Premature optimization is the root of all evil." - Knuth

    If I provoked thought, please click the green arrow

    If I provoked Aha! please click Propose as Answer

    Monday, December 3, 2012 11:06 PM
  • Ok when I do that I get errors saying other things aren't specified.

    I'm a bit of a noob. So excuse my lack of information when I say:

    When I remove the <T> The color of the example changes from light blue to black.


    Monday, December 3, 2012 11:15 PM
  • It's difficult no answer the question without seeing the actual code.

     

    Noam B.



    Do not Forget to Vote as Answer/Helpful, please. It encourages us to help you...

    Tuesday, December 4, 2012 12:02 PM
  • I apologize for not being able to show you my code.but, can you explain what the <T> argument is? and what other options there are in place of <T>?

    Like I said I'm at a pretty basic level and most of my code is copied from examples and tutorials.

    Tuesday, December 4, 2012 5:05 PM
  • <T> T here indicate the generic type. And Error is saying you have example class which is not Generic and you are trying to generic declaration somewhere. Without seeing you code it's difficult where exactly it's failing. Also, C# 4.0 has something called dynamic keyword which can be used in your case.

    Dhananjay(Tech Lead). Please mark the reply as answers if it helps.

    Tuesday, December 4, 2012 5:39 PM
  • I wonder if you're encountering a situation such as this.  Excerpted from CS0308 docs.


    The following example also generates CS0308. To resolve the error, use the directive "using System.Collections.Generic."

    // CS0308b.cs
    // compile with: /t:library
    using System.Collections;
    // To resolve, uncomment the following line:
    // using System.Collections.Generic;
    public class MyStack<T>
    {
        // Store the elements of the stack:
        private T[] items = new T[100];
        private int stack_counter = 0;
    
        // Define the iterator block:
        public IEnumerator<T> GetEnumerator()   // CS0308
        {
            for (int i = stack_counter - 1 ; i >= 0; i--)
            yield return items[i];
        }
    }
    

    • Edited by Wyck Tuesday, December 4, 2012 7:02 PM Oops. Fixed bogus code formatting.
    Tuesday, December 4, 2012 7:01 PM
  • Replace the "T" in your code with object you are using.

    example:

    List<T> list1 = new List<T>();
    
    
    //becomes
    List<String> list2 = new List<String>();
    
    
    //or
    Dictionary<T,T> dict1 = new Dictionary<T,T>();
    
    //becomes
    Dictionary<Object,Double> dict2 = new Dictionary<Object,Double>();

    Thats the best way I can explain it without seeing your code.

    Tuesday, December 4, 2012 8:55 PM
  • Sorry I feel bad not being helpful. Here is the relevant section of my code.

    I already had the "using systems.collections.generic;" before it was suggested by Wyck.

        using System;
        using System.Collections.Generic;
        using System.Collections.ObjectModel;
    
        public sealed class Example<T> : List<T> where T: IGameObject
        {
            private SomethingeElse<T> mComparer;
            private object mLock;
            private int mMaxCapacity;
            private bool mNeedSort;
            private List<T> mPendingAdditions;
            private List<T> mPendingRemovals;
            private int mSortCursor;
            private List<T> mStaticBuffer;
            private bool mWantSort;
            private int mWorkChunkCursor;

    I figured setting "where T: IGameObject" would do the trick. If I take that out will i have to change T to IGameObject at every instance?



    • Edited by InherentCoder Tuesday, December 4, 2012 11:16 PM added some explanations at the bottom.
    Tuesday, December 4, 2012 11:12 PM
  • Is this is for UnityEngine..? What you trying to do..?

    Classified SR-2 | 2x Xeon W5580 - 3.20 GHz | 12x 2GB Kingston KHX2000C9D3T1K3/6GX | 2x MARS II/2DIS/3GD5 | SAMSUNG 830 MZ-7PC512D/AM 2.5" 512GB SATA III MLC | 4x Spinpoint F3EG HD503HI 500GB 5400 16MB SATA 3.0Gb/s |


    • Edited by VendorX Tuesday, December 4, 2012 11:38 PM
    Tuesday, December 4, 2012 11:36 PM
  • I'm not using Unity, I am using Visual Studio 2012. I thought the code would work across platforms.
    Tuesday, December 4, 2012 11:41 PM
  • ...probably you should read this anyway:

    How to: Create an Iterator Block for a Generic List

    BTW: Which platforms..?


    Classified SR-2 | 2x Xeon W5580 - 3.20 GHz | 12x 2GB Kingston KHX2000C9D3T1K3/6GX | 2x MARS II/2DIS/3GD5 | SAMSUNG 830 MZ-7PC512D/AM 2.5" 512GB SATA III MLC | 4x Spinpoint F3EG HD503HI 500GB 5400 16MB SATA 3.0Gb/s |


    • Edited by VendorX Wednesday, December 5, 2012 12:27 AM
    Tuesday, December 4, 2012 11:50 PM
  • Why don't you just replace <T> with <IGameObject>, rather than trying to set T.

    that would probably fix your issue.

    (its easy to do, just ctrl+f, and find/replace <T> with <IGameObject>)


    • Edited by holtam07 Wednesday, December 5, 2012 2:53 PM
    Wednesday, December 5, 2012 2:53 PM
  • I tried that but I got some other weird errors.

    @VendorX I'm reading away :)

    Wednesday, December 5, 2012 8:06 PM
  • Now I am getting this one error multiple times.

    I do have "using System.Collections.Generic;"

    The type or namespace name 'T' could not be found (are you missing a using directive or an assembly reference?)

    Wednesday, December 5, 2012 8:13 PM
  • Is there no way to tell Visual Studio to just build the program even with errors? I don't wish to solve the original problem I just would like to see if it will work with ignoring it. If the program won't run then I'll go back and apologize to Visual Studio and tell it I'm sorry for doubting its error catching abilities.
    Wednesday, December 5, 2012 8:23 PM
  • Build warnings can be ignored but not errors. If it is possible to build anything at our will, I can write some junk and expect it to build.

    In fact, the error is not raised by the Visual Studio but by the complier.

    I suggest you better share your code, so that someone from the community can help.


    Thanks, Murugesan M - Please Mark as the Answer, if this answers your question. Please vote as helpful, if this post is helpful.

    Wednesday, December 5, 2012 8:39 PM
  • It's good to use the code out there to learn; but before you get into all that, you should learn how generics works in C#.

    "Penso, logo existo" - René Descartes
    "A produção de muitas coisas úteis resulta em muitas pessoas inúteis" - Karl Marx
    "Vive como se fosses morrer amanhã, aprende como se fosses viver para sempre" - Mahatma Gandhi

    João Miguel

    Wednesday, December 5, 2012 9:38 PM
  • Sorry I feel bad not being helpful. Here is the relevant section of my code.

    I already had the "using systems.collections.generic;" before it was suggested by Wyck.

        using System;
        using System.Collections.Generic;
        using System.Collections.ObjectModel;
    
        public sealed class Example<T> : List<T> where T: IGameObject
        {
            private SomethingeElse<T> mComparer;
            private object mLock;
            private int mMaxCapacity;
            private bool mNeedSort;
            private List<T> mPendingAdditions;
            private List<T> mPendingRemovals;
            private int mSortCursor;
            private List<T> mStaticBuffer;
            private bool mWantSort;
            private int mWorkChunkCursor;

    I figured setting "where T: IGameObject" would do the trick. If I take that out will i have to change T to IGameObject at every instance?

    Okay, so which line is the error on?  Is it on the line with SomethingElse?  Is SomethingElse generic?
    Wednesday, December 5, 2012 9:44 PM
  • @InherentCoder: This is just an example of class where Example, IGameObject (T) and SomethingeElse must be replaced by the right ones.


    Classified SR-2 | 2x Xeon W5580 - 3.20 GHz | 12x 2GB Kingston KHX2000C9D3T1K3/6GX | 2x MARS II/2DIS/3GD5 | SAMSUNG 830 MZ-7PC512D/AM 2.5" 512GB SATA III MLC | 4x Spinpoint F3EG HD503HI 500GB 5400 16MB SATA 3.0Gb/s |



    • Edited by VendorX Thursday, December 6, 2012 3:36 AM
    Thursday, December 6, 2012 12:22 AM
  • Your error is likely not in the section of code you posted.  For example. The following compiles (with warnings about unused fields.)

    using System;
    using System.Collections.Generic;
    using System.Collections.ObjectModel;
    
    public interface IGameObject
    {
    }
    
    public class SomethingeElse<T>
    {
    }
    
    public sealed class Example<T> : List<T> where T : IGameObject
    {
        private SomethingeElse<T> mComparer;
        private object mLock;
        private int mMaxCapacity;
        private bool mNeedSort;
        private List<T> mPendingAdditions;
        private List<T> mPendingRemovals;
        private int mSortCursor;
        private List<T> mStaticBuffer;
        private bool mWantSort;
        private int mWorkChunkCursor;
    }

    Is it possible that it's the extra 'e' in SomethingeElse that is giving you trouble?

    • Proposed as answer by Jason Dot Wang Friday, December 7, 2012 4:15 AM
    • Marked as answer by Jason Dot Wang Thursday, December 13, 2012 9:45 AM
    Thursday, December 6, 2012 1:39 PM