Error cs0246 the type or namespace name particleemitter could not be found

"AssetsParticleScalerParticleScaler.cs(99,12): error CS0246: The type or namespace name 'ParticleEmitter' could not be found (are you missing a using directive or an assembly reference?)" I was

«AssetsParticleScalerParticleScaler.cs(99,12): error CS0246: The type or namespace name ‘ParticleEmitter’ could not be found (are you missing a using directive or an assembly reference?)»

I was looking everywhere for the issue. I found some answers in stackoverflow, some similar errors, I did everything they say but they don’t work ..
Any time I try an answer get the same error with the name of what I defined again.
I have been looking for the answers for few days and no answer for this..
I will be so thankful if you help me to solve this issue.
thanks

This script will only work in editor mode. You cannot adjust the scale dynamically in-game!

    using UnityEngine;
    using System.Collections;
    using UnityEngine.ParticlesLegacyModule; // i defined particleEmitter here!

    #if UNITY_EDITOR 
    using UnityEditor;
    #endif

    [ExecuteInEditMode]
    public class ParticleScaler : MonoBehaviour 
    {
        public float particleScale = 1.0f;
        public bool alsoScaleGameobject = true;

        float prevScale;

        void Start()
        {
            prevScale = particleScale;
        }

        void Update () 
        {
    #if UNITY_EDITOR 
            //check if we need to update
            if (prevScale != particleScale && particleScale > 0)
            {
                if (alsoScaleGameobject)
                    transform.localScale = new Vector3(particleScale, particleScale, particleScale);

                float scaleFactor = particleScale / prevScale;

                //scale legacy particle systems
                ScaleLegacySystems(scaleFactor);

                //scale shuriken particle systems
                ScaleShurikenSystems(scaleFactor);

                //scale trail renders
                ScaleTrailRenderers(scaleFactor);

                prevScale = particleScale;
            }
    #endif
        }

        void ScaleShurikenSystems(float scaleFactor)
        {
    #if UNITY_EDITOR 
            //get all shuriken systems we need to do scaling on
            ParticleSystem[] systems = GetComponentsInChildren<ParticleSystem>();

            foreach (ParticleSystem system in systems)
            {
                system.startSpeed *= scaleFactor;
                system.startSize *= scaleFactor;
                system.gravityModifier *= scaleFactor;

                //some variables cannot be accessed through regular script, we will acces them through a serialized object
                SerializedObject so = new SerializedObject(system);

                //unity 4.0 and onwards will already do this one for us
    #if UNITY_3_5 
                so.FindProperty("ShapeModule.radius").floatValue *= scaleFactor;
                so.FindProperty("ShapeModule.boxX").floatValue *= scaleFactor;
                so.FindProperty("ShapeModule.boxY").floatValue *= scaleFactor;
                so.FindProperty("ShapeModule.boxZ").floatValue *= scaleFactor;
    #endif

                so.FindProperty("VelocityModule.x.scalar").floatValue *= scaleFactor;
                so.FindProperty("VelocityModule.y.scalar").floatValue *= scaleFactor;
                so.FindProperty("VelocityModule.z.scalar").floatValue *= scaleFactor;
                so.FindProperty("ClampVelocityModule.magnitude.scalar").floatValue *= scaleFactor;
                so.FindProperty("ClampVelocityModule.x.scalar").floatValue *= scaleFactor;
                so.FindProperty("ClampVelocityModule.y.scalar").floatValue *= scaleFactor;
                so.FindProperty("ClampVelocityModule.z.scalar").floatValue *= scaleFactor;
                so.FindProperty("ForceModule.x.scalar").floatValue *= scaleFactor;
                so.FindProperty("ForceModule.y.scalar").floatValue *= scaleFactor;
                so.FindProperty("ForceModule.z.scalar").floatValue *= scaleFactor;
                so.FindProperty("ColorBySpeedModule.range").vector2Value *= scaleFactor;
                so.FindProperty("SizeBySpeedModule.range").vector2Value *= scaleFactor;
                so.FindProperty("RotationBySpeedModule.range").vector2Value *= scaleFactor;

                so.ApplyModifiedProperties();
            }
    #endif
        }

        void ScaleLegacySystems(float scaleFactor)
        {
    #if UNITY_EDITOR 
            //get all emitters we need to do scaling on
            ParticleEmitter[] emitters = GetComponentsInChildren<ParticleEmitter>();

            //get all animators we need to do scaling on
            ParticleAnimator[] animators = GetComponentsInChildren<ParticleAnimator>();

            //apply scaling to emitters
            foreach (ParticleEmitter emitter in emitters)
            {
                emitter.minSize *= scaleFactor;
                emitter.maxSize *= scaleFactor;
                emitter.worldVelocity *= scaleFactor;
                emitter.localVelocity *= scaleFactor;
                emitter.rndVelocity *= scaleFactor;

                //some variables cannot be accessed through regular script, we will acces them through a serialized object
                SerializedObject so = new SerializedObject(emitter);

                so.FindProperty("m_Ellipsoid").vector3Value *= scaleFactor;
                so.FindProperty("tangentVelocity").vector3Value *= scaleFactor;
                so.ApplyModifiedProperties();
            }

            //apply scaling to animators
            foreach (ParticleAnimator animator in animators)
            {
                animator.force *= scaleFactor;
                animator.rndForce *= scaleFactor;
            }
    #endif
        }

        void ScaleTrailRenderers(float scaleFactor)
        {
            //get all animators we need to do scaling on
            TrailRenderer[] trails = GetComponentsInChildren<TrailRenderer>();

            //apply scaling to animators
            foreach (TrailRenderer trail in trails)
            {
                trail.startWidth *= scaleFactor;
                trail.endWidth *= scaleFactor;
            }
        }
    }

description title ms.date f1_keywords helpviewer_keywords ms.assetid

Compiler Error CS0246

Compiler Error CS0246

01/23/2018

CS0246

CS0246

4948fae2-2cc0-4ce4-b98c-ea69a8120b71

Compiler Error CS0246

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

A type or namespace that is used in the program was not found. You might have forgotten to reference (References) the assembly that contains the type, or you might not have added the required using directive. Or, there might be an issue with the assembly you are trying to reference.

The following situations cause compiler error CS0246.

  • Did you misspell the name of the type or namespace? Without the correct name, the compiler cannot find the definition for the type or namespace. This often occurs because the casing used in the name of the type is not correct. For example, Dataset ds; generates CS0246 because the s in Dataset must be capitalized.

  • If the error is for a namespace name, did you add a reference (References) to the assembly that contains the namespace? For example, your code might contain the directive using Accessibility. However, if your project does not reference the assembly Accessibility.dll, error CS0246 is reported. For more information, see Managing references in a project

  • If the error is for a type name, did you include the proper using directive, or, alternatively, fully qualify the name of the type? Consider the following declaration: DataSet ds. To use the DataSet type, you need two things. First, you need a reference to the assembly that contains the definition for the DataSet type. Second, you need a using directive for the namespace where DataSet is located. For example, because DataSet is located in the System.Data namespace, you need the following directive at the beginning of your code: using System.Data.

    The using directive is not required. However, if you omit the directive, you must fully qualify the DataSet type when referring to it. Full qualification means that you specify both the namespace and the type each time you refer to the type in your code. If you omit the using directive in the previous example, you must write System.Data.DataSet ds to declare ds instead of DataSet ds.

  • Did you use a variable or some other language element where a type was expected? For example, in an is statement, if you use a Type object instead of an actual type, you get error CS0246.

  • Did you reference the assembly that was built against a higher framework version than the target framework of the program? Or did you reference the project that is targeting a higher framework version than the target framework of the program? For example, you work on the project that is targeting .NET Framework 4.6.1 and use the type from the project that is targeting .NET Framework 4.7.1. Then you get error CS0246.

  • Are all referenced projects included in the selected build configuration and platform? Use the Visual Studio Configuration Manager to make sure all referenced projects are marked to be built with the selected configuration and platform.

  • Did you use a using alias directive without fully qualifying the type name? A using alias directive does not use the using directives in the source code file to resolve types. The following example generates CS0246 because the type List<int> is not fully qualified. The using directive for System.Collections.Generic does not prevent the error.

    using System.Collections.Generic;  
    
    // The following declaration generates CS0246.  
    using myAliasName = List<int>;
    
    // To avoid the error, fully qualify List.  
    using myAliasName2 = System.Collections.Generic.List<int>;  

    If you get this error in code that was previously working, first look for missing or unresolved references in Solution Explorer. Do you need to reinstall a NuGet package? For information about how the build system searches for references, see Resolving file references in team build. If all references seem to be correct, look in your source control history to see what has changed in your .csproj file and/or your local source file.

    If you haven’t successfully accessed the reference yet, use the Object Browser to inspect the assembly that is supposed to contain this namespace and verify that the namespace is present. If you verify with Object Browser that the assembly contains the namespace, try removing the using directive for the namespace and see what else breaks. The root problem may be with some other type in another assembly.

The following example generates CS0246 because a necessary using directive is missing.

// CS0246.cs  
//using System.Diagnostics;  
  
public class MyClass  
{  
    // The following line causes CS0246. To fix the error, uncomment  
    // the using directive for the namespace for this attribute,  
    // System.Diagnostics.  
    [Conditional("A")]  
    public void Test()  
    {  
    }  
  
    public static void Main()  
    {  
    }  
}  

The following example causes CS0246 because an object of type Type was used where an actual type was expected.

// CS0246b.cs  
using System;  
  
class ExampleClass  
{  
    public bool supports(object o, Type t)  
    {  
        // The following line causes CS0246. You must use an  
        // actual type, such as ExampleClass, String, or Type.  
        if (o is t)  
        {  
            return true;  
        }  
        return false;  
    }  
}  
  
class Program  
{  
    public static void Main()  
    {  
        ExampleClass myC = new ExampleClass();  
        myC.supports(myC, myC.GetType());  
    }  
}  

Recommended

  • 1. Download ASR Pro
  • 2. Follow the on-screen instructions to run a scan
  • 3. Restart your computer and wait for it to finish running the scan, then follow the on-screen instructions again to remove any viruses found by scanning your computer with ASR Pro
  • Speed up your PC today with this easy-to-use download.

    You may receive an error message indicating Visual Studio error cs0246. There are several ways to solve this problem, and we will deal with it shortly. g.Unity error: CS0246: Could not find type or namespace name ‘image’ (are you missing a take directive or an assembly reference?) “

    Error CS0246: The type or namespace name ‘________’ could not be found. Do you still have any guidance on using personal directories? The root cause. This error occurs when the namespace you are trying to use does not exist.

    Error CS0246: The type or namespace name ‘________’ could not be found. Don’t have a using directive from your assembly references? The root cause. This error always occurs when the namespace you are trying to use does not exist.

    error cs0246 visual studio

    Typeor namespace alias ‘type / namespace’ not found (is there a public directive or strong assembly reference missing?)

    Recommended

    Is your PC running slow? Do you have problems starting up Windows? Don’t despair! ASR Pro is the solution for you. This powerful and easy-to-use tool will diagnose and repair your PC, increasing system performance, optimizing memory, and improving security in the process. So don’t wait — download ASR Pro today!

  • 1. Download ASR Pro
  • 2. Follow the on-screen instructions to run a scan
  • 3. Restart your computer and wait for it to finish running the scan, then follow the on-screen instructions again to remove any viruses found by scanning your computer with ASR Pro
  • The type or namespace in which it is used in a program has not previously been found. Perhaps you have defined a reference ( references ) to the assembly containing the type, or you probably did not add the required using statement. Or it may have a congregation problem that people are trying to link to.

    • There are two answers to this error. The first is when you need to correct the namespace name to match the existing one. The goal is to rebuild the newly created custom namespace.

      Did you misspell a name like “also”? Without the correct name, the user compiler cannot find a definition for the type or namespace. This happens all the time because the case used for the type name is incorrect. For example, Ds; dataset creates CS0246 because the s in the dataset must be uppercase.


    • If this particular error is manufacturer namespace, add a reference ( References ) directly to the assembly containing its namespace. Names? For example, your code could be using the Accessibility directive . However, if your project is not referenced In its assembly Accessibility.dll, error CS0246 will be declared. For information see Boards a in Project

    • If an error can occur with the type name, did you include the correct using statement, or, if that failed, did you just fully define the name associated with the type? See the following document: DataSet ds . To use the DataSet part, you need two things. First, you need a reference to this assembly, which contains a definition that is of type DataSet . Second, you need to use with one directive for the entire namespace that contains the DataSet . Since DataSet is in each of our System.Data namespaces, you should generally follow the instructions at the beginning of your preferred code for argumentation: using System.Data .

      How do I fix error CS0103?

      CS0103 is called when you use an address for a variable or method that does not exist in the situation in which you are using it. To fix CS0103, you need to fix any variable or system name from which it is declared or possibly referenced.

      The using directive is definitely not required. However, if you skip a statement, you must fully meet the criteria for a DataSet if you do reference it. Fully qualified means that whenever you give time to a type in your codeThat is, most people specify both the type and the namespace. If you omit the using directive from the previous example, you would compose System.Data.DataSet ds to get ds instead of <. to declare the code> DataSet ds .

    • Have you used an appropriate variable to determine where the type was expected? For example, if you use the Type object, preferably the actual type, in the is statement, you will encounter error CS0246.

    • error cs0246 visual studio

      Did you mean an installation built for a version of the platform that is larger than the target program? Or maybe you mentioned a project targeting a higher version of the framework than what you see in the target program structure? For example, you are working on a distribution targeting the .NET Framework 4.6.1 and a project-specific use case targeting the .NET Framework 4.7.1. Then you will get error CS0246.

    • How do I fix namespace errors?

      Select View >> Solution Explorer.Right click on your project and select Properties.On the Project Properties tab, click Compile.Select Advanced Compilation Options.Choose . NET Framework 4 from the Target Framework dropdown.

      Have you used the alias information without specifying the full legal name? The using alias directive typically uses the using directives in a source file to resolve forms. In the next exampleCS0246 is not generated because the type List is not fully defined. The using directive in System.Collections.Generic does not prevent the error.

        with System.Collections.Generic;// The following announcement has been moved to CS0246.using myAliasName = List ;// Fill in the spec list to avoid errors.using myAliasName2 = System.Collections.Generic.List ; 

      If you get this type of error in code you've tried, first check Solution Explorer for missing or dangerous links. Do I need to reinstall the NuGet package? For more information on improving the search for system credentials, see Allowing file credentials in Team Build . When all links seem to be covered, check your source code check time to see what changed in your .csproj file and / or city source file.

      If you haven't yet evaluated the link, use Object Explorer to inspect the assembly that should contain this process namespace and see if this namespace might exist. When using Object Browser to verify that this assembly withtakes over the namespace, try removing the using information for the namespace and explore other language factions. The main problem can arise especially with a different type of different assembly.

    The following example creates CS0246 a because the required using directive is indeed missing.

      // CS0246.cs// with System.Diagnostics;  public class maclass      // The next line calls CS0246. To fix the error, uncomment it.   // type of namespace using directive to get this attribute,   // system diagnostics.   [Conditional ("A")]   invalid public test ()                 Static Font Empty Main ()              

    Why am I getting error CS0246 the type or namespace name could not be found?

    You may have forgotten to reference this assembly containing the type, or the clients may not have added the required directive. Or there may be a dilemma with the assembly you are trying to reference. Without the correct name, these compilers cannot find the human type or namespace definition.

    The following example calls CS0246 because the Type form object was used where the actual form was expected.

    How do I fix namespace errors?

    Select View >> Solution Explorer.Right click on your project and select Properties.On the Project Properties tab, select Compile.Select Advanced Compilation Options.Choose . NET Framework 3 from the Target Framework dropdown.

      // CS0246b.csSystem use;  Example class class     generic boolean support (object o, type t)              // The used string calls CS0246. You must wear one       // a serious type such as ExampleClass, String, or Type.        should (oh there are t)                      returns true;                  return at is incorrect;          Class program      Public static void Main ()              ExampleClass myC corresponds to the new ExampleClass ();        myC.supports (myC, myC.GetType ());         
    • 4 reading cycles

    Speed up your PC today with this easy-to-use download.

    Are you missing a using directive or an assembly reference Visual Studio 2019?

    Open the current project in Solution Explorer.Right-click the Links folder and select Add Link.Find and select the assembly that might match your error message.Click OK to add it to your project.

    How do I fix namespace errors?

    Select View >> Solution Explorer.Right click on your project and select Properties.Select Compile from the navigation bar of the project properties.Select Advanced Compilation Options.Choose . NET Framework 4 from the Target Framework dropdown.

    How do you fix Are you missing a using directive or an assembly reference?

    Open the project in Solution Explorer.Right-click the Links folder and select Add Link.Find and select the assembly that matches your error message, also known as a class.Click OK to add them to your project.

    How do I fix error cs0234?

    If you should see this error after migrating code from one development machine to another, make sure the company has the correct part numbers on the new machine and that the assembly solutions are the same as on the old machine.

    Blad Cs0246 Visual Studio
    Erreur Cs0246 Studio Visuel
    Fout Cs0246 Visuele Studio
    Error Cs0246 Visual Studio
    Fel Cs0246 Visual Studio
    Fehler Cs0246 Visual Studio
    Erro Cs0246 Visual Studio
    Errore Cs0246 Studio Visivo
    오류 Cs0246 비주얼 스튜디오
    Oshibka Cs0246 Visual Studio

    Related posts:

    How To Fix A Debug Stored Procedure Error In Visual Studio

    Tips To Resolve FTP Error 126 Remote Rmdir Error

    Tips To Resolve Alaska Airlines Error Code 1580

    Troubleshoot And Resolve Wii Error 003 Solution Detected By Unauthorized Device

    C# Compiler Error

    CS0246 – The type or namespace name ‘type/namespace’ could not be found (are you missing a using directive or an assembly reference?)

    Reason for the Error

    You will most likely receive this error when the C# compiler has not found the type or the namespace that is used in your C# program.

    There are plenty of reasons why you will have this error code from C#. These include

    • You have missed adding reference to the assembly that contains the type.
    • You have missed adding the required using directive.
    • You could have misspell the name of the type or namespace.
    • You would have referenced an assembly that was built against a higher .NET framework version than the target version of the current program.

    For example, try compiling the below code snippet.

    using System;
    namespace DeveloperPubNamespace
    {
       class Program
        {
    
            public static void Main()
            {
                var lstData = new List<int>();
            }
        }
    }

    This program will result with the C# error code CS0246 because you are using the type List but is not fully qualified or the using directive is not applied in the program for the namespace where the List exists.

    Error CS0246 The type or namespace name ‘List<>’ could not be found (are you missing a using directive or an assembly reference?) DeveloperPublish C:UsersSenthilBalusourcereposConsoleApp3ConsoleApp3Program.cs 9 Active

    C# Error CS0246 – The type or namespace name 'type/namespace' could not be found

    Solution

    You can fix this error in C# by ensuring that you add the right type or namespace in your program. Ensure that you have used the using directive to include the namespace or atleast using the fully qualified name for the class as shown below.

    namespace DeveloperPubNamespace
    {
       class Program
        {
    
            public static void Main()
            {
                var lstData = new System.Collections.Generic.List<int>();
            }
        }
    }

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using System;
     
    /// <summary>
    /// Main post processing class where image effects are applied to scene texture
    /// </summary>
    [ExecuteInEditMode, ImageEffectAllowedInSceneView]
    public class PostProcessor : MonoBehaviour {
     
        [Header("Analog Glitch settings")]
        [Range(0, 1)] public half ScanLineJitter;
        [Range(0, 1)] public half VerticalJump;
        [Range(0, 1)] public half HorizontalShake;
        [Range(0, 1)] public half ColorDrift;
        [Header("Glitch settings")]
        [Range(0, 1)] public half Intensity;
        [Range(0, 1)] public half ColorIntensity;
        public Texture2D displacementMap;
        
        /// <summary>
        /// Class holding information about shaders uniforms names
        /// </summary>
        private static class ShaderUniforms {
            
            //Vignette shader
            public static readonly int VignettePower = Shader.PropertyToID("_VignettePower");
            public static readonly int VignetteCenter = Shader.PropertyToID("_VignetteCenter");
     
            //Chromatic abberation shader
            public static readonly int ColorsShiftAmount = Shader.PropertyToID("_ColorShiftFactor");
            public static readonly int FishEyeEffectFactor = Shader.PropertyToID("_FishEyeEffectFactor");
            public static readonly int FishEyeStart = Shader.PropertyToID("_FishEyeEffectStart");
            public static readonly int FishEyeEnd = Shader.PropertyToID("_FishEyeEffectEnd");
     
            //Distortion
            public static readonly int Distortion = Shader.PropertyToID("_Distortion");
            public static readonly int CubicDistortion = Shader.PropertyToID("_CubicDistortion");
            public static readonly int Scale = Shader.PropertyToID("_Scale");
     
            //GlitchEffect
            public static readonly int scanLineJitter = Shader.PropertyToID("_scanLineJitter");
            public static readonly int verticalJump = Shader.PropertyToID("_verticalJump");
            public static readonly int horizontalShake = Shader.PropertyToID("_horizontalShake");
            public static readonly int colorDrift = Shader.PropertyToID("_colorDrift");
     
            //GlitchEffect2
            public static readonly int intensity = Shader.PropertyToID("_Intensity");
            public static readonly int colorIntensity = Shader.PropertyToID("_ColorIntensity");
        }
        
     
        [Tooltip("Post processor settings, to create new press right click in project view then: Create -> Mobile Optimized Post Processing -> PostProcessorSettings")]
        public PostProcessorSettings Settings;
     
        /// <summary>
        /// Dictionary containing material instances used by post processor
        /// </summary>
        /// <typeparam name="string">Path to shader file for example "Hidden/VignetteShader"</typeparam>
        /// <typeparam name="Material">Material instance created from shader find by path (key)</typeparam>
        /// <returns></returns>
        private Dictionary<string, Material> Materials = new Dictionary<string, Material>();
        
        private const string VignetteShader = "Hidden/VignetteShader";  
        private const string ChromaticAbberationShader = "Hidden/ChromaticAbberationShader";
        private const string AnalogGlitch = "Hidden/Analog";
        private const string GlitchEffect = "Hidden/GlitchShader";
     
        private const string Barrel = "Hidden/Barrel";
     
        half _verticalJumpTime;
     
        [Range(0, 1)]
        private half flipIntensity;
        private half _glitchup;
        private half _glitchdown;
        private half flicker;
        private half _glitchupTime = 0.05f;
        private half _glitchdownTime = 0.05f;
        private half _flickerTime = 0.5f;
     
        /// <summary>
        /// Inform about lack of settings user only once to avoid spamming same warning over and over again in console
        /// </summary>
        private bool InformedAboutLackOfSettings = false;
     
        /// <summary>
        /// Method for obtaining material instance by supplying shader file path
        /// </summary>
        /// <param name="shaderName">Shader file path</param>
        /// <returns></returns>
        public Material GetMaterial(string shaderName) {
            Material material;
            if(Materials.TryGetValue(shaderName, out material)) {
                return material;
            } else {
                Shader shader = Shader.Find(shaderName);
     
                if(shader == null) {
                    Debug.LogError("Shader not found (" + shaderName  + "), check if missed shader is in Shaders folder if not reimport this package. If this problem occurs only in build try to add all shaders in Shaders folder to Always Included Shaders (Project Settings -> Graphics -> Always Included Shaders)");
                }
                
                Material NewMaterial = new Material(shader);
                NewMaterial.hideFlags = HideFlags.HideAndDontSave;  
                Materials.Add(shaderName, NewMaterial);
                return NewMaterial;
            }
        }
     
        void OnRenderImage (RenderTexture sourceTexture, RenderTexture destTexture) {
            RenderTexture currentTarget = sourceTexture;
     
            //if settings are null just passthrough source image
            if(Settings == null) {
                Graphics.Blit(currentTarget, destTexture);
                
                //check if allready informed about lack of post processing settings to avoid spamming with same message in log console
                if(!InformedAboutLackOfSettings) {
                    Debug.LogWarning("Please attach post processor settings!");
                    InformedAboutLackOfSettings = true;
                }
                return;
            }
            InformedAboutLackOfSettings = false;
     
            //Apply Glitch Effects
            if(Settings.AnalogGlitchEnabled){
                RenderTexture AnalogGlitchTarget = RenderTexture.GetTemporary(sourceTexture.width, sourceTexture.height);
                ApplyAnalogGlitch(currentTarget, AnalogGlitchTarget);
                ReleaseTemporary(currentTarget, sourceTexture);
                currentTarget = AnalogGlitchTarget;
                Settings.scanLineJitter = ScanLineJitter;
                Settings.verticalJump = VerticalJump;
                Settings.horizontalShake = HorizontalShake;
                Settings.colorDrift = ColorDrift;
            }
     
            if(Settings.GlitchEnabled){
                RenderTexture GlitchTarget = RenderTexture.GetTemporary(sourceTexture.width, sourceTexture.height);
                ApplyGlitch(currentTarget, GlitchTarget);
                ReleaseTemporary(currentTarget, sourceTexture);
                currentTarget = GlitchTarget;
                Settings.intensity = Intensity;
                Settings.colorIntensity = ColorIntensity;
            }
            
            //Apply Distortion effects
            if(Settings.DistortionEnabled){
                RenderTexture disTarget = RenderTexture.GetTemporary(sourceTexture.width, sourceTexture.height);
                ApplyDistortion(currentTarget, disTarget);
                ReleaseTemporary(currentTarget, sourceTexture);
                currentTarget = disTarget;
            }
     
            //Apply color grading effects
            if(Settings.ColorGradingEnabled) {
                currentTarget = ApplyColorGrading(currentTarget, sourceTexture);
            }
     
            //Apply Vignette effect
            if(Settings.VignetteEnabled) {
                RenderTexture vignetteTarget = RenderTexture.GetTemporary(sourceTexture.width, sourceTexture.height);
                ApplyVignette(currentTarget, vignetteTarget);
                ReleaseTemporary(currentTarget, sourceTexture);
                currentTarget = vignetteTarget;
            }
     
            //Copy last render target to screen buffer
            Graphics.Blit(currentTarget, destTexture);
            ReleaseTemporary(currentTarget, sourceTexture);
        }
     
        /// <summary>
        /// Helper function to avoid releasing sourceTexture by a mistake
        /// </summary>
        /// <param name="texture">Texture you want to release</param>
        /// <param name="sourceTexture">Original source texture</param> 
        private void ReleaseTemporary(RenderTexture texture, RenderTexture sourceTexture) {
            if(texture != sourceTexture) {
                RenderTexture.ReleaseTemporary(texture);
            }
        }
     
        private void ApplyVignette(RenderTexture from, RenderTexture to) {
            Material VignetteMaterial = GetMaterial(VignetteShader);
            VignetteMaterial.Sethalf(ShaderUniforms.VignettePower, Settings.VignettePower);
            VignetteMaterial.SetVector(ShaderUniforms.VignetteCenter, Settings.VignetteCenter);
            Graphics.Blit(from, to, VignetteMaterial);
        }
     
        private void ApplyAnalogGlitch(RenderTexture from, RenderTexture to) {
            Material AnalogGlitchMaterial = GetMaterial(AnalogGlitch);
            _verticalJumpTime += Time.deltaTime * Settings.verticalJump * 11.3f;
     
            var sl_thresh = Mathf.Clamp01(1.0f - Settings.scanLineJitter * 1.2f);
            var sl_disp = 0.002f + Mathf.Pow(Settings.scanLineJitter, 3) * 0.05f;
            AnalogGlitchMaterial.SetVector("_ScanLineJitter", new Vector2(sl_disp, sl_thresh));
     
            var vj = new Vector2(Settings.verticalJump, _verticalJumpTime);
            AnalogGlitchMaterial.SetVector("_VerticalJump", vj);
     
            AnalogGlitchMaterial.Sethalf("_HorizontalShake", Settings.horizontalShake * 0.2f);
     
            var cd = new Vector2(Settings.colorDrift * 0.04f, Time.time * 606.11f);
            AnalogGlitchMaterial.SetVector("_ColorDrift", cd);
     
            Graphics.Blit(from, to, AnalogGlitchMaterial);
        }
     
        private void ApplyGlitch(RenderTexture from, RenderTexture to) {
            Material GlitchMaterial = GetMaterial(GlitchEffect);
            GlitchMaterial.Sethalf("_Intensity", Settings.intensity);
            GlitchMaterial.Sethalf("_ColorIntensity", Settings.colorIntensity);
            GlitchMaterial.SetTexture("_DispTex", displacementMap);
     
            flicker += Time.deltaTime * Settings.colorIntensity;
            if (flicker > _flickerTime)
            {
                GlitchMaterial.Sethalf("filterRadius", UnityEngine.Random.Range(-3f, 3f) * Settings.colorIntensity);
                GlitchMaterial.SetVector("direction", Quaternion.AngleAxis(UnityEngine.Random.Range(0, 360) * Settings.colorIntensity, Vector3.forward) * Vector4.one);
                flicker = 0;
                _flickerTime = UnityEngine.Random.value;
            }
     
            if (Settings.colorIntensity == 0)
                GlitchMaterial.Sethalf("filterRadius", 0);
     
            _glitchup += Time.deltaTime * flipIntensity;
            if (_glitchup > _glitchupTime)
            {
                if (UnityEngine.Random.value < 0.1f * flipIntensity)
                    GlitchMaterial.Sethalf("flip_up", UnityEngine.Random.Range(0, 1f) * flipIntensity);
                else
                    GlitchMaterial.Sethalf("flip_up", 0);
     
                _glitchup = 0;
                _glitchupTime = UnityEngine.Random.value / 10f;
            }
     
            if (flipIntensity == 0)
                GlitchMaterial.Sethalf("flip_up", 0);
     
            _glitchdown += Time.deltaTime * flipIntensity;
            if (_glitchdown > _glitchdownTime)
            {
                if (UnityEngine.Random.value < 0.1f * flipIntensity)
                    GlitchMaterial.Sethalf("flip_down", 1 - UnityEngine.Random.Range(0, 1f) * flipIntensity);
                else
                    GlitchMaterial.Sethalf("flip_down", 1);
     
                _glitchdown = 0;
                _glitchdownTime = UnityEngine.Random.value / 10f;
            }
     
            if (flipIntensity == 0)
                GlitchMaterial.Sethalf("flip_down", 1);
     
            if (UnityEngine.Random.value < 0.05 * Settings.intensity)
            {
                GlitchMaterial.Sethalf("displace", UnityEngine.Random.value * Settings.intensity);
                GlitchMaterial.Sethalf("scale", 1 - UnityEngine.Random.value * Settings.intensity);
            }
            else
                GlitchMaterial.Sethalf("displace", 0);
            Graphics.Blit(from, to, GlitchMaterial);
        }
        
        private void ApplyDistortion(RenderTexture from, RenderTexture to) {
            Material DistortionMaterial = GetMaterial(Barrel);
            DistortionMaterial.Sethalf(ShaderUniforms.Distortion, Settings.Distortion);
            DistortionMaterial.Sethalf(ShaderUniforms.CubicDistortion, Settings.CubicDistortion);
            DistortionMaterial.Sethalf(ShaderUniforms.Scale, Settings.Scale);
            Graphics.Blit(from, to, DistortionMaterial);
        }
     
        private RenderTexture ApplyColorGrading(RenderTexture currentTarget, RenderTexture sourceTexture) {
            if(Settings.ChromaticAbberationEnabled) {
                RenderTexture CHBTarget = RenderTexture.GetTemporary(sourceTexture.width, sourceTexture.height);
                Material CHBMaterial = GetMaterial(ChromaticAbberationShader);
                CHBMaterial.Sethalf(ShaderUniforms.ColorsShiftAmount, Settings.ColorsShiftAmount);
                CHBMaterial.Sethalf(ShaderUniforms.FishEyeEffectFactor, Settings.FishEyeEffectFactor);
     
                CHBMaterial.Sethalf(ShaderUniforms.FishEyeStart, Settings.FishEyeEffectStart);
                CHBMaterial.Sethalf(ShaderUniforms.FishEyeEnd, Settings.FishEyeEffectEnd);
     
                Graphics.Blit(currentTarget, CHBTarget, CHBMaterial);
                ReleaseTemporary(currentTarget, sourceTexture);
                currentTarget = CHBTarget;
            }
     
            return currentTarget;
        }
        /// <summary>
        /// Destroy all material instances created for post processing 
        /// </summary>
        void OnDisable() {
            foreach(string shader in Materials.Keys) {
                Material material;
                if(Materials.TryGetValue(shader, out material)) {
                    DestroyImmediate(material);
                }
            }
            Materials.Clear();
        }
    }
    • Remove From My Forums
    • Question

    • When our automated build runs, we are getting this error on our ASP.NET MVC:

      ASPNETCOMPILER: Web.config(23): error CS0246: The type or namespace name ‘Common’ could not be found (are you missing a using directive or an assembly reference?)

      Line 23 of the web.config is simply a «<add namespace=»<our namespace name here>»/>» inside the <namespaces> section. 

      Everything works perfectly when we compile from within Visual Studio. However, on the build server there is no «bin» folder visible inside the MVC project. Hence, it appears that it’s not able to find our assembly from which the namespace is being referenced.

      How can we get the build server to create the «bin» folder? Or is there anything solution I’m missing?  Thanks.

    Answers

    • I was able to find the answer to my own question. The answer can be found here: http://blogs.msdn.com/jimlamb/archive/2010/04/20/turn-on-compile-time-view-checking-for-asp-net-mvc-projects-in-tfs-build-2010.aspx.
       Basically the issue is that default setting inside the *.csproj file needed to be changed from this:

      <Target Name="AfterBuild" Condition="'$(MvcBuildViews)'=='true'">
       <AspNetCompiler VirtualPath="temp" PhysicalPath="$(ProjectDir)" />
      </Target>
      

      to this:

      <Target Name="AfterBuild" Condition="'$(MvcBuildViews)'=='true'">
       <AspNetCompiler VirtualPath="temp" PhysicalPath="$(WebProjectOutputDir)" />
      </Target>
      

      or, even more elegantly (as described in Jim Lamb’s post) in its own target since AfterBuild should not be overriden this way:

      <Target Name="BuildViews" Condition="'$(MvcBuildViews)'=='true'" AfterTargets="Build">
       <AspNetCompiler VirtualPath="temp" PhysicalPath="$(WebProjectOutputDir)" />
      </Target>
      

      The key is that the physical path be set to the $(WebProjectOutputDir) variable rather than the $(ProjectDir) variable. Without this, an MVC app can’t see any assemblies in the bin folder and therefore can’t compile. Also, this condition typically
      gets hit when $(MvcBuildViews) is set to true — which is a convenient setting if you want to compiler to tell you about any problems in your views at compile time rather than at run-time where you can get the yellow screen of death.

      • Marked as answer by

        Tuesday, June 1, 2010 3:40 PM

    Recently, I was working on an ASP.NET MVC project using Visual Studio and the web project had strongly-typed views that were using model classes located in another class project in the same solution. The project itself got built successfully and was running fine until it tried to show those views, it returned the Compilation Error saying that the type or namespace name could not be found. In this article, I will show you what I tried and how I finally solved the problem.

    The exact server error is shown below. The ‘MyCustomClass’ is the assembly name of the class project in the solution.

    Compilation Error
    Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

    Compiler Error Message: CS0246: The type or namespace name ‘MyCustomClass’ could not be found (are you missing a using directive or an assembly reference?)

    It seemed strange to me that the view had trouble finding the reference of the type since the view was strongly-typed, generated by Visual Studio using the «Add View» window, and the class from another assembly was chosen from the «Model Class» drop-down menu.

    What was also odd was that the error was occurring in the auto-generated view code and not from the source file in the solution.

    Here are the things I tried to solve the problem.

    Checking «Copy Local» property of the reference

    The first thing I checked was if the class library’s reference in the ASP.NET MVC project had the «Copy Local» property set to true. In the past, I had some issues with Visual Studio not finding types when the property was set to false.

    We can check this property by expanding the References node in the ASP.NET MVC project and right-click the reference in question and select Properties from the context-menu as shown below:
    Visual Studio - reference properties

    Then check the «Copy Local» in the Properties window:
    Visual Studio - reference copy local propertiy

    In my case, it was already true, so I had to keep looking.

    Adding namespace in web.config of the View

    Next, I tried to add the namespace that it couldn’t find manually inside the<namespaces> tag in the web.config file under Views folder (not in the one located in the root folder!!):

          <namespaces>
            <add namespace="System.Web.Mvc" />
            <add namespace="System.Web.Mvc.Ajax" />
            <add namespace="System.Web.Mvc.Html" />
            <add namespace="System.Web.Optimization"/>
            ...
          </namespaces>
    

    This also didn’t do anything.

    Note: To learn more about why there is also a web.config under Views folder, check this article.

    Adding @Using inside the View

    Next, I tried to add namespace directly to the view itself that is causing the problem. I added the @using directive at the beginning of the view:

    @using MyCustomClass;
    

    This modification changed the source of the error from the auto-generated code to the source file of the view itself and nothing more.

    Checking properties of the class project

    Then I turned my attention to the class project itself to see if anything in there might cause this «type or namespace name could not be found» error.

    First, I checked the Properties of the project. You do that by right-clicking on the project name in solution explorer and selecting «Properties» from the context menu, as shown below:

    Visual Studio - project properties

    Click image to enlarge

    Instantly, I noticed a possible culprit. Under the Application tab, the «Output type» had «Console application» selected instead of «Class Library«:

    Visual Studio - project properties output type

    Click image to enlarge

    In the end, this was the source of the problem. Changing «Output type» to «Class Library» finally fixed the issue.

    Conclusion

    When the ASP.NET MVC project builds and the web application runs successfully, the run-time error The type or namespace name could not be found might come as a surprise. In this article, we examined a few examples, what to check if this problem occurs. In the end, for me, the cause of the problem was a referenced class library, that was mistakenly created as a console application.

    Понравилась статья? Поделить с друзьями:
  • Error css class
  • Error csrf token mismatch
  • Error csrf token has expired
  • Error cs9010 primary constructor body is not allowed
  • Error cs8803 top level statements must precede namespace and type declarations