web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

FileStream - ClrObject could not be created

(0) ShareShare
ReportReport
Posted on by

I dont know why getting error 'CLRObject' 



System.IO.FileStream fs,inputStream,outputStream;
System.IO.Directory ff;
System.IO.Compression.GZipStream GZipStream, compStream ;
str s;
System.Byte[] buffer;
int bytesRead;
System.IO.StreamWriter sw;
;

inputStream = new System.IO.FileStream("c:\\temp\\test", System.IO.FileMode::Open, System.IO.FileAccess::Read);
outputStream = new System.IO.FileStream("c:\\temp\\test.zip", System.IO.FileMode::OpenOrCreate, System.IO.FileAccess::Write);

GZipStream = new System.IO.Compression.GZipStream(outputStream, System.IO.Compression.CompressionMode::Compress);

buffer = inputStream.get_Length();
bytesRead = inputStream.Read(buffer, 0, buffer.get_Length());
compStream.Write(buffer, 0, buffer.get_Length());

inputStream.Close();
compStream.Close();
outputStream.Close();

*This post is locked for comments

I have the same question (0)
  • Community Member Profile Picture
    on at

    error line --> inputStream = new System.IO.FileStream("c:\\temp\\test", System.IO.FileMode::Open, System.IO.FileAccess::Read);

  • Grzegorz Skrzypczyk Profile Picture
    225 on at

    You are initialising the variable GZipStream:

    GZipStream = new System.IO.Compression.GZipStream(outputStream, System.IO.Compression.CompressionMode::Compress);

    But then writing using the variable compStream:

    compStream.Write(buffer, 0, buffer.get_Length());

  • Martin Dráb Profile Picture
    237,803 Most Valuable Professional on at

    What exactly does the error message say?

    It's a runtime error, right?

    Are you running the code on client or server?

  • Community Member Profile Picture
    on at

    yes but I getting the actual error on the previous line

    So,

    inputStream = new System.IO.FileStream("c:\\temp\\test", System.IO.FileMode::Open, System.IO.FileAccess::Read);

    error is object clrobject could not be created

  • Community Member Profile Picture
    on at

    runnig on Server

    Error: object clrobject could not be created

    Line: inputStream = new System.IO.FileStream("c:\\temp\\test", System.IO.FileMode::Open, System.IO.FileAccess::Read);

  • Grzegorz Skrzypczyk Profile Picture
    225 on at

    Are you sure the file exists? Consider if the code is running on the client or aos - 'C:\\temp\\' will likely be a different location depending on the tier.

    Please also have a look at this: msdn.microsoft.com/.../fileiopermission.aspx

    You may need to use the .net equivalent of the class described in the link.

  • Martin Dráb Profile Picture
    237,803 Most Valuable Professional on at

    Checking if the file exists on the AOS is the right first step.

    The next one is checking if the AOS service has permissions to open it.

  • Community Member Profile Picture
    on at

    file exists and permissions is open for AOS services. I guess I'll have to find a different solution, thank you.

  • Martin Dráb Profile Picture
    237,803 Most Valuable Professional on at

    Make sure you test these claims properly; it's easy to overlook something. For example, you may want to utilize WinAPIServer::fileExists() to test the first one.

    If both things correct, the only other reason I can think of is that the file is exclusively locked by some other application. Maybe you still have it open in an editor, for instance.

  • Verified answer
    Community Member Profile Picture
    on at

    |Alternative 1

        WinApi::shellExecute("C:\\ Program Files (x86)\\WinRAR\\WinRAR.exe", "a \" c:\\ilgaza\\ExcelTest.zip \"\"C:\\ilgaza\\ExcelTest\"");






    | Alternative 2:

    System.IO.StreamWriter sw;
    InteropPermission perm = yeni InteropPermission (InteropKind :: ClrInterop);
    ;
    
    
    perm.assert ();
    
    
    sw = yeni System.IO.StreamWriter (@ 'C: \ ilgaza \ deneme.bat');
    
    
    sw.WriteLine (@ 'ayarla FILETOZIP = c: \ ilgaza \ ExcelTest');
    sw.WriteLine (@ 'TEMPDIR = C ayarlayın: \ ilgaza \ temp738');
    sw.WriteLine ('rmdir% TEMPDIR%');
    sw.WriteLine ('mkdir% TEMPDIR%');
    sw.WriteLine ('xcopy / s% FILETOZIP%% TEMPDIR%');
    sw.WriteLine ('echo Set objArgs = WScript.Arguments> _zipIt.vbs');
    sw.WriteLine ('echo InputFolder = objArgs (0) >> _zipIt.vbs');
    CreateTextFile (ZipFile, True). "PK" ^ & Chr (5) ^ & Chr (6) ^ & String (18, vbNullChar) >> _zipIt yazın. ) gn;
    sw.WriteLine ('echo Set objShell = CreateObject ("Shell.Application") >> _zipIt.vbs');
    sw.WriteLine ('echo Set kaynak = objShell.NameSpace (InputFolder) .Items >> _zipIt.vbs');
    sw.WriteLine ('echo objShell.NameSpace (ZipFile) .CopyHere (kaynak) >> _zipIt.vbs');
    sw.WriteLine ('echo wScript.Sleep 12000 >> _zipIt.vbs');
    sw.WriteLine (@ 'CScript _zipIt.vbs% TEMPDIR% C: \ ilgaza \ ExcelTest.zip');
    sw.WriteLine ('del_zipIt.vbs');
    sw.WriteLine ('rmdir / s / q% TEMPDIR%');
    sw.Flush ();
    sw.Close ();
    sw.Dispose ();
    
    
    
    
    
    WINAPI :: ShellExecute (@ "C: \ ilgaza \ deneme.bat");
    
    
    CodeAccessPermission :: RevertAssert ();

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans