using serialization to serialize my objects to hard drive

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Alexandre (www.pointnetsolutions.com)

    #1

    using serialization to serialize my objects to hard drive

    Hey im using serialization to serialize my objects to hard drive,
    reading them is no problem but overwriting them causes me problems,i
    have un authorized access to the files but i gave the folder all the
    permissions.

    source:


    can someone tell me what im not doing right

  • Alexandre (www.pointnetsolutions.com)

    #2
    Re: using serialization to serialize my objects to hard drive

    this only occurs when i write a new file and then try to over write it.
    if the thread finishes and starts overagain i am able to overwrite a
    file that already exists as often as i want..

    Comment

    • Willy Denoyette [MVP]

      #3
      Re: using serialization to serialize my objects to hard drive


      "Alexandre (www.pointnetso lutions.com)" <alexandre.bris ebois@gmail.com >
      wrote in message
      news:1114278684 .509416.322520@ f14g2000cwb.goo glegroups.com.. .[color=blue]
      > Hey im using serialization to serialize my objects to hard drive,
      > reading them is no problem but overwriting them causes me problems,i
      > have un authorized access to the files but i gave the folder all the
      > permissions.
      >
      > source:
      > http://www.vkarlsen.no/pastebin/default.asp?id=5545
      >
      > can someone tell me what im not doing right
      >[/color]

      Please post the exact exception message.
      You should also post the complete code that illustrates the problem you
      have, not a few methods like you did now.

      Willy.


      Comment

      • Steve Walker

        #4
        Re: using serialization to serialize my objects to hard drive

        In message <1114281928.811 575.307330@z14g 2000cwz.googleg roups.com>,
        "Alexandre (www.pointnetso lutions.com)" <alexandre.bris ebois@gmail.com >
        writes[color=blue]
        >this only occurs when i write a new file and then try to over write it.
        >if the thread finishes and starts overagain i am able to overwrite a
        >file that already exists as often as i want..[/color]

        Are you using a filestream to write to disk? Is it in a using block /
        being cleaned up manually? The example below does not error. Remove the
        'using' block, and you get a file locked exception:

        "An unhandled exception of type 'System.IO.IOEx ception' occurred in
        mscorlib.dll

        Additional information: The process cannot access the file "I:\x.dat"
        because it is being used by another process."

        static void Main(string[] args)
        {
        WriteFile();
        WriteFile();
        Console.Read();
        }
        static void WriteFile()
        {
        Foo foo = new Foo();
        BinaryFormatter bf = new BinaryFormatter ();
        using(FileStrea m fs = new FileStream(@"I: \x.dat",FileMod e.Create))
        {
        bf.Serialize(fs ,foo);
        }
        }

        --
        Steve Walker

        Comment

        • Alexandre (www.pointnetsolutions.com)

          #5
          Re: using serialization to serialize my objects to hard drive

          Additional information: The process cannot access the file "I:\x.dat"
          because it is being used by another process."

          is the exact error im getting this is all on a webservice, and i am
          using the user statment "block" and i still get this error when i
          create a new fresh file where i overwrite the file im alright.

          it seems that when i create a new filei have to wait for the gc to
          dispose of the application thread to release everything before i can
          overwrite....

          i find this quite strange because the code is clean and should work i
          juste cannot find anything wrong with it.

          if any one can give me some light on this i would be greatful...

          Alexandre

          Comment

          • Steve Walker

            #6
            Re: using serialization to serialize my objects to hard drive

            In message <1114490980.152 261.125050@l41g 2000cwc.googleg roups.com>,
            "Alexandre (www.pointnetso lutions.com)" <alexandre.bris ebois@gmail.com >
            writes[color=blue]
            >Additional information: The process cannot access the file "I:\x.dat"
            >because it is being used by another process."
            >
            >is the exact error im getting this is all on a webservice, and i am
            >using the user statment "block" and i still get this error when i
            >create a new fresh file where i overwrite the file im alright.
            >
            >it seems that when i create a new filei have to wait for the gc to
            >dispose of the application thread to release everything before i can
            >overwrite... .[/color]

            I think you need to post the code.

            --
            Steve Walker

            Comment

            • Alexandre (www.pointnetsolutions.com)

              #7
              Re: using serialization to serialize my objects to hard drive

              i will post again :


              Comment

              • Steve Walker

                #8
                Re: using serialization to serialize my objects to hard drive

                In message <1114526752.321 907.299920@z14g 2000cwz.googleg roups.com>,
                "Alexandre (www.pointnetso lutions.com)" <alexandre.bris ebois@gmail.com >
                writes[color=blue]
                >i will post again :
                >http://www.vkarlsen.no/pastebin/ViewPaste.aspx?id=5563[/color]

                That code works on my machine. Do you have another process locking it;
                virus scanner, or index server, perhaps? You can use Process Explorer
                http://www.sysinternals.com to find out which process has a file locked.

                --
                Steve Walker

                Comment

                • Alexandre (www.pointnetsolutions.com)

                  #9
                  Re: using serialization to serialize my objects to hard drive

                  i am using this code in a web service, therefore i truely have no idea
                  why it causes this problem like you have experienced this code works
                  great locally

                  Comment

                  • Aaron

                    #10
                    Re: using serialization to serialize my objects to hard drive

                    If you are trying to write to a file from a webservice you may have threading
                    issues as multiple requests would be trying to write to the same file.

                    "Alexandre (www.pointnetso lutions.com)" wrote:
                    [color=blue]
                    > i am using this code in a web service, therefore i truely have no idea
                    > why it causes this problem like you have experienced this code works
                    > great locally
                    >
                    >[/color]

                    Comment

                    Working...