The modifier 'public' is not valid for this item C#

Pagina: 1
Acties:

Onderwerpen

Vraag


Acties:
  • 0 Henk 'm!

  • Nieuwsgier
  • Registratie: Juli 2012
  • Laatst online: 27-07 11:09
Ik heb in een Visual Studio project het ProtectionLevel veranderd van "Encrypt sensitive data with user key" naar "Do not save sensitive data"
Het gevolg daarvan was dat een groot aantal scripts plotseling leeg bleken.

Ik probeer nu de scripts te herstellen (had backup's ) maar krijg nu bij twee regels code plotseling de melding "the modifier 'public'is not available for this item.

Heb heel google al afgestruind maar de daar aangedragen oplossing bieden geen soulaas.

De foutmelding ontstaat bij de regels :
public String ReadFile(String FilePath, String ErrInfo)
en
public void WriteToFile(String FilePath, String strContents, String ErrInfo)
...
code:
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
#region Help:  Introduction to the script task
/* The Script Task allows you to perform virtually any operation that can be accomplished in
 * a .Net application within the context of an Integration Services control flow. 
 * 
 * Expand the other regions which have "Help" prefixes for examples of specific ways to use
 * Integration Services features within this script task. */
#endregion


#region Namespaces
using System;
using System.Data;
using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms;
using System.IO;
#endregion

namespace ST_f4c2afa68ece4cf39609297cf25d99d2
{
    /// <summary>
    /// ScriptMain is the entry point class of the script.  Do not change the name, attributes,
    /// or parent of this class.
    /// </summary>
    [Microsoft.SqlServer.Dts.Tasks.ScriptTask.SSISScriptTaskEntryPointAttribute]
    public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
    {
        #region Help:  Using Integration Services variables and parameters in a script
        /* To use a variable in this script, first ensure that the variable has been added to 
         * either the list contained in the ReadOnlyVariables property or the list contained in 
         * the ReadWriteVariables property of this script task, according to whether or not your
         * code needs to write to the variable.  To add the variable, save this script, close this instance of
         * Visual Studio, and update the ReadOnlyVariables and 
         * ReadWriteVariables properties in the Script Transformation Editor window.
         * To use a parameter in this script, follow the same steps. Parameters are always read-only.
         * 
         * Example of reading from a variable:
         *  DateTime startTime = (DateTime) Dts.Variables["System::StartTime"].Value;
         * 
         * Example of writing to a variable:
         *  Dts.Variables["User::myStringVariable"].Value = "new value";
         * 
         * Example of reading from a package parameter:
         *  int batchId = (int) Dts.Variables["$Package::batchId"].Value;
         *  
         * Example of reading from a project parameter:
         *  int batchId = (int) Dts.Variables["$Project::batchId"].Value;
         * 
         * Example of reading from a sensitive project parameter:
         *  int batchId = (int) Dts.Variables["$Project::batchId"].GetSensitiveValue();
         * */

        #endregion

        #region Help:  Firing Integration Services events from a script
        /* This script task can fire events for logging purposes.
         * 
         * Example of firing an error event:
         *  Dts.Events.FireError(18, "Process Values", "Bad value", "", 0);
         * 
         * Example of firing an information event:
         *  Dts.Events.FireInformation(3, "Process Values", "Processing has started", "", 0, ref fireAgain)
         * 
         * Example of firing a warning event:
         *  Dts.Events.FireWarning(14, "Process Values", "No values received for input", "", 0);
         * */
        #endregion

        #region Help:  Using Integration Services connection managers in a script
        /* Some types of connection managers can be used in this script task.  See the topic 
         * "Working with Connection Managers Programatically" for details.
         * 
         * Example of using an ADO.Net connection manager:
         *  object rawConnection = Dts.Connections["Sales DB"].AcquireConnection(Dts.Transaction);
         *  SqlConnection myADONETConnection = (SqlConnection)rawConnection;
         *  //Use the connection in some code here, then release the connection
         *  Dts.Connections["Sales DB"].ReleaseConnection(rawConnection);
         *
         * Example of using a File connection manager
         *  object rawConnection = Dts.Connections["Prices.zip"].AcquireConnection(Dts.Transaction);
         *  string filePath = (string)rawConnection;
         *  //Use the connection in some code here, then release the connection
         *  Dts.Connections["Prices.zip"].ReleaseConnection(rawConnection);
         * */
        #endregion


        /// <summary>
        /// This method is called when this script task executes in the control flow.
        /// Before returning from this method, set the value of Dts.TaskResult to indicate success or failure.
        /// To open Help, press F1.
        /// </summary>
        public void Main()
        {
            { String ErrInfo = "";
            String FilePath = Dts.Variables["User::Pad_kostendragers"].Value.ToString();
            try
            {
                String FileContent; //Variable to store File Contents
                FileContent = ReadFile(FilePath, ErrInfo);
                if (ErrInfo.Length  > 0)
                {
                    Dts.Log("Error while reading File " + FilePath, 0, null);
                    Dts.Log(ErrInfo, 0, null);
                    Dts.TaskResult = (int)ScriptResults.Failure;
                    return;
                }

               
               FileContent = FileContent.Replace("&amp;lt;", "<"); 
           FileContent = FileContent.Replace("&amp;gt;", ">");
               FileContent = FileContent.Replace("&amp;amp;", "&");
            FileContent = FileContent.Replace("encoding=\"utf-16\"", string.Empty);
                    
               FileContent = FileContent.Replace("&lt;string&gt;",string.Empty);
               FileContent = FileContent.Replace("&lt;/string&gt;", string.Empty);
               

                WriteToFile(FilePath, FileContent, ErrInfo);
                if (ErrInfo.Length >  0)
                {
                    Dts.Log("Error while writing File " + FilePath, 0, null);
                    Dts.Log(ErrInfo, 0, null);
                    Dts.TaskResult = (int)ScriptResults.Failure;
                    return;
                }
            }
            catch (Exception e)
            {
                Dts.Log(e.Message, 0, null);
                Dts.TaskResult = (int)ScriptResults.Failure;
            }
        }

        public String ReadFile(String FilePath, String ErrInfo)
        {
            String strContents;
            StreamReader sReader;
            try
            {
                sReader = File.OpenText(FilePath);
                strContents = sReader.ReadToEnd();
                sReader.Close();
                return strContents;
            }
            catch (Exception e)
            {
                MessageBox.Show(ErrInfo);
                ErrInfo = e.Message;
                return "";
            }
        }

        public void WriteToFile(String FilePath, String strContents, String ErrInfo)
        {
            StreamWriter sWriter;
            try
            {
                sWriter = new StreamWriter(FilePath);
                sWriter.Write(strContents);
                sWriter.Close();
            }
            catch (Exception e)
            {
                MessageBox.Show(ErrInfo);
                ErrInfo = e.Message;
            }
        }


            Dts.TaskResult = (int)ScriptResults.Success;
        }

        #region ScriptResults declaration
        /// <summary>
        /// This enum provides a convenient shorthand within the scope of this class for setting the
        /// result of the script.
        /// 
        /// This code was generated automatically.
        /// </summary>
        enum ScriptResults
        {
            Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,
            Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
        };
        #endregion

    }
}

...

Beste antwoord (via Nieuwsgier op 17-04-2018 15:19)


  • Rannasha
  • Registratie: Januari 2002
  • Laatst online: 12:16

Rannasha

Does not compute.

Check je accolades. Er zit er een { teveel in je Main() waardoor de Main() niet is afgesloten wanneer je met de volgende methode begint.

Daarnaast is er verderop een verdwaalde
C#:
1
2
            Dts.TaskResult = (int)ScriptResults.Success;
        }

dat buiten de methodes valt.

|| Vierkant voor Wiskunde ||

Alle reacties


Acties:
  • Beste antwoord
  • 0 Henk 'm!

  • Rannasha
  • Registratie: Januari 2002
  • Laatst online: 12:16

Rannasha

Does not compute.

Check je accolades. Er zit er een { teveel in je Main() waardoor de Main() niet is afgesloten wanneer je met de volgende methode begint.

Daarnaast is er verderop een verdwaalde
C#:
1
2
            Dts.TaskResult = (int)ScriptResults.Success;
        }

dat buiten de methodes valt.

|| Vierkant voor Wiskunde ||


Acties:
  • 0 Henk 'm!

  • Nieuwsgier
  • Registratie: Juli 2012
  • Laatst online: 27-07 11:09
Thnx